(cherry picked from commit 1f8c5b0120177ecd160110026ab2e018e20dd0c1) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
70 lines
2.2 KiB
Kotlin
70 lines
2.2 KiB
Kotlin
package eu.kanade.tachiyomi.widget
|
|
|
|
import android.content.Context
|
|
import android.util.AttributeSet
|
|
import android.view.LayoutInflater
|
|
import android.view.MenuItem
|
|
import android.view.animation.Animation
|
|
import android.view.animation.AnimationUtils
|
|
import android.widget.FrameLayout
|
|
import androidx.annotation.IdRes
|
|
import androidx.annotation.MenuRes
|
|
import androidx.appcompat.view.ActionMode
|
|
import androidx.core.view.isVisible
|
|
import eu.kanade.tachiyomi.R
|
|
import eu.kanade.tachiyomi.databinding.ActionToolbarBinding
|
|
|
|
/**
|
|
* A toolbar holding only menu items.
|
|
*/
|
|
class ActionToolbar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
|
FrameLayout(context, attrs) {
|
|
|
|
private val binding = ActionToolbarBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
/**
|
|
* Remove menu items and remove listener.
|
|
*/
|
|
fun destroy() {
|
|
binding.menu.menu.clear()
|
|
binding.menu.setOnMenuItemClickListener(null)
|
|
}
|
|
|
|
/**
|
|
* Gets a menu item if found.
|
|
*/
|
|
fun findItem(@IdRes itemId: Int): MenuItem? {
|
|
return binding.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 (binding.menu.menu.size() == 0) {
|
|
mode.menuInflater.inflate(menuRes, binding.menu.menu)
|
|
binding.menu.setOnMenuItemClickListener { listener(it) }
|
|
}
|
|
|
|
binding.actionToolbar.isVisible = true
|
|
val bottomAnimation = AnimationUtils.loadAnimation(context, R.anim.enter_from_bottom)
|
|
binding.actionToolbar.startAnimation(bottomAnimation)
|
|
}
|
|
|
|
/**
|
|
* Hide the menu toolbar.
|
|
*/
|
|
fun hide() {
|
|
val bottomAnimation = AnimationUtils.loadAnimation(context, R.anim.exit_to_bottom)
|
|
bottomAnimation.setAnimationListener(
|
|
object : SimpleAnimationListener() {
|
|
override fun onAnimationEnd(animation: Animation) {
|
|
binding.actionToolbar.isVisible = false
|
|
}
|
|
}
|
|
)
|
|
binding.actionToolbar.startAnimation(bottomAnimation)
|
|
}
|
|
}
|