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)
This commit is contained in:
Andreas E 2020-11-29 17:15:15 +01:00 committed by GitHub
parent ff66f307dd
commit c9c0f3d014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -194,7 +194,9 @@ class SourceController :
* Opens a catalogue with the given controller. * Opens a catalogue with the given controller.
*/ */
private fun openSource(source: CatalogueSource, controller: BrowseSourceController) { 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()) parentController!!.router.pushController(controller.withFadeTransaction())
} }

View File

@ -133,6 +133,13 @@ class ReaderPresenter(
}.map(::ReaderChapter) }.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 * Called when the presenter is created. It retrieves the saved active chapter if the process
* was restored. * was restored.
@ -224,6 +231,8 @@ class ReaderPresenter(
this.manga = manga this.manga = manga
if (chapterId == -1L) chapterId = initialChapterId if (chapterId == -1L) chapterId = initialChapterId
checkTrackers(manga)
val context = Injekt.get<Application>() val context = Injekt.get<Application>()
val source = sourceManager.getOrStub(manga.source) val source = sourceManager.getOrStub(manga.source)
loader = ChapterLoader(context, downloadManager, manga, source) loader = ChapterLoader(context, downloadManager, manga, source)
@ -357,7 +366,8 @@ class ReaderPresenter(
// Save last page read and mark as read if needed // Save last page read and mark as read if needed
selectedChapter.chapter.last_page_read = page.index 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 selectedChapter.chapter.read = true
updateTrackChapterRead(selectedChapter) updateTrackChapterRead(selectedChapter)
deleteChapterIfNeeded(selectedChapter) deleteChapterIfNeeded(selectedChapter)
@ -408,16 +418,19 @@ class ReaderPresenter(
/** /**
* Saves this [chapter] progress (last read page and whether it's read). * 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) { private fun saveChapterProgress(chapter: ReaderChapter) {
db.updateChapterProgress(chapter.chapter).asRxCompletable() if (!preferences.incognitoMode().get() || hasTrackers) {
.onErrorComplete() db.updateChapterProgress(chapter.chapter).asRxCompletable()
.subscribeOn(Schedulers.io()) .onErrorComplete()
.subscribe() .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) { private fun saveChapterHistory(chapter: ReaderChapter) {
if (!preferences.incognitoMode().get()) { if (!preferences.incognitoMode().get()) {