Commit 080d3fb8 by Paktalin

Minor refactoring

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