mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 15:39:08 +01:00
Changed the library list swipe animation speed to be more like the play store
This commit is contained in:
parent
0fde1ba102
commit
98749190c2
@ -39,6 +39,11 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith
|
|||||||
import eu.kanade.tachiyomi.util.view.snack
|
import eu.kanade.tachiyomi.util.view.snack
|
||||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
||||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
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 java.util.Locale
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -46,11 +51,6 @@ import kotlin.math.min
|
|||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlin.math.sign
|
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),
|
class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
||||||
FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener,
|
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.x = sign * distance.pow(0.6f)
|
||||||
recycler_layout.alpha = 1f
|
recycler_layout.alpha = 1f
|
||||||
} else if (distance <= swipeDistance * 1.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 =
|
recycler_layout.alpha =
|
||||||
(1f - (distance - (swipeDistance * 0.1f)) / swipeDistance)
|
(1f - (distance - (swipeDistance * 0.1f)) / swipeDistance)
|
||||||
if (moved) {
|
if (moved) {
|
||||||
@ -205,13 +205,9 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
|||||||
scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1)
|
scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1)
|
||||||
moved = true
|
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)
|
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)
|
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 onSwipeLeft(x: Float, xPos: Float) = goToNextCategory(x, xPos)
|
||||||
override fun onSwipeRight(x: Float, y: Float) = goToNextCategory(x)
|
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) {
|
if (lockedRecycler && abs(x) > 1000f) {
|
||||||
val sign = sign(x).roundToInt()
|
val sign = sign(x).roundToInt()
|
||||||
if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null) return
|
if ((sign < 0 && nextCategory == null) || (sign > 0) && prevCategory == null) return
|
||||||
@ -714,10 +710,11 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
|||||||
flinging = true
|
flinging = true
|
||||||
val duration = (distance * 100 * speed).toLong()
|
val duration = (distance * 100 * speed).toLong()
|
||||||
val set = AnimatorSet()
|
val set = AnimatorSet()
|
||||||
val translationXAnimator = ValueAnimator.ofFloat(recycler_layout.x, sign * 100f)
|
val translationXAnimator = ValueAnimator.ofFloat(abs(xPos - startPosX!!),
|
||||||
|
swipeDistance)
|
||||||
translationXAnimator.duration = duration
|
translationXAnimator.duration = duration
|
||||||
translationXAnimator.addUpdateListener { animation ->
|
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)
|
val translationAlphaAnimator = ValueAnimator.ofFloat(recycler_layout.alpha, 0f)
|
||||||
@ -729,12 +726,16 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
|
|||||||
set.start()
|
set.start()
|
||||||
set.addListener(object : Animator.AnimatorListener {
|
set.addListener(object : Animator.AnimatorListener {
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
recycler_layout.x = -sign * 100f
|
recycler_layout.x = -sign * (swipeDistance / 100f).pow(3.5f)
|
||||||
recycler_layout.alpha = 0f
|
recycler_layout.alpha = 0f
|
||||||
scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1)
|
recycler_layout.post {
|
||||||
resetScrollingValues()
|
scrollToHeader((if (sign <= 0) nextCategory else prevCategory) ?: -1)
|
||||||
resetRecyclerY(true, (100 * speed).toLong())
|
recycler_layout.post {
|
||||||
flinging = false
|
resetScrollingValues()
|
||||||
|
resetRecyclerY(true, (100 * speed).toLong())
|
||||||
|
flinging = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAnimationCancel(animation: Animator?) {}
|
override fun onAnimationCancel(animation: Animator?) {}
|
||||||
|
@ -676,9 +676,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
) <= Companion.SWIPE_THRESHOLD * 0.75f
|
) <= Companion.SWIPE_THRESHOLD * 0.75f
|
||||||
) {
|
) {
|
||||||
if (diffX > 0) {
|
if (diffX > 0) {
|
||||||
currentGestureDelegate?.onSwipeRight(velocityX, e1.y)
|
currentGestureDelegate?.onSwipeRight(velocityX, e2.x)
|
||||||
} else {
|
} else {
|
||||||
currentGestureDelegate?.onSwipeLeft(velocityX, e1.y)
|
currentGestureDelegate?.onSwipeLeft(velocityX, e2.x)
|
||||||
}
|
}
|
||||||
result = true
|
result = true
|
||||||
}
|
}
|
||||||
@ -733,8 +733,8 @@ interface OnTouchEventInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface SwipeGestureInterface {
|
interface SwipeGestureInterface {
|
||||||
fun onSwipeRight(x: Float, y: Float)
|
fun onSwipeRight(x: Float, xPos: Float)
|
||||||
fun onSwipeLeft(x: Float, y: Float)
|
fun onSwipeLeft(x: Float, xPos: Float)
|
||||||
fun onSwipeTop(x: Float, y: Float)
|
fun onSwipeTop(x: Float, y: Float)
|
||||||
fun onSwipeBottom(x: Float, y: Float)
|
fun onSwipeBottom(x: Float, y: Float)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user