@ -187,7 +187,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
if ( historyByMangaId . isNotEmpty ( ) ) {
if ( historyByMangaId . isNotEmpty ( ) ) {
val history = historyByMangaId . map { history ->
val history = historyByMangaId . map { history ->
val chapter = handler . awaitOne { chaptersQueries . getChapterById ( history . chapter _id ) }
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 ( ) ) {
if ( history . isNotEmpty ( ) ) {
mangaObject . history = history
mangaObject . history = history
@ -295,11 +295,14 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
internal suspend fun restoreHistoryForManga ( history : List < BackupHistory > ) {
internal suspend fun restoreHistoryForManga ( history : List < BackupHistory > ) {
// List containing history to be updated
// List containing history to be updated
val toUpdate = mutableListOf < HistoryUpdate > ( )
val toUpdate = mutableListOf < HistoryUpdate > ( )
for ( ( url , lastRead ) in history ) {
for ( ( url , lastRead , readDuration ) in history ) {
var dbHistory = handler . awaitOneOrNull { historyQueries . getHistoryByChapterUrl ( url ) }
var dbHistory = handler . awaitOneOrNull { historyQueries . getHistoryByChapterUrl ( url ) }
// Check if history already in database and update
// Check if history already in database and update
if ( dbHistory != null ) {
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 (
toUpdate . add (
HistoryUpdate (
HistoryUpdate (
chapterId = dbHistory . chapter _id ,
chapterId = dbHistory . chapter _id ,
@ -316,7 +319,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
HistoryUpdate (
HistoryUpdate (
chapterId = it . _id ,
chapterId = it . _id ,
readAt = Date ( lastRead ) ,
readAt = Date ( lastRead ) ,
sessionReadDuration = 0 ,
sessionReadDuration = readDuration ,
) ,
) ,
)
)
}
}