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
This commit is contained in:
Jannik 2022-01-18 18:03:56 +01:00
parent 87cc4c5ec1
commit 1e54bc7983
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
2 changed files with 22 additions and 8 deletions

View File

@ -229,7 +229,7 @@ class PlayerActivity : AppCompatActivity() {
else -> View.VISIBLE else -> View.VISIBLE
} }
if (state == ExoPlayer.STATE_ENDED && model.currentEpisode.nextEpisodeId != null && Preferences.autoplay) { if (state == ExoPlayer.STATE_ENDED && hasNextEpisode() && Preferences.autoplay) {
playNextEpisode() 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: // if remaining time < 20 sec, a next ep is set, autoplay is enabled and not in pip:
// show next ep button // show next ep button
if (remainingTime in 1..20000) { if (remainingTime in 1..20000) {
if (!btnNextEpIsVisible && model.currentEpisode.nextEpisodeId != null && Preferences.autoplay && !isInPiPMode()) { if (!btnNextEpIsVisible && hasNextEpisode() && Preferences.autoplay && !isInPiPMode()) {
showButtonNextEp() showButtonNextEp()
} }
} else if (btnNextEpIsVisible) { } else if (btnNextEpIsVisible) {
@ -358,12 +358,17 @@ class PlayerActivity : AppCompatActivity() {
private fun onMediaChanged() { private fun onMediaChanged() {
exo_text_title.text = model.getMediaTitle() exo_text_title.text = model.getMediaTitle()
// hide the next ep button, if there is none // hide the next episode button, if there is none
button_next_ep_c.visibility = if (model.currentEpisode.nextEpisodeId == null) { button_next_ep_c.visibility = if (hasNextEpisode()) View.VISIBLE else View.GONE
View.GONE }
} else {
View.VISIBLE /**
} * 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())
} }
/** /**

View File

@ -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? { fun getEpisodeMetaByAoDMediaId(aodMediaId: Int): EpisodeMeta? {
val meta = mediaMeta val meta = mediaMeta
return if (meta is TVShowMeta) { return if (meta is TVShowMeta) {