Fixed Fab Movement when snackbar is showing + Text fixes
This commit is contained in:
parent
d719cae942
commit
62af86c77a
@ -476,7 +476,7 @@ class LibraryController(
|
||||
val mangas = selectedMangas.toList()
|
||||
presenter.removeMangaFromLibrary(mangas, true)
|
||||
destroyActionModeIfNeeded()
|
||||
view?.snack(activity?.getString(R.string.remove_from_library) ?: "", 5000) {
|
||||
view?.snack(activity?.getString(R.string.manga_removed_library) ?: "", 5000) {
|
||||
setAction(R.string.action_undo) {
|
||||
presenter.addMangas(mangas)
|
||||
}
|
||||
|
@ -393,19 +393,19 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
||||
val view = view
|
||||
destroyActionModeIfNeeded()
|
||||
presenter.downloadChapters(chapters)
|
||||
if (view != null && !presenter.manga.favorite) {
|
||||
snack = view.snack(view.context.getString(R.string.snack_add_to_library), Snackbar
|
||||
.LENGTH_INDEFINITE) {
|
||||
setAction(R.string.action_add) {
|
||||
presenter.addToLibrary()
|
||||
}
|
||||
addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
|
||||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
||||
super.onDismissed(transientBottomBar, event)
|
||||
if (snack == transientBottomBar) snack = null
|
||||
if (view != null && !presenter.manga.favorite && (snack == null || snack?.getText() != view.context.getString(R.string.snack_add_to_library))) {
|
||||
snack =
|
||||
view.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) {
|
||||
setAction(R.string.action_add) {
|
||||
presenter.addToLibrary()
|
||||
}
|
||||
})
|
||||
}
|
||||
addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
|
||||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
||||
super.onDismissed(transientBottomBar, event)
|
||||
if (snack == transientBottomBar) snack = null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,11 @@ Int = 0) {
|
||||
ViewCompat.setElevation(this.view, 6f)
|
||||
}
|
||||
|
||||
fun Snackbar.getText(): CharSequence {
|
||||
val textView: TextView = view.findViewById(com.google.android.material.R.id.snackbar_text)
|
||||
return textView.text
|
||||
}
|
||||
|
||||
inline fun View.visible() {
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ abstract class FABAnimationBase : FloatingActionButton.Behavior() {
|
||||
|
||||
var isAnimatingOut = false
|
||||
|
||||
override fun onStartNestedScroll(coordinatorLayout: androidx.coordinatorlayout.widget.CoordinatorLayout, child: FloatingActionButton,
|
||||
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
|
||||
directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
|
||||
// Ensure we react to vertical scrolling
|
||||
return axes == ViewCompat.SCROLL_AXIS_VERTICAL ||
|
||||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
|
||||
}
|
||||
|
||||
override fun onNestedScroll(coordinatorLayout: androidx.coordinatorlayout.widget.CoordinatorLayout, child: FloatingActionButton,
|
||||
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
|
||||
target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int,
|
||||
dyUnconsumed: Int, type: Int) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type)
|
||||
|
@ -1,15 +1,17 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import eu.kanade.tachiyomi.R
|
||||
import timber.log.Timber
|
||||
import kotlin.math.min
|
||||
|
||||
@Suppress("unused", "UNUSED_PARAMETER")
|
||||
@ -53,18 +55,10 @@ class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: Attribut
|
||||
button.startAnimation(inAnimation)
|
||||
}
|
||||
|
||||
|
||||
override fun layoutDependsOn(parent: CoordinatorLayout, child: FloatingActionButton, dependency: View): Boolean {
|
||||
return dependency is Snackbar.SnackbarLayout
|
||||
}
|
||||
|
||||
override fun onDependentViewChanged(parent: CoordinatorLayout, child: FloatingActionButton, dependency: View): Boolean {
|
||||
val translationY = getFabTranslationYForSnackbar(parent, child)
|
||||
val percentComplete = -translationY / dependency.height
|
||||
val scaleFactor = 1 - percentComplete
|
||||
|
||||
child.translationY = -translationY
|
||||
return false
|
||||
child.translationY = translationY
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getFabTranslationYForSnackbar(parent: CoordinatorLayout, fab:
|
||||
@ -74,9 +68,15 @@ class FABAnimationUpDown @JvmOverloads constructor(ctx: Context, attrs: Attribut
|
||||
for (i in 0 until dependencies.size) {
|
||||
val view = dependencies[i]
|
||||
if (view is Snackbar.SnackbarLayout) {
|
||||
Timber.d("snack y: ${view.translationY}")
|
||||
minOffset = min(minOffset, view.translationY - view.height)
|
||||
}
|
||||
}
|
||||
return minOffset
|
||||
}
|
||||
|
||||
override fun getInsetDodgeRect(parent: CoordinatorLayout, child: FloatingActionButton, rect: Rect): Boolean {
|
||||
rect.set(child.left, child.top + 100, child.right, child.bottom - 1000)
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user