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 891fe48a9..278f09dda 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 @@ -470,16 +470,12 @@ class PlayerActivity : */ internal fun switchEpisode(previous: Boolean, autoPlay: Boolean = false) { val switchMethod = if (previous && !autoPlay) { - { callback: () -> Unit -> presenter.previousEpisode(callback) } + { callback: () -> Unit -> presenter.previousEpisode(player.timePos, player.duration, callback) } } else { - { callback: () -> Unit -> presenter.nextEpisode(callback, autoPlay) } + { callback: () -> Unit -> presenter.nextEpisode(player.timePos, player.duration, callback, autoPlay) } } val errorRes = if (previous) R.string.no_previous_episode else R.string.no_next_episode - launchIO { - presenter.saveEpisodeProgress(player.timePos, player.duration) - presenter.saveEpisodeHistory() - } val wasPlayerPaused = player.paused player.paused = true showLoadingIndicator(true) 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 1ba1c7433..3757d1091 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 @@ -234,10 +234,17 @@ class PlayerPresenter( return source is AnimeHttpSource && !EpisodeLoader.isDownloaded(currentEpisode, anime) } - fun nextEpisode(callback: () -> Unit, fromStart: Boolean = false): String? { + fun nextEpisode(pos: Int?, duration: Int?, callback: () -> Unit, fromStart: Boolean = false): String? { val anime = anime ?: return null val source = sourceManager.getOrStub(anime.source) + val progressEpisode = currentEpisode + + launchIO { + saveEpisodeProgress(pos, duration, progressEpisode) + saveEpisodeHistory() + } + val index = getCurrentEpisodeIndex() if (index == episodeList.lastIndex) return null currentEpisode = episodeList[index + 1] @@ -264,10 +271,17 @@ class PlayerPresenter( return anime.title + " - " + episodeList[index + 1].name } - fun previousEpisode(callback: () -> Unit): String? { + fun previousEpisode(pos: Int?, duration: Int?, callback: () -> Unit): String? { val anime = anime ?: return null val source = sourceManager.getOrStub(anime.source) + val progressEpisode = currentEpisode + + launchIO { + saveEpisodeProgress(pos, duration, progressEpisode) + saveEpisodeHistory() + } + val index = getCurrentEpisodeIndex() if (index == 0) return null currentEpisode = episodeList[index - 1] @@ -301,9 +315,9 @@ class PlayerPresenter( ) } - suspend fun saveEpisodeProgress(pos: Int?, duration: Int?) { + suspend fun saveEpisodeProgress(pos: Int?, duration: Int?, episode: Episode? = currentEpisode) { if (incognitoMode) return - val episode = currentEpisode ?: return + if (episode == null) return val seconds = (pos ?: return) * 1000L val totalSeconds = (duration ?: return) * 1000L if (totalSeconds > 0L) {