Commit 0bd690e9 by Paktalin

extracted toast messages to resources

parent 115907ef
package com.paktalin.vocabularynotebook
import android.content.Context
import android.os.Build
import android.text.TextUtils
import android.widget.EditText
import android.widget.Toast
class Utils {
companion object {
fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context: Context): Boolean {
if (TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2)) {
Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show()
Utils.shortToast(context, toastMessage)
return false
}
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
import android.util.Log
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.firestoreitems.Vocabulary.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
......@@ -24,7 +25,8 @@ class AddWordFragment : WordFragment() {
updateRecycleView(wordItem) }
.addOnFailureListener {
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) {
......
......@@ -8,8 +8,12 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.Utils
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
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.notebook_sheet.*
import kotlinx.android.synthetic.main.word_item.view.*
......@@ -64,7 +68,7 @@ class EditWordFragment : WordFragment() {
}
.addOnFailureListener {
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()
}
}
......
......@@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_log_in.*
......@@ -46,8 +45,7 @@ class LogInActivity : AppCompatActivity() {
}
.addOnFailureListener {
Log.w(TAG, "signInWithEmail:failure", it)
Toast.makeText(this@LogInActivity, "Authentication failed.",
Toast.LENGTH_SHORT).show()
Utils.shortToast(this@LogInActivity, getString(R.string.toast_auth_failed))
}
}
}
......@@ -68,7 +66,7 @@ class LogInActivity : AppCompatActivity() {
}
.addOnFailureListener {
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
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import com.paktalin.vocabularynotebook.VocabularyAdapter
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import kotlinx.android.synthetic.main.fragment_vocabulary.*
import android.support.v7.widget.SearchView
import com.paktalin.vocabularynotebook.Utils
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
......@@ -110,8 +110,7 @@ class MainActivity : AppCompatActivity() {
fun hideProgressBar() { progress.visibility = View.GONE }
fun showToastNoWords() {
Toast.makeText(this@MainActivity,
"You don't have any words yet. Add your fist one!", Toast.LENGTH_SHORT).show()
Utils.shortToast(this, getString(R.string.toast_no_words))
}
fun removeFragment(fragment: Fragment) {
......
......@@ -18,4 +18,7 @@
<!--Toast messages-->
<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>
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