Commit a419bbf5 by Paktalin

Refactoring

parent c882a289
...@@ -28,7 +28,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -28,7 +28,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
private lateinit var viewHolder: ViewHolder private lateinit var viewHolder: ViewHolder
private var tracker: SelectionTracker<Long>? = null private var tracker: SelectionTracker<Long>? = null
private var menu = true
init { init {
setHasStableIds(true) setHasStableIds(true)
...@@ -68,33 +67,23 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -68,33 +67,23 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
} }
private fun showPopupMenu(v: View, position: Int) { private fun showPopupMenu(v: View, position: Int) {
if (menu) { val popup = PopupMenu(mainActivity, v)
val popup = PopupMenu(mainActivity, v) popup.menuInflater.inflate(R.menu.word_item_menu, popup.menu)
popup.menuInflater.inflate(R.menu.word_item_menu, popup.menu) popup.setOnMenuItemClickListener {
popup.setOnMenuItemClickListener { if (it.itemId == R.id.option_delete) {
if (it.itemId == R.id.option_delete) { deleteWord(vocabulary.displayedAt(position), position)
deleteWord(vocabulary.displayedAt(position), position)
}
if (it.itemId == R.id.option_edit) {
startEditFragment(v, vocabulary.displayedAt(position))
}
true
} }
// if not edit mode, then start EditFragment if (it.itemId == R.id.option_edit) {
if (mainActivity.supportFragmentManager.findFragmentByTag("edit_fragment") == null) startEditFragment(v, vocabulary.displayedAt(position))
popup.show() }
} else { true
Log.d(TAG, "not menu!")
} }
// if not edit mode, then start EditFragment
if (mainActivity.supportFragmentManager.findFragmentByTag("edit_fragment") == null)
popup.show()
} }
fun refresh() { fun refresh() {}
/*displayedVocabulary.clear()
FirestoreManager().extractVocabulary { documents ->
displayedVocabulary.addWordsAsDocuments(documents)
this.notifyDataSetChanged()
}*/
}
private fun deleteWord(wordPojo: WordPojo, position: Int) { private fun deleteWord(wordPojo: WordPojo, position: Int) {
vocabulary.deleteWord(wordPojo) vocabulary.deleteWord(wordPojo)
......
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