Commit 9f8de0f3 by Paktalin

More refactoring

parent 14e394cc
......@@ -56,6 +56,7 @@ class VocabularyAdapter(private val fullVocabulary: Vocabulary, private val main
}
private fun deleteWord(position: Int) {
//TODO delete entry point
displayedVocabulary.deleteWord(position)
// update recyclerView
recyclerView.removeViewAt(position)
......@@ -73,11 +74,13 @@ class VocabularyAdapter(private val fullVocabulary: Vocabulary, private val main
fun addWord(newWord: WordItem) {
displayedVocabulary.addWord(newWord)
// TODO add word to fullVocabulary
this.sort()
}
fun updateWord(updatedWord: WordItem) {
displayedVocabulary.updateWord(updatedWord)
// TODO update word in fullVocabulary
this.sort()
}
......
......@@ -125,14 +125,6 @@ class MainActivity : AppCompatActivity() {
shortToast(this, getString(R.string.toast_empty_vocabulary))
}
fun addWord(newWord: WordItem) {
vocabularyAdapter.addWord(newWord)
}
fun updateWord(updatedWord: WordItem) {
vocabularyAdapter.updateWord(updatedWord)
}
override fun onPause() {
super.onPause()
// TODO save changes
......
......@@ -38,6 +38,8 @@ class AddWordFragment : WordFragment() {
}
override fun saveToFirestore(word:String, translation:String, vocabularyId: String) {
// TODO add entry point
val wordPojo = WordItem.Pojo(word, translation, null)
FirestoreManager().saveNewWord(
{ documentId -> onSuccessfulSave(wordPojo, vocabularyId, documentId) },
......@@ -45,10 +47,6 @@ class AddWordFragment : WordFragment() {
wordPojo)
}
override fun updateRecycleView(wordItem: WordItem) {
mainActivity.addWord(wordItem)
}
private fun textWatcher(setEmpty: () -> Unit): TextWatcher {
return object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
......@@ -66,7 +64,7 @@ class AddWordFragment : WordFragment() {
clearFields()
mainActivity.removeProgressBar()
val wordItem = WordItem(wordPojo, documentId, vocabularyId)
updateRecycleView(wordItem)
mainActivity.vocabularyAdapter.addWord(wordItem)
word.requestFocus()
}
......
......@@ -41,10 +41,6 @@ class EditWordFragment : WordFragment() {
visible(mainActivity.btnSubmitLayout)
}
override fun updateRecycleView(wordItem: WordItem) {
mainActivity.updateWord(wordItem)
}
private fun setWordItemData() {
word.setText(wordItem.pojo.word)
translation.setText(wordItem.pojo.translation)
......@@ -69,6 +65,7 @@ class EditWordFragment : WordFragment() {
}
override fun saveToFirestore(word: String, translation: String, vocabularyId: String) {
// TODO edit entry point
val wordPojo = WordItem.Pojo(word, translation, wordItem.pojo.time)
FirestoreManager().updateWord(
{ onSuccessfulSave(wordPojo) },
......@@ -80,7 +77,7 @@ class EditWordFragment : WordFragment() {
gone(mainActivity.btnSubmitLayout)
mainActivity.removeProgressBar()
wordItem.pojo = wordPojo
updateRecycleView(wordItem)
mainActivity.vocabularyAdapter.updateWord(wordItem)
stop()
}
......
......@@ -34,11 +34,8 @@ abstract class WordFragment : Fragment() {
fun submitWord() {
gone(mainActivity.btnSubmitLayout)
val word = word.text.toString()
val translation = translation.text.toString()
mainActivity.addProgressBar()
saveToFirestore(word, translation, FirestoreManager.vocabularyId!!)
saveToFirestore(word.text.toString(), translation.text.toString(), FirestoreManager.vocabularyId!!)
return
}
......@@ -49,5 +46,4 @@ abstract class WordFragment : Fragment() {
protected abstract fun cancelEditing()
protected abstract fun saveToFirestore(word:String, translation:String, vocabularyId:String)
protected abstract fun updateRecycleView(wordItem: WordItem)
}
\ No newline at end of file
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