From aa8f3c8dd46561c2bafabf54c52a510b7fad3c3d Mon Sep 17 00:00:00 2001 From: Rohit Mane <53574579+12ohit@users.noreply.github.com> Date: Thu, 14 Jul 2022 01:06:42 +0530 Subject: [PATCH] Fix inverted playback time crash (#661) Fixes the bug where player will crash while trying to invert time while video is not loaded Co-authored-by: jmir1 --- .../tachiyomi/ui/player/PlayerActivity.kt | 2 +- .../tachiyomi/ui/player/PlayerControlsView.kt | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 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 11fb103ff..9b17b458e 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 @@ -1456,7 +1456,7 @@ class PlayerActivity : playerControls.updatePlaybackPos(value.toInt()) if (preferences.invertedDurationTxt().get()) playerControls.updatePlaybackDuration(value.toInt()) } - "duration" -> playerControls.updatePlaybackDuration(value.toInt()) + "duration" -> if (!preferences.invertedDurationTxt().get()) playerControls.updatePlaybackDuration(value.toInt()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerControlsView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerControlsView.kt index c273e0a61..a5b18eee9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerControlsView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerControlsView.kt @@ -161,21 +161,23 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr binding.controlsSkipIntroBtn.setOnLongClickListener { skipIntroLengthDialog(); true } binding.playbackPositionBtn.setOnClickListener { - preferences.invertedDurationTxt().set(false) - preferences.invertedPlaybackTxt().set(!preferences.invertedPlaybackTxt().get()) - if (activity.player.timePos != null) { + if (activity.player.timePos != null && activity.player.duration != null) { + preferences.invertedDurationTxt().set(false) + preferences.invertedPlaybackTxt().set(!preferences.invertedPlaybackTxt().get()) updatePlaybackPos(activity.player.timePos!!) updatePlaybackDuration(activity.player.duration!!) } } binding.playbackDurationBtn.setOnClickListener { - preferences.invertedPlaybackTxt().set(false) - preferences.invertedDurationTxt().set(!preferences.invertedDurationTxt().get()) - if (preferences.invertedDurationTxt().get() && activity.player.timePos != null) { - updatePlaybackPos(activity.player.timePos!!) - updatePlaybackDuration(activity.player.timePos!!) - } else updatePlaybackDuration(activity.player.duration!!) + if (activity.player.timePos != null && activity.player.duration != null) { + preferences.invertedPlaybackTxt().set(false) + preferences.invertedDurationTxt().set(!preferences.invertedDurationTxt().get()) + if (preferences.invertedDurationTxt().get()) { + updatePlaybackPos(activity.player.timePos!!) + updatePlaybackDuration(activity.player.timePos!!) + } else updatePlaybackDuration(activity.player.duration!!) + } } binding.toggleAutoplay.setOnCheckedChangeListener { _, isChecked ->