mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-09 18:48:55 +01:00
Action toolbar code cleanup
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.MenuRes
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.android.synthetic.main.common_action_toolbar.view.common_action_menu
|
||||
import kotlinx.android.synthetic.main.common_action_toolbar.view.common_action_toolbar
|
||||
|
||||
/**
|
||||
* A toolbar holding only menu items.
|
||||
*/
|
||||
class ActionToolbar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
FrameLayout(context, attrs) {
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.common_action_toolbar, this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove menu items and remove listener.
|
||||
*/
|
||||
fun destroy() {
|
||||
common_action_menu.menu.clear()
|
||||
common_action_menu.setOnMenuItemClickListener(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a menu item if found.
|
||||
*/
|
||||
fun findItem(@IdRes itemId: Int): MenuItem? {
|
||||
return common_action_menu.menu.findItem(itemId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the menu toolbar using the provided ActionMode's context to inflate the items.
|
||||
*/
|
||||
fun show(mode: ActionMode, @MenuRes menuRes: Int, listener: (item: MenuItem?) -> Boolean) {
|
||||
// Avoid re-inflating the menu
|
||||
if (common_action_menu.menu.size() == 0) {
|
||||
mode.menuInflater.inflate(menuRes, common_action_menu.menu)
|
||||
common_action_menu.setOnMenuItemClickListener { listener(it) }
|
||||
}
|
||||
|
||||
common_action_toolbar.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the menu toolbar.
|
||||
*/
|
||||
fun hide() {
|
||||
common_action_toolbar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
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.IdRes
|
||||
import androidx.annotation.MenuRes
|
||||
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
|
||||
|
||||
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 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 findItem(@IdRes itemId: Int): MenuItem? {
|
||||
return bottom_menu.menu.findItem(itemId)
|
||||
}
|
||||
|
||||
fun show(menuInflater: MenuInflater) {
|
||||
// Avoid re-inflating the menu
|
||||
if (bottom_menu.menu.size() == 0) {
|
||||
menuInflater.inflate(menuRes, bottom_menu.menu)
|
||||
}
|
||||
|
||||
bottom_menu_bar.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
fun hide() {
|
||||
bottom_menu_bar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user