fix progress saving properly (#657)

This commit is contained in:
Quickdesh 2022-07-13 01:37:57 +05:30 committed by GitHub
parent 3489dbe7c1
commit 7fd286acd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View file

@ -470,16 +470,12 @@ class PlayerActivity :
*/ */
internal fun switchEpisode(previous: Boolean, autoPlay: Boolean = false) { internal fun switchEpisode(previous: Boolean, autoPlay: Boolean = false) {
val switchMethod = if (previous && !autoPlay) { val switchMethod = if (previous && !autoPlay) {
{ callback: () -> Unit -> presenter.previousEpisode(callback) } { callback: () -> Unit -> presenter.previousEpisode(player.timePos, player.duration, callback) }
} else { } 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 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 val wasPlayerPaused = player.paused
player.paused = true player.paused = true
showLoadingIndicator(true) showLoadingIndicator(true)

View file

@ -234,10 +234,17 @@ class PlayerPresenter(
return source is AnimeHttpSource && !EpisodeLoader.isDownloaded(currentEpisode, anime) 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 anime = anime ?: return null
val source = sourceManager.getOrStub(anime.source) val source = sourceManager.getOrStub(anime.source)
val progressEpisode = currentEpisode
launchIO {
saveEpisodeProgress(pos, duration, progressEpisode)
saveEpisodeHistory()
}
val index = getCurrentEpisodeIndex() val index = getCurrentEpisodeIndex()
if (index == episodeList.lastIndex) return null if (index == episodeList.lastIndex) return null
currentEpisode = episodeList[index + 1] currentEpisode = episodeList[index + 1]
@ -264,10 +271,17 @@ class PlayerPresenter(
return anime.title + " - " + episodeList[index + 1].name 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 anime = anime ?: return null
val source = sourceManager.getOrStub(anime.source) val source = sourceManager.getOrStub(anime.source)
val progressEpisode = currentEpisode
launchIO {
saveEpisodeProgress(pos, duration, progressEpisode)
saveEpisodeHistory()
}
val index = getCurrentEpisodeIndex() val index = getCurrentEpisodeIndex()
if (index == 0) return null if (index == 0) return null
currentEpisode = episodeList[index - 1] 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 if (incognitoMode) return
val episode = currentEpisode ?: return if (episode == null) return
val seconds = (pos ?: return) * 1000L val seconds = (pos ?: return) * 1000L
val totalSeconds = (duration ?: return) * 1000L val totalSeconds = (duration ?: return) * 1000L
if (totalSeconds > 0L) { if (totalSeconds > 0L) {