From 744b0a3f58e24490e0c399ac85f318c8c05eb249 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 30 Oct 2019 20:53:14 -0700 Subject: [PATCH] More Fab work + Checks for duplicate snackbars --- .../ui/manga/chapter/ChaptersController.kt | 2 +- .../tachiyomi/widget/FABAnimationUpDown.kt | 2 -- .../tachiyomi/widget/FABMoveBehaviour.kt | 34 +++++++++++++++++++ app/src/main/res/values/styles.xml | 2 ++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index dda91f1519..916343baae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -121,7 +121,7 @@ class ChaptersController : NucleusController(), if (!reveal_view.showRevealEffect(coordinates.x, coordinates.y, revealAnimationListener)) { openChapter(item.chapter) } - } else { + } else if (snack == null || snack?.getText() != view.context.getString(R.string.no_next_chapter)) { snack = view.snack(R.string.no_next_chapter, Snackbar.LENGTH_LONG) { addCallback(object : BaseTransientBottomBar.BaseCallback() { override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt index 67d63b0c4c..6828382b56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/FABAnimationUpDown.kt @@ -11,7 +11,6 @@ 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") @@ -68,7 +67,6 @@ 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt new file mode 100644 index 0000000000..8d7d0ad25d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/FABMoveBehaviour.kt @@ -0,0 +1,34 @@ +package eu.kanade.tachiyomi.widget + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.snackbar.Snackbar +import kotlin.math.min + +class FABMoveBehaviour(context: Context, attrs: AttributeSet) : + CoordinatorLayout.Behavior(context, attrs) { + + 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) + child.translationY = translationY + return true + } + + private fun getFabTranslationYForSnackbar(parent: CoordinatorLayout, fab: FloatingActionButton): Float { + var minOffset = 0f + val dependencies = parent.getDependencies(fab) + for (i in 0 until dependencies.size) { + val view = dependencies[i] + if (view is Snackbar.SnackbarLayout) { + minOffset = min(minOffset, view.translationY - view.height) + } + } + return minOffset + } +} \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 50e68de444..dbd4611730 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -152,7 +152,9 @@ bottom|end @dimen/fab_margin fitCenter + bottom|right|end @color/md_white_1000 + eu.kanade.tachiyomi.widget.FABMoveBehaviour