From 45c3c05f011244bac11b94006bed7f75c5da65fa Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 24 Feb 2024 13:13:35 +0200 Subject: [PATCH] Fix updating history in incognito mode #783 --- .../org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt | 1 + .../koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt | 5 ++++- .../org/koitharu/kotatsu/details/ui/DetailsViewModel.kt | 1 + .../org/koitharu/kotatsu/history/data/HistoryRepository.kt | 4 ++-- .../koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt | 1 + .../org/koitharu/kotatsu/history/domain/MarkAsReadUseCase.kt | 1 + 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt index bbc70b8db..24c33b620 100644 --- a/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt +++ b/app/src/androidTest/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt @@ -57,6 +57,7 @@ class AppShortcutManagerTest { page = 4, scroll = 2, percent = 0.3f, + force = false, ) awaitUpdate() diff --git a/app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt b/app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt index 40e97ea7c..f01cc9521 100644 --- a/app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt +++ b/app/src/androidTest/kotlin/org/koitharu/kotatsu/settings/backup/AppBackupAgentTest.kt @@ -7,7 +7,9 @@ import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest -import org.junit.Assert.* +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -61,6 +63,7 @@ class AppBackupAgentTest { page = 3, scroll = 40, percent = 0.2f, + force = false, ) val history = checkNotNull(historyRepository.getOne(SampleData.manga)) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index e9f6d59a2..d79a9fb73 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -320,6 +320,7 @@ class DetailsViewModel @Inject constructor( page = 0, scroll = 0, percent = percent, + force = true, ) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt index 5d2e06292..5f075777c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt @@ -90,8 +90,8 @@ class HistoryRepository @Inject constructor( .distinctUntilChanged() } - suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int, percent: Float) { - if (shouldSkip(manga)) { + suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int, percent: Float, force: Boolean) { + if (!force && shouldSkip(manga)) { return } db.withTransaction { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt index a0af9d1a8..2af13e3fc 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt @@ -24,6 +24,7 @@ class HistoryUpdateUseCase @Inject constructor( page = readerState.page, scroll = readerState.scroll, percent = percent, + force = false, ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/MarkAsReadUseCase.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/MarkAsReadUseCase.kt index cd24dbfc0..49dbb548c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/MarkAsReadUseCase.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/MarkAsReadUseCase.kt @@ -30,6 +30,7 @@ class MarkAsReadUseCase @Inject constructor( page = pages.lastIndex, scroll = 0, percent = 1f, + force = true, ) }