From 882fe9555cbe37b94cdcedb02a09e3a0998e81fd Mon Sep 17 00:00:00 2001 From: KingLucius Date: Sun, 21 Jun 2026 09:33:57 +0300 Subject: [PATCH] Clean Player Animation code --- .../ui/player/FullScreenPlayer.kt | 112 ++++++++---------- 1 file changed, 50 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index 4ba933e1347..22a3888e4f3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -267,83 +267,70 @@ open class FullScreenPlayer : AbstractPlayerFragment( // The lib uses Invisible instead of Gone for no reason binding.previewFrameLayout.height - binding.bottomPlayerBar.height ) else -sStyle.elevation.toPx - ObjectAnimator.ofFloat(sView, "translationY", move.toFloat()).apply { - duration = 200 - start() - } - } - protected fun animateLayoutChanges() { - if (isLayout(PHONE)) { // isEnabled also disables the onKeyDown - playerBinding?.exoProgress?.isEnabled = isShowing // Prevent accidental clicks/drags + sView.animateY(move.toFloat()) } - if (isShowing) { - updateUIVisibility() - } else { - toggleEpisodesOverlay(false) - playerBinding?.playerHolder?.postDelayed({ updateUIVisibility() }, 200) + private fun View.animateY(value: Float) { + ObjectAnimator.ofFloat(this, "translationY", value).apply { + duration = 200 + start() } + } - val titleMove = if (isShowing) 0f else -50.toPx.toFloat() - playerBinding?.playerVideoTitleHolder?.let { - ObjectAnimator.ofFloat(it, "translationY", titleMove).apply { - duration = 200 - start() - } + private fun View.animateX(value: Float) { + ObjectAnimator.ofFloat(this, "translationX", value).apply { + duration = 200 + start() } - playerBinding?.playerVideoTitleRez?.let { - ObjectAnimator.ofFloat(it, "translationY", titleMove).apply { - duration = 200 - start() - } - } - playerBinding?.playerVideoInfo?.let { - ObjectAnimator.ofFloat(it, "translationY", titleMove).apply { - duration = 200 - start() + } + + protected fun animateLayoutChanges() { + + playerBinding?.apply { + + if (isLayout(PHONE)) { // isEnabled also disables the onKeyDown + exoProgress.isEnabled = isShowing // Prevent accidental clicks/drags } - } - playerBinding?.playerMetadataScrim?.let { - ObjectAnimator.ofFloat(it, "translationY", 1f).apply { - duration = 200 - start() + + if (isShowing) { + updateUIVisibility() + } else { + toggleEpisodesOverlay(false) + playerHolder.postDelayed({ updateUIVisibility() }, 200) } - } - val playerBarMove = if (isShowing) 0f else 50.toPx.toFloat() - playerBinding?.bottomPlayerBar?.let { - ObjectAnimator.ofFloat(it, "translationY", playerBarMove).apply { - duration = 200 - start() + val titleMove = if (isShowing) 0f else -50.toPx.toFloat() + + listOfNotNull( + playerVideoTitleHolder, + playerVideoTitleRez, + playerVideoInfo, + playerGoBackHolder, + ).forEach { + it.animateY(titleMove) } - } - if (isLayout(PHONE)) { - playerBinding?.playerEpisodesButton?.let { - ObjectAnimator.ofFloat(it, "translationX", if (isShowing) 0f else 50.toPx.toFloat()) - .apply { - duration = 200 - start() - } + + playerMetadataScrim.animateY(1f) + + val playerBarMove = if (isShowing) 0f else 50.toPx.toFloat() + bottomPlayerBar.animateY(playerBarMove) + + if (isLayout(PHONE)) { + playerEpisodesButton.animateX(if (isShowing) 0f else 50.toPx.toFloat()) } - } - val fadeTo = if (isShowing) 1f else 0f - val fadeAnimation = AlphaAnimation(1f - fadeTo, fadeTo) - fadeAnimation.duration = 100 - fadeAnimation.fillAfter = true + val fadeTo = if (isShowing) 1f else 0f + val fadeAnimation = AlphaAnimation(1f - fadeTo, fadeTo) - animateLayoutChangesForSubtitles() + fadeAnimation.duration = 100 + fadeAnimation.fillAfter = true - val playerSourceMove = if (isShowing) 0f else -50.toPx.toFloat() + animateLayoutChangesForSubtitles() - playerBinding?.apply { - playerOpenSource.let { - ObjectAnimator.ofFloat(it, "translationY", playerSourceMove).apply { - duration = 200 - start() - } - } + val playerSourceMove = if (isShowing) 0f else -50.toPx.toFloat() + + playerOpenSource.animateY(playerSourceMove) if (!isLocked) { playerHostView?.gestureHelper?.animateCenterControls(fadeTo) @@ -1013,6 +1000,7 @@ open class FullScreenPlayer : AbstractPlayerFragment( } toggleEpisodesOverlay(true) } + else -> return null // Avoid capturing all input } return true