Commit cab16d05 by Paktalin

Refactoring: removed sort() function from VocabularyAdapter

parent 38404f70
......@@ -10,7 +10,6 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.fragments.SubmitEditedFragment
import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import com.paktalin.vocabularynotebook.utils.Log
import com.paktalin.vocabularynotebook.utils.addSubmitFragment
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.visible
......@@ -37,7 +36,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
var sort: Sort = Sort.BY_TIME
set(value) {
field = value
sort()
vocabulary.sort(sort)
notifyDataSetChanged()
}
init {
......@@ -73,14 +73,13 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
fun refresh() {}
fun addWord(newWord: WordPojo) {
Log.d(TAG, "vocabularyAdapter addWord")
vocabulary.addWord(newWord)
this.sort()
notifyDataSetChanged()
}
fun updateWord(wordPojo: WordPojo) {
vocabulary.updateWord(wordPojo)
this.sort()
notifyDataSetChanged()
}
fun filter(query: String) {
......@@ -120,11 +119,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
this.notifyItemRangeChanged(position, vocabulary.displayedSize())
}
private fun sort() {
vocabulary.sort(sort)
this.notifyDataSetChanged()
}
private fun editWord(container: View, wordPosition: Int) {
addSubmitFragment(mainActivity.supportFragmentManager,
SubmitEditedFragment().apply {
......
......@@ -49,6 +49,8 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
override fun updateWord(updatedWord: WordPojo) {
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.updateWord(updatedWord) }
// TODO change this
sort(displayedVocabulary.sort)
}
override fun deleteWord(wordPojo: WordPojo) {
......@@ -59,6 +61,8 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
override fun addWord(newWord: WordPojo) {
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.addWord(newWord) }
// TODO change this
sort(displayedVocabulary.sort)
}
fun sort(sort: Sort) {
......
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