From f64b2f7f1bf2629f50bdd23693d0e3687d353f60 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Fri, 17 Jun 2022 01:58:55 +0200 Subject: [PATCH] added trailer animation --- .../cloudstream3/ui/player/CS3IPlayer.kt | 3 + .../ui/player/FullScreenPlayer.kt | 10 +++ .../cloudstream3/ui/result/ResultFragment.kt | 71 ++++++++++++------- .../ui/result/ResultTrailerPlayer.kt | 1 + app/src/main/res/layout/fragment_result.xml | 28 ++++++++ .../main/res/layout/trailer_custom_layout.xml | 18 +++-- 6 files changed, 102 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index 06a2c3a3..96fb8def 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -31,6 +31,7 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache import com.google.android.exoplayer2.util.MimeTypes import com.google.android.exoplayer2.video.VideoSize import com.lagradost.cloudstream3.APIHolder.getApiFromName +import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.USER_AGENT import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.mvvm.logError @@ -923,6 +924,8 @@ class CS3IPlayer : IPlayer { yt?.let { ytf -> ytVideos[ytLink] = ytf loadYtFile(context, ytf) + } ?: run { + playerError?.invoke(ErrorLoadingException("No Link")) } } } 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 7e9174b7..bd94560a 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 @@ -229,6 +229,15 @@ open class FullScreenPlayer : AbstractPlayerFragment() { } } + val playerSourceMove = if (isShowing) 0f else -50.toPx.toFloat() + player_open_source?.let { + ObjectAnimator.ofFloat(it, "translationY", playerSourceMove).apply { + duration = 200 + start() + } + } + + if (!isLocked) { player_ffwd_holder?.alpha = 1f player_rew_holder?.alpha = 1f @@ -251,6 +260,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() { } bottom_player_bar?.startAnimation(fadeAnimation) + player_open_source?.startAnimation(fadeAnimation) player_top_holder?.startAnimation(fadeAnimation) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index a1ddebe6..7ac6d149 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -50,6 +50,7 @@ import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick import com.lagradost.cloudstream3.ui.download.EasyDownloadButton +import com.lagradost.cloudstream3.ui.player.CSPlayerEvent import com.lagradost.cloudstream3.ui.player.GeneratorPlayer import com.lagradost.cloudstream3.ui.player.RepoLinkGenerator import com.lagradost.cloudstream3.ui.player.SubtitleData @@ -88,8 +89,10 @@ import com.lagradost.cloudstream3.utils.VideoDownloadManager.getFileName import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename import kotlinx.android.synthetic.main.fragment_result.* import kotlinx.android.synthetic.main.fragment_result_swipe.* +import kotlinx.android.synthetic.main.fragment_trailer.* import kotlinx.android.synthetic.main.result_recommendations.* import kotlinx.android.synthetic.main.result_sync.* +import kotlinx.android.synthetic.main.trailer_custom_layout.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.runBlocking @@ -608,36 +611,42 @@ class ResultFragment : ResultTrailerPlayer() { } override fun playerError(exception: Exception) { - if (player.getIsPlaying()) // because we dont want random toasts in player + if (player.getIsPlaying()) { // because we dont want random toasts in player super.playerError(exception) + } else { + nextMirror() + } } private fun loadTrailer(index: Int? = null) { - currentTrailers.getOrNull(index ?: currentTrailerIndex)?.let { trailer -> - //if(trailer.contains("youtube.com")) { // wont load in exo - // nextMirror() - // return - //} - context?.let { ctx -> - player.onPause() - player.loadPlayer( - ctx, - false, - ExtractorLink( - "", - "Trailer", - trailer, - "", - Qualities.Unknown.value - ), - null, - startPosition = 0L, - subtitles = emptySet(), - subtitle = null, - autoPlay = false - ) + val isSuccess = + currentTrailers.getOrNull(index ?: currentTrailerIndex)?.let { trailer -> + context?.let { ctx -> + player.onPause() + player.loadPlayer( + ctx, + false, + ExtractorLink( + "", + "Trailer", + trailer, + "", + Qualities.Unknown.value + ), + null, + startPosition = 0L, + subtitles = emptySet(), + subtitle = null, + autoPlay = false + ) + true + } ?: run { + false + } + } ?: run { + false } - } + result_trailer_loading?.isVisible = isSuccess } private fun setTrailers(trailers: List?) { @@ -758,6 +767,12 @@ class ResultFragment : ResultTrailerPlayer() { result_overlapping_panels?.setStartPanelLockState(OverlappingPanelsLayout.LockState.CLOSE) result_overlapping_panels?.setEndPanelLockState(OverlappingPanelsLayout.LockState.CLOSE) + player_open_source?.setOnClickListener { + currentTrailers.getOrNull(currentTrailerIndex)?.let { + context?.openBrowser(it) + } + } + updateUIListener = ::updateUI val restart = arguments?.getBoolean(RESTART_BUNDLE) ?: false @@ -828,6 +843,12 @@ class ResultFragment : ResultTrailerPlayer() { } else if (dy < -5) { result_bookmark_fab?.extend() } + if (!isFullScreenPlayer && player.getIsPlaying()) { + if (scrollY > (player_background?.height ?: scrollY)) { + player.handleEvent(CSPlayerEvent.Pause) + } + } + //result_poster_blur_holder?.translationY = -scrollY.toFloat() }) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt index ebc2c5be..b513a4c1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt @@ -53,6 +53,7 @@ open class ResultTrailerPlayer : com.lagradost.cloudstream3.ui.player.FullScreen screenHeight } + result_trailer_loading?.isVisible = false player_background?.apply { isVisible = true layoutParams = diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index 4c1aef8a..3a9de7ad 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -138,6 +138,34 @@ android:background="?attr/primaryBlackBackground" android:orientation="vertical"> + + + + + + + + - + + + android:layout_marginEnd="20dp" + android:layout_width="30dp" + android:layout_height="30dp" />