From 98749190c27c6b70c93de04d171acddc56d369d2 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 19 Mar 2020 23:14:59 -0400 Subject: [PATCH] Changed the library list swipe animation speed to be more like the play store --- .../ui/library/LibraryListController.kt | 45 ++++++++++--------- .../kanade/tachiyomi/ui/main/MainActivity.kt | 8 ++-- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index df5e783b6d..a08453c077 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -39,6 +39,11 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative +import kotlinx.android.synthetic.main.filter_bottom_sheet.* +import kotlinx.android.synthetic.main.library_grid_recycler.* +import kotlinx.android.synthetic.main.library_list_controller.* +import kotlinx.android.synthetic.main.main_activity.* +import kotlinx.coroutines.delay import java.util.Locale import kotlin.math.abs import kotlin.math.max @@ -46,11 +51,6 @@ import kotlin.math.min import kotlin.math.pow import kotlin.math.roundToInt import kotlin.math.sign -import kotlinx.android.synthetic.main.filter_bottom_sheet.* -import kotlinx.android.synthetic.main.library_grid_recycler.* -import kotlinx.android.synthetic.main.library_list_controller.* -import kotlinx.android.synthetic.main.main_activity.* -import kotlinx.coroutines.delay class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, @@ -193,7 +193,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), recycler_layout.x = sign * distance.pow(0.6f) recycler_layout.alpha = 1f } else if (distance <= swipeDistance * 1.1f) { - recycler_layout.x = (max(0f, distance - 50f) * sign) / 3 + recycler_layout.x = sign * (distance / 100f).pow(3.5f) recycler_layout.alpha = (1f - (distance - (swipeDistance * 0.1f)) / swipeDistance) if (moved) { @@ -205,13 +205,9 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1) moved = true } - recycler_layout.x = ((distance - swipeDistance * 2) * sign) / 3 + recycler_layout.x = -sign * (max(0f, (swipeDistance * 2 - distance)) / 100f) + .pow(3.5f) recycler_layout.alpha = ((distance - swipeDistance * 1.1f) / swipeDistance) - if (sign > 0) { - recycler_layout.x = min(0f, recycler_layout.x) - } else { - recycler_layout.x = max(0f, recycler_layout.x) - } recycler_layout.alpha = min(1f, recycler_layout.alpha) } } @@ -701,10 +697,10 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), } } - override fun onSwipeLeft(x: Float, y: Float) = goToNextCategory(x) - override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x) + override fun onSwipeLeft(x: Float, xPos: Float) = goToNextCategory(x, xPos) + override fun onSwipeRight(x: Float, xPos: Float) = goToNextCategory(x, xPos) - private fun goToNextCategory(x: Float) { + private fun goToNextCategory(x: Float, xPos: Float) { if (lockedRecycler && abs(x) > 1000f) { val sign = sign(x).roundToInt() if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null) return @@ -714,10 +710,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), flinging = true val duration = (distance * 100 * speed).toLong() val set = AnimatorSet() - val translationXAnimator = ValueAnimator.ofFloat(recycler_layout.x, sign * 100f) + val translationXAnimator = ValueAnimator.ofFloat(abs(xPos - startPosX!!), + swipeDistance) translationXAnimator.duration = duration translationXAnimator.addUpdateListener { animation -> - recycler_layout.x = animation.animatedValue as Float + recycler_layout.x = sign * (animation.animatedValue as Float / 100f).pow(3.5f) } val translationAlphaAnimator = ValueAnimator.ofFloat(recycler_layout.alpha, 0f) @@ -729,12 +726,16 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), set.start() set.addListener(object : Animator.AnimatorListener { override fun onAnimationEnd(animation: Animator?) { - recycler_layout.x = -sign * 100f + recycler_layout.x = -sign * (swipeDistance / 100f).pow(3.5f) recycler_layout.alpha = 0f - scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1) - resetScrollingValues() - resetRecyclerY(true, (100 * speed).toLong()) - flinging = false + recycler_layout.post { + scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1) + recycler_layout.post { + resetScrollingValues() + resetRecyclerY(true, (100 * speed).toLong()) + flinging = false + } + } } override fun onAnimationCancel(animation: Animator?) {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index af72d12b5d..73c8b0e25a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -676,9 +676,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { ) <= Companion.SWIPE_THRESHOLD * 0.75f ) { if (diffX > 0) { - currentGestureDelegate?.onSwipeRight(velocityX, e1.y) + currentGestureDelegate?.onSwipeRight(velocityX, e2.x) } else { - currentGestureDelegate?.onSwipeLeft(velocityX, e1.y) + currentGestureDelegate?.onSwipeLeft(velocityX, e2.x) } result = true } @@ -733,8 +733,8 @@ interface OnTouchEventInterface { } interface SwipeGestureInterface { - fun onSwipeRight(x: Float, y: Float) - fun onSwipeLeft(x: Float, y: Float) + fun onSwipeRight(x: Float, xPos: Float) + fun onSwipeLeft(x: Float, xPos: Float) fun onSwipeTop(x: Float, y: Float) fun onSwipeBottom(x: Float, y: Float) }