mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-30 02:05:00 -05:00
Save read duration to backup (#7672)
* Save read duration to backup * Add default value Co-authored-by: Andreas <andreas.everos@gmail.com> Co-authored-by: Andreas <andreas.everos@gmail.com>
This commit is contained in:
parent
737cf9898d
commit
3d4e56948d
3 changed files with 11 additions and 5 deletions
|
@ -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,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa
|
||||||
val manga = backupManga.getMangaImpl()
|
val manga = backupManga.getMangaImpl()
|
||||||
val chapters = backupManga.getChaptersImpl()
|
val chapters = backupManga.getChaptersImpl()
|
||||||
val categories = backupManga.categories.map { it.toInt() }
|
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()
|
val tracks = backupManga.getTrackingImpl()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -7,10 +7,12 @@ import kotlinx.serialization.protobuf.ProtoNumber
|
||||||
data class BrokenBackupHistory(
|
data class BrokenBackupHistory(
|
||||||
@ProtoNumber(0) var url: String,
|
@ProtoNumber(0) var url: String,
|
||||||
@ProtoNumber(1) var lastRead: Long,
|
@ProtoNumber(1) var lastRead: Long,
|
||||||
|
@ProtoNumber(2) var readDuration: Long = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BackupHistory(
|
data class BackupHistory(
|
||||||
@ProtoNumber(1) var url: String,
|
@ProtoNumber(1) var url: String,
|
||||||
@ProtoNumber(2) var lastRead: Long,
|
@ProtoNumber(2) var lastRead: Long,
|
||||||
|
@ProtoNumber(3) var readDuration: Long = 0,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue