Commit 080d3fb8 by Paktalin

Minor refactoring

parent 632ea2a0
......@@ -7,6 +7,7 @@ import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.vocabula
class Vocabulary() {
private var words: MutableList<WordItem> = mutableListOf()
private var displayed: MutableList<WordItem> = mutableListOf()
constructor(vocabulary: Vocabulary) : this() {
copyWordsFrom(vocabulary)
......@@ -22,14 +23,6 @@ class Vocabulary() {
}
}
companion object {
private val TAG = "VN/" + Vocabulary::class.java.simpleName
const val SORT_BY_TIME = 0
const val SORT_BY_WORD = 1
const val SORT_BY_TRANSLATION = 2
}
fun sort(sortOrder:Int) {
when(sortOrder) {
SORT_BY_TIME -> sortByTime()
......@@ -82,4 +75,12 @@ class Vocabulary() {
words.sortWith(Comparator { item1, item2 ->
item1.pojo.translation.toLowerCase().compareTo(item2.pojo.translation.toLowerCase()) })
}
companion object {
private val TAG = "VN/" + Vocabulary::class.java.simpleName
const val SORT_BY_TIME = 0
const val SORT_BY_WORD = 1
const val SORT_BY_TRANSLATION = 2
}
}
\ No newline at end of file
......@@ -55,15 +55,6 @@ class VocabularyAdapter(private val fullVocabulary: Vocabulary, private val main
popup.show()
}
private fun deleteWord(position: Int) {
//TODO delete from fullVocabulary
displayedVocabulary.deleteWord(position)
// update recyclerView
recyclerView.removeViewAt(position)
this.notifyItemRemoved(position)
this.notifyItemRangeChanged(position, displayedVocabulary.size())
}
fun refresh() {
/*displayedVocabulary.clear()
FirestoreManager().extractVocabulary { documents ->
......@@ -72,6 +63,14 @@ class VocabularyAdapter(private val fullVocabulary: Vocabulary, private val main
}*/
}
private fun deleteWord(position: Int) {
//TODO delete from fullVocabulary
displayedVocabulary.deleteWord(position)
recyclerView.removeViewAt(position)
this.notifyItemRemoved(position)
this.notifyItemRangeChanged(position, displayedVocabulary.size())
}
fun addWord(newWord: WordItem) {
displayedVocabulary.addWord(newWord)
// TODO add word to fullVocabulary
......
......@@ -82,7 +82,7 @@ class MainActivity : AppCompatActivity() {
}
private fun setUpVocabularyAdapter() {
addProgressBar()
addProgressBar(supportFragmentManager, R.id.container_main)
FirestoreManager().extractVocabularyId({
// recyclerView.adapter = VocabularyAdapter(Vocabulary(), this@MainActivity)
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
......@@ -96,8 +96,8 @@ class MainActivity : AppCompatActivity() {
}
}
},
{ showToastNoWords() },
{ removeProgressBar() }, this)
{ shortToast(this, getString(R.string.toast_empty_vocabulary)) },
{ removeProgressBar(supportFragmentManager) }, this)
}
private fun hideKeyboard() {
......@@ -113,14 +113,6 @@ class MainActivity : AppCompatActivity() {
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
fun addProgressBar() {
com.paktalin.vocabularynotebook.utils.addProgressBar(supportFragmentManager, R.id.container_main)
}
fun removeProgressBar() {
com.paktalin.vocabularynotebook.utils.removeProgressBar(supportFragmentManager)
}
private fun showToastNoWords() {
shortToast(this, getString(R.string.toast_empty_vocabulary))
}
......
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