From 1e54bc798374b969e6afa062470b6ef2355393ff Mon Sep 17 00:00:00 2001 From: Jannik Date: Tue, 18 Jan 2022 18:03:56 +0100 Subject: [PATCH] don't show next ep button or autoplay if the current ep is the last ep next_episode_id can be non null, even if it's the last episode --- .../ui/activity/player/PlayerActivity.kt | 21 ++++++++++++------- .../ui/activity/player/PlayerViewModel.kt | 9 ++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt index f7ab2eb..677e056 100644 --- a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt +++ b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt @@ -229,7 +229,7 @@ class PlayerActivity : AppCompatActivity() { else -> View.VISIBLE } - if (state == ExoPlayer.STATE_ENDED && model.currentEpisode.nextEpisodeId != null && Preferences.autoplay) { + if (state == ExoPlayer.STATE_ENDED && hasNextEpisode() && Preferences.autoplay) { playNextEpisode() } } @@ -301,7 +301,7 @@ class PlayerActivity : AppCompatActivity() { // if remaining time < 20 sec, a next ep is set, autoplay is enabled and not in pip: // show next ep button if (remainingTime in 1..20000) { - if (!btnNextEpIsVisible && model.currentEpisode.nextEpisodeId != null && Preferences.autoplay && !isInPiPMode()) { + if (!btnNextEpIsVisible && hasNextEpisode() && Preferences.autoplay && !isInPiPMode()) { showButtonNextEp() } } else if (btnNextEpIsVisible) { @@ -358,12 +358,17 @@ class PlayerActivity : AppCompatActivity() { private fun onMediaChanged() { exo_text_title.text = model.getMediaTitle() - // hide the next ep button, if there is none - button_next_ep_c.visibility = if (model.currentEpisode.nextEpisodeId == null) { - View.GONE - } else { - View.VISIBLE - } + // hide the next episode button, if there is none + button_next_ep_c.visibility = if (hasNextEpisode()) View.VISIBLE else View.GONE + } + + /** + * Check if the current episode has a next episode. + * + * @return Boolean: true if there is a next episode, else false. + */ + private fun hasNextEpisode(): Boolean { + return (model.currentEpisode.nextEpisodeId != null && !model.currentEpisodeIsLastEpisode()) } /** diff --git a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt index 4a50821..0ea2834 100644 --- a/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt +++ b/app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt @@ -250,6 +250,15 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application) } } + /** + * Check if the current episode is the last in the episodes list. + * + * @return Boolean: true if it is the last, else false. + */ + fun currentEpisodeIsLastEpisode(): Boolean { + return episodes.items.lastOrNull()?.id == currentEpisode.id + } + fun getEpisodeMetaByAoDMediaId(aodMediaId: Int): EpisodeMeta? { val meta = mediaMeta return if (meta is TVShowMeta) {