Commit 38b6f6d7 by Paktalin

Minor refactoring

parent 54c05326
...@@ -62,34 +62,31 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -62,34 +62,31 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
fun addWordItem(newWordItem: WordItem) { fun addWordItem(newWordItem: WordItem) {
wordItems.add(0, newWordItem) wordItems.add(0, newWordItem)
this.sort() this.sort()
this.notifyItemInserted(0)
} }
fun updateWordItem(updatedWordItem: WordItem) { fun updateWordItem(updatedWordItem: WordItem) {
val updatedItemId = wordItems.indexOf(updatedWordItem) val updatedItemId = wordItems.indexOf(updatedWordItem)
wordItems[updatedItemId] = updatedWordItem wordItems[updatedItemId] = updatedWordItem
this.sort() this.sort()
this.notifyDataSetChanged()
} }
private fun sortByTranslation() { private fun sortByTranslation() {
wordItems.sortWith(Comparator { item1, item2 -> wordItems.sortWith(Comparator { item1, item2 ->
item1.pojo!!.translation!!.compareTo(item2.pojo!!.translation!!) item1.pojo!!.translation!!.compareTo(item2.pojo!!.translation!!)
}) })
this.notifyDataSetChanged()
} }
private fun sortByWord() { private fun sortByWord() {
wordItems.sortWith(Comparator { item1, item2 -> wordItems.sortWith(Comparator { item1, item2 ->
item1.pojo!!.word!!.compareTo(item2.pojo!!.word!!) item1.pojo!!.word!!.compareTo(item2.pojo!!.word!!)
}) })
this.notifyDataSetChanged()
} }
fun sort() { fun sort() {
sortByWord = !sortByWord sortByWord = !sortByWord
if (sortByWord) sortByWord() if (sortByWord) sortByWord()
else sortByTranslation() else sortByTranslation()
this.notifyDataSetChanged()
} }
@SuppressLint("ResourceType") @SuppressLint("ResourceType")
......
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