From a8477019e02e0b23cada82746ec5c578af33b9d9 Mon Sep 17 00:00:00 2001 From: jmir1 Date: Fri, 15 Apr 2022 17:16:04 +0200 Subject: [PATCH] make episode switch buttons unclickable --- .../tachiyomi/ui/player/PlayerActivity.kt | 15 ++++++-- .../tachiyomi/ui/player/PlayerPresenter.kt | 38 ++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt index 520b9544d..b84066577 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt @@ -276,6 +276,7 @@ class PlayerActivity : player.addObserver(this) Thread.setDefaultUncaughtExceptionHandler { _, throwable -> + launchUI { toast(throwable.message) } logcat(LogPriority.ERROR, throwable) finish() } @@ -633,10 +634,16 @@ class PlayerActivity : val plCount = presenter.episodeList.size val plPos = presenter.getCurrentEpisodeIndex() - val g = ContextCompat.getColor(this, R.color.tint_disabled) - val w = ContextCompat.getColor(this, R.color.tint_normal) - binding.playerControls.binding.prevBtn.imageTintList = ColorStateList.valueOf(if (plPos == 0) g else w) - binding.playerControls.binding.nextBtn.imageTintList = ColorStateList.valueOf(if (plPos == plCount - 1) g else w) + val grey = ContextCompat.getColor(this, R.color.tint_disabled) + val white = ContextCompat.getColor(this, R.color.tint_normal) + with(binding.playerControls.binding.prevBtn) { + this.imageTintList = ColorStateList.valueOf(if (plPos == 0) grey else white) + this.isClickable = plPos != 0 + } + with(binding.playerControls.binding.nextBtn) { + this.imageTintList = ColorStateList.valueOf(if (plPos == plCount - 1) grey else white) + this.isClickable = plPos != plCount - 1 + } } private fun updatePlaybackStatus(paused: Boolean) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt index f70d2fce2..defc3fd65 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerPresenter.kt @@ -164,17 +164,21 @@ class PlayerPresenter( currentEpisode = episodeList.first { initialEpisodeId == it.id } launchIO { try { - val currentEpisode = currentEpisode ?: throw Exception("bruh") + val currentEpisode = currentEpisode ?: throw Exception("No episode loaded.") EpisodeLoader.getLinks(currentEpisode, anime, source!!) .subscribeFirst( { activity, it -> currentVideoList = it - activity.setVideoList(it) + if (it.isNotEmpty()) { + activity.setVideoList(it) + } else { + activity.setInitialEpisodeError(Exception("Video list is empty.")) + } }, PlayerActivity::setInitialEpisodeError, ) } catch (e: Exception) { - logcat(LogPriority.ERROR, e) { e.message ?: "error getting links" } + logcat(LogPriority.ERROR, e) { e.message ?: "Error getting links." } } } } @@ -186,7 +190,7 @@ class PlayerPresenter( } fun nextEpisode(callback: () -> Unit): String? { - val anime = anime ?: return "Invalid" + val anime = anime ?: return null val source = sourceManager.getOrStub(anime.source) val index = getCurrentEpisodeIndex() @@ -194,25 +198,29 @@ class PlayerPresenter( currentEpisode = episodeList[index + 1] launchIO { try { - val currentEpisode = currentEpisode ?: throw Exception("bruh") + val currentEpisode = currentEpisode ?: throw Exception("No episode loaded.") EpisodeLoader.getLinks(currentEpisode, anime, source) .subscribeFirst( { activity, it -> currentVideoList = it - activity.setVideoList(it) - callback() + if (it.isNotEmpty()) { + activity.setVideoList(it) + callback() + } else { + activity.setInitialEpisodeError(Exception("Video list is empty.")) + } }, PlayerActivity::setInitialEpisodeError, ) } catch (e: Exception) { - logcat(LogPriority.ERROR, e) { e.message ?: "error getting links" } + logcat(LogPriority.ERROR, e) { e.message ?: "Error getting links." } } } return anime.title + " - " + episodeList[index + 1].name } fun previousEpisode(callback: () -> Unit): String? { - val anime = anime ?: return "Invalid" + val anime = anime ?: return null val source = sourceManager.getOrStub(anime.source) val index = getCurrentEpisodeIndex() @@ -220,18 +228,22 @@ class PlayerPresenter( currentEpisode = episodeList[index - 1] launchIO { try { - val currentEpisode = currentEpisode ?: throw Exception("bruh") + val currentEpisode = currentEpisode ?: throw Exception("No episode loaded.") EpisodeLoader.getLinks(currentEpisode, anime, source) .subscribeFirst( { activity, it -> currentVideoList = it - activity.setVideoList(it) - callback() + if (it.isNotEmpty()) { + activity.setVideoList(it) + callback() + } else { + activity.setInitialEpisodeError(Exception("Video list is empty.")) + } }, PlayerActivity::setInitialEpisodeError, ) } catch (e: Exception) { - logcat(LogPriority.ERROR, e) { e.message ?: "error getting links" } + logcat(LogPriority.ERROR, e) { e.message ?: "Error getting links." } } } return anime.title + " - " + episodeList[index - 1].name