Commit f4a8ddf1 by Paktalin

Refactoring: sort() function in DisplayedVocabulary

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