* Add initial code for scaling animations, apply scale to reader nav overlay * Rename extension function, apply system animator scale to ActionToolbar * Apply system animator scale to expanding manga cover animation * Apply system animator scale to image crossfade (also disables animated covers when browsing) * Add documentation, make MotionScene Transition comment a bit more clear * Disable animated covers in MangaInfoHeaderAdapter if animator duration scale is 0 * Disable animated covers in Library if animator duration scale is 0 * Convert loadAny listener to extension function (cherry picked from commit df683375b1d7a15c03d315e85d4a0327b49f8ceb) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryComfortableGridHolder.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCompactGridHolder.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt
74 lines
2.4 KiB
Kotlin
74 lines
2.4 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
|
|
import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale
|
|
import eu.kanade.tachiyomi.widget.listener.SimpleAnimationListener
|
|
|
|
/**
|
|
* 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)
|
|
bottomAnimation.applySystemAnimatorScale(context)
|
|
binding.actionToolbar.startAnimation(bottomAnimation)
|
|
}
|
|
|
|
/**
|
|
* Hide the menu toolbar.
|
|
*/
|
|
fun hide() {
|
|
val bottomAnimation = AnimationUtils.loadAnimation(context, R.anim.exit_to_bottom)
|
|
bottomAnimation.applySystemAnimatorScale(context)
|
|
bottomAnimation.setAnimationListener(
|
|
object : SimpleAnimationListener() {
|
|
override fun onAnimationEnd(animation: Animation) {
|
|
binding.actionToolbar.isVisible = false
|
|
}
|
|
}
|
|
)
|
|
binding.actionToolbar.startAnimation(bottomAnimation)
|
|
}
|
|
}
|