mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-25 14:19:27 +03:00
fix progress saving properly (#657)
This commit is contained in:
parent
3489dbe7c1
commit
7fd286acd9
2 changed files with 20 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue