Commit 6dbccfca by Paktalin

Enables/disables popup menu according to the tag selection

parent 1473c257
...@@ -9,6 +9,7 @@ import android.view.WindowManager ...@@ -9,6 +9,7 @@ import android.view.WindowManager
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.recyclerview.selection.Selection
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
...@@ -120,19 +121,20 @@ class MainActivity : AppCompatActivity() { ...@@ -120,19 +121,20 @@ class MainActivity : AppCompatActivity() {
private fun setUpSelectionTracker() { private fun setUpSelectionTracker() {
vocabularyAdapter.selectionTracker = MySelectionTracker().apply { vocabularyAdapter.selectionTracker = MySelectionTracker().apply {
init(recyclerView) init(recyclerView)
addObserver { selection -> addObserver { selection -> whenSelectionChanges(selection) }
run { }
}
private fun whenSelectionChanges(selection: Selection<Long>) {
if (!selection.isEmpty) { if (!selection.isEmpty) {
// TODO disable popup menu vocabularyAdapter.showPopupMenu = false
Log.d(TAG, "selection ${selection.toList()}") Log.d(TAG, "selection ${selection.toList()}")
visible(tagLayout) visible(tagLayout)
} else { } else {
vocabularyAdapter.showPopupMenu = true
gone(tagLayout) gone(tagLayout)
} }
} }
}
}
}
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
......
...@@ -24,6 +24,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -24,6 +24,7 @@ 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
lateinit var selectionTracker: MySelectionTracker lateinit var selectionTracker: MySelectionTracker
var showPopupMenu = true
init { init {
setHasStableIds(true) setHasStableIds(true)
...@@ -62,6 +63,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -62,6 +63,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
} }
private fun showPopupMenu(v: View, position: Int) { private fun showPopupMenu(v: View, position: Int) {
if (showPopupMenu) {
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 {
...@@ -77,6 +79,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -77,6 +79,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
if (mainActivity.supportFragmentManager.findFragmentByTag("edit_fragment") == null) if (mainActivity.supportFragmentManager.findFragmentByTag("edit_fragment") == null)
popup.show() popup.show()
} }
}
fun refresh() {} fun refresh() {}
......
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