Commit f4a8ddf1 by Paktalin

Refactoring: sort() function in DisplayedVocabulary

parent cab16d05
......@@ -131,5 +131,5 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
R.id.main_activity_container)
}
val TAG = "VN/" + VocabularyAdapter::class.java.simpleName
private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.vocabulary
import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(wordList) {
var sort: Sort = Sort.BY_TIME
fun clear() {
......@@ -29,21 +30,9 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
fun sort(sort: Sort) {
this.sort = sort
when (sort) {
Sort.BY_TIME -> {
wordList.sortWith(Comparator { item1, item2 ->
-item1.time!!.compareTo(item2.time)
})
}
Sort.BY_WORD -> {
wordList.sortWith(Comparator { item1, item2 ->
item1.word.toLowerCase().compareTo(item2.word.toLowerCase())
})
}
Sort.BY_TRANSLATION -> {
wordList.sortWith(Comparator { item1, item2 ->
item1.translation.toLowerCase().compareTo(item2.translation.toLowerCase())
})
}
Sort.BY_TIME -> wordList.sortByDescending { w -> w.time }
Sort.BY_WORD -> wordList.sortBy { w -> w.word.toLowerCase() }
Sort.BY_TRANSLATION -> wordList.sortBy { w -> w.translation.toLowerCase() }
}
}
......@@ -53,7 +42,5 @@ class DisplayedVocabulary(wordList: MutableList<WordPojo>): BasicVocabulary(word
wordPojo.translation.toLowerCase().contains(string)
}
companion object {
private val TAG = "VN/" + DisplayedVocabulary::class.simpleName
}
private val TAG = "VN/" + DisplayedVocabulary::class.simpleName
}
......@@ -29,8 +29,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
snapshot["tag"].toString(),
snapshot.id)
}
private val TAG = "VN/" + VocabSet::class.java.simpleName
}
init {
......@@ -105,4 +103,6 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
private fun displayAll() {
displayedVocabulary.addAll(wordList)
}
private val TAG = "VN/" + VocabSet::class.java.simpleName
}
\ 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