Commit cab16d05 by Paktalin

Refactoring: removed sort() function from VocabularyAdapter

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