Commit 6dbccfca by Paktalin

Enables/disables popup menu according to the tag selection

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