Commit 9f8de0f3 by Paktalin

More refactoring

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