mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-09 18:48:55 +01:00
Tweak how bottom action menu is configured
This commit is contained in:
@@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.widget
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.MenuRes
|
||||
import androidx.appcompat.widget.ActionMenuView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu
|
||||
import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu_bar
|
||||
@@ -14,15 +14,27 @@ import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu
|
||||
class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
FrameLayout(context, attrs) {
|
||||
|
||||
@MenuRes
|
||||
private var menuRes: Int = 0
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.common_bottom_action_menu, this)
|
||||
}
|
||||
|
||||
fun show(menuInflater: MenuInflater, @MenuRes menuRes: Int, listener: ActionMenuView.OnMenuItemClickListener) {
|
||||
fun configure(@MenuRes menuRes: Int, listener: (item: MenuItem?) -> Boolean) {
|
||||
this.menuRes = menuRes
|
||||
bottom_menu.setOnMenuItemClickListener { listener(it) }
|
||||
}
|
||||
|
||||
fun cleanup() {
|
||||
bottom_menu.menu.clear()
|
||||
bottom_menu.setOnMenuItemClickListener(null)
|
||||
}
|
||||
|
||||
fun show(menuInflater: MenuInflater) {
|
||||
// Avoid re-inflating the menu
|
||||
if (bottom_menu.menu.size() == 0) {
|
||||
menuInflater.inflate(menuRes, bottom_menu.menu)
|
||||
bottom_menu.setOnMenuItemClickListener(listener)
|
||||
}
|
||||
|
||||
bottom_menu_bar.visibility = View.VISIBLE
|
||||
@@ -30,8 +42,5 @@ class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: Attrib
|
||||
|
||||
fun hide() {
|
||||
bottom_menu_bar.visibility = View.GONE
|
||||
|
||||
bottom_menu.setOnMenuItemClickListener(null)
|
||||
bottom_menu.menu.clear()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user