diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index 652f276f2..e5c76789f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -187,7 +187,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { if (historyByMangaId.isNotEmpty()) { val history = historyByMangaId.map { history -> val chapter = handler.awaitOne { chaptersQueries.getChapterById(history.chapter_id) } - BackupHistory(chapter.url, history.last_read?.time ?: 0L) + BackupHistory(chapter.url, history.last_read?.time ?: 0L, history.time_read) } if (history.isNotEmpty()) { mangaObject.history = history @@ -295,11 +295,14 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { internal suspend fun restoreHistoryForManga(history: List) { // List containing history to be updated val toUpdate = mutableListOf() - for ((url, lastRead) in history) { + for ((url, lastRead, readDuration) in history) { var dbHistory = handler.awaitOneOrNull { historyQueries.getHistoryByChapterUrl(url) } // Check if history already in database and update if (dbHistory != null) { - dbHistory = dbHistory.copy(last_read = Date(max(lastRead, dbHistory.last_read?.time ?: 0L))) + dbHistory = dbHistory.copy( + last_read = Date(max(lastRead, dbHistory.last_read?.time ?: 0L)), + time_read = max(readDuration, dbHistory.time_read) - dbHistory.time_read, + ) toUpdate.add( HistoryUpdate( chapterId = dbHistory.chapter_id, @@ -316,7 +319,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { HistoryUpdate( chapterId = it._id, readAt = Date(lastRead), - sessionReadDuration = 0, + sessionReadDuration = readDuration, ), ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt index e32086bb0..978102f74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt @@ -63,7 +63,8 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa val manga = backupManga.getMangaImpl() val chapters = backupManga.getChaptersImpl() val categories = backupManga.categories.map { it.toInt() } - val history = backupManga.brokenHistory.map { BackupHistory(it.url, it.lastRead) } + backupManga.history + val history = + backupManga.brokenHistory.map { BackupHistory(it.url, it.lastRead, it.readDuration) } + backupManga.history val tracks = backupManga.getTrackingImpl() try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt index 790e433c9..a2b66cced 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt @@ -7,10 +7,12 @@ import kotlinx.serialization.protobuf.ProtoNumber data class BrokenBackupHistory( @ProtoNumber(0) var url: String, @ProtoNumber(1) var lastRead: Long, + @ProtoNumber(2) var readDuration: Long = 0, ) @Serializable data class BackupHistory( @ProtoNumber(1) var url: String, @ProtoNumber(2) var lastRead: Long, + @ProtoNumber(3) var readDuration: Long = 0, )