From c9c0f3d01431a1008669d2a04bb6a5c87ccca645 Mon Sep 17 00:00:00 2001 From: Andreas E Date: Sun, 29 Nov 2020 17:15:15 +0100 Subject: [PATCH] Enhance incognito mode (#4073) * When in Incognito Mode don't set lastUsedSource * When in Incognito Mode don't save chapter progress Still allows tracking and mark as read when reaching last page * When in Incognito Mode don't mark as read (overwritten if hasTrackers) --- .../ui/browse/source/SourceController.kt | 4 ++- .../tachiyomi/ui/reader/ReaderPresenter.kt | 25 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index 72ce7529c9..dd9c7c81b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -194,7 +194,9 @@ class SourceController : * Opens a catalogue with the given controller. */ private fun openSource(source: CatalogueSource, controller: BrowseSourceController) { - preferences.lastUsedSource().set(source.id) + if (!preferences.incognitoMode().get()) { + preferences.lastUsedSource().set(source.id) + } parentController!!.router.pushController(controller.withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 7068022621..4c35fa7183 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -133,6 +133,13 @@ class ReaderPresenter( }.map(::ReaderChapter) } + private var hasTrackers: Boolean = false + private val checkTrackers: (Manga) -> Unit = { manga -> + val tracks = db.getTracks(manga).executeAsBlocking() + + hasTrackers = tracks.size > 0 + } + /** * Called when the presenter is created. It retrieves the saved active chapter if the process * was restored. @@ -224,6 +231,8 @@ class ReaderPresenter( this.manga = manga if (chapterId == -1L) chapterId = initialChapterId + checkTrackers(manga) + val context = Injekt.get() val source = sourceManager.getOrStub(manga.source) loader = ChapterLoader(context, downloadManager, manga, source) @@ -357,7 +366,8 @@ class ReaderPresenter( // Save last page read and mark as read if needed selectedChapter.chapter.last_page_read = page.index - if (selectedChapter.pages?.lastIndex == page.index) { + val shouldTrack = !preferences.incognitoMode().get() || hasTrackers + if (selectedChapter.pages?.lastIndex == page.index && shouldTrack) { selectedChapter.chapter.read = true updateTrackChapterRead(selectedChapter) deleteChapterIfNeeded(selectedChapter) @@ -408,16 +418,19 @@ class ReaderPresenter( /** * Saves this [chapter] progress (last read page and whether it's read). + * If incognito mode isn't on or has at least 1 tracker */ private fun saveChapterProgress(chapter: ReaderChapter) { - db.updateChapterProgress(chapter.chapter).asRxCompletable() - .onErrorComplete() - .subscribeOn(Schedulers.io()) - .subscribe() + if (!preferences.incognitoMode().get() || hasTrackers) { + db.updateChapterProgress(chapter.chapter).asRxCompletable() + .onErrorComplete() + .subscribeOn(Schedulers.io()) + .subscribe() + } } /** - * Saves this [chapter] last read history. + * Saves this [chapter] last read history if incognito mode isn't on. */ private fun saveChapterHistory(chapter: ReaderChapter) { if (!preferences.incognitoMode().get()) {