Commit 0bd690e9 by Paktalin

extracted toast messages to resources

parent 115907ef
package com.paktalin.vocabularynotebook package com.paktalin.vocabularynotebook
import android.content.Context import android.content.Context
import android.os.Build
import android.text.TextUtils import android.text.TextUtils
import android.widget.EditText
import android.widget.Toast import android.widget.Toast
class Utils { class Utils {
companion object { companion object {
fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context: Context): Boolean { fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context: Context): Boolean {
if (TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2)) { if (TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2)) {
Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show() Utils.shortToast(context, toastMessage)
return false return false
} }
return true return true
} }
fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
} }
} }
\ No newline at end of file
...@@ -2,7 +2,8 @@ package com.paktalin.vocabularynotebook.ui ...@@ -2,7 +2,8 @@ package com.paktalin.vocabularynotebook.ui
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.Utils
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
...@@ -24,7 +25,8 @@ class AddWordFragment : WordFragment() { ...@@ -24,7 +25,8 @@ class AddWordFragment : WordFragment() {
updateRecycleView(wordItem) } updateRecycleView(wordItem) }
.addOnFailureListener { .addOnFailureListener {
Log.w(TAG, "addNewWordToDb:failure", it.fillInStackTrace()) Log.w(TAG, "addNewWordToDb:failure", it.fillInStackTrace())
Toast.makeText(mainActivity, "Couldn't add the word", Toast.LENGTH_SHORT).show()} Utils.shortToast(mainActivity, getString(R.string.toast_new_word_fail))
}
} }
override fun updateRecycleView(wordItem: WordItem) { override fun updateRecycleView(wordItem: WordItem) {
......
...@@ -8,8 +8,12 @@ import android.view.View ...@@ -8,8 +8,12 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.Utils
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import kotlinx.android.synthetic.main.fragment_new_word.* import kotlinx.android.synthetic.main.fragment_new_word.*
import kotlinx.android.synthetic.main.notebook_sheet.* import kotlinx.android.synthetic.main.notebook_sheet.*
import kotlinx.android.synthetic.main.word_item.view.* import kotlinx.android.synthetic.main.word_item.view.*
...@@ -64,7 +68,7 @@ class EditWordFragment : WordFragment() { ...@@ -64,7 +68,7 @@ class EditWordFragment : WordFragment() {
} }
.addOnFailureListener { .addOnFailureListener {
Log.w(TAG, "updateExistingWord:failure", it.fillInStackTrace()) Log.w(TAG, "updateExistingWord:failure", it.fillInStackTrace())
Toast.makeText(mainActivity, "Couldn't update the word", Toast.LENGTH_SHORT).show() Utils.shortToast(mainActivity, getString(R.string.toast_update_word_failed))
stop() stop()
} }
} }
......
...@@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity ...@@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_log_in.* import kotlinx.android.synthetic.main.activity_log_in.*
...@@ -46,8 +45,7 @@ class LogInActivity : AppCompatActivity() { ...@@ -46,8 +45,7 @@ class LogInActivity : AppCompatActivity() {
} }
.addOnFailureListener { .addOnFailureListener {
Log.w(TAG, "signInWithEmail:failure", it) Log.w(TAG, "signInWithEmail:failure", it)
Toast.makeText(this@LogInActivity, "Authentication failed.", Utils.shortToast(this@LogInActivity, getString(R.string.toast_auth_failed))
Toast.LENGTH_SHORT).show()
} }
} }
} }
...@@ -68,7 +66,7 @@ class LogInActivity : AppCompatActivity() { ...@@ -68,7 +66,7 @@ class LogInActivity : AppCompatActivity() {
} }
.addOnFailureListener { .addOnFailureListener {
Log.d(TAG, "createUserWithEmail:failure", it.fillInStackTrace()) Log.d(TAG, "createUserWithEmail:failure", it.fillInStackTrace())
Toast.makeText(this@LogInActivity, it.message, Toast.LENGTH_SHORT).show() Utils.shortToast(this@LogInActivity, it.message!!)
} }
} }
} }
......
...@@ -16,11 +16,11 @@ import android.view.Menu ...@@ -16,11 +16,11 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import com.paktalin.vocabularynotebook.VocabularyAdapter import com.paktalin.vocabularynotebook.VocabularyAdapter
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import kotlinx.android.synthetic.main.fragment_vocabulary.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
import android.support.v7.widget.SearchView import android.support.v7.widget.SearchView
import com.paktalin.vocabularynotebook.Utils
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
...@@ -110,8 +110,7 @@ class MainActivity : AppCompatActivity() { ...@@ -110,8 +110,7 @@ class MainActivity : AppCompatActivity() {
fun hideProgressBar() { progress.visibility = View.GONE } fun hideProgressBar() { progress.visibility = View.GONE }
fun showToastNoWords() { fun showToastNoWords() {
Toast.makeText(this@MainActivity, Utils.shortToast(this, getString(R.string.toast_no_words))
"You don't have any words yet. Add your fist one!", Toast.LENGTH_SHORT).show()
} }
fun removeFragment(fragment: Fragment) { fun removeFragment(fragment: Fragment) {
......
...@@ -18,4 +18,7 @@ ...@@ -18,4 +18,7 @@
<!--Toast messages--> <!--Toast messages-->
<string name="toast_no_words">You don\'t have any words yet. Add your fist one!</string> <string name="toast_no_words">You don\'t have any words yet. Add your fist one!</string>
<string name="toast_auth_failed">Authentication failed</string>
<string name="toast_new_word_fail">Couldn\'t add the word</string>
<string name="toast_update_word_failed">Couldn\'t update the word</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment