Show notification to disable Incognito Mode when it's enabled (#4976)

* Show notification to disable Incognito Mode when it's enabled

* Finish ReaderActivity and BrowseSourceController when incognito is disabled

* CLeanup strings

* Only register DisableIncognitoReceiver when needed
This commit is contained in:
Ivan Iskandar
2021-05-01 09:36:54 +07:00
committed by GitHub
parent 908c9bc624
commit cb203ef02c
7 changed files with 101 additions and 6 deletions
@@ -167,6 +167,12 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
window.decorView.setOnSystemUiVisibilityChangeListener {
setMenuVisibility(menuVisible, animate = false)
}
// Finish when incognito mode is disabled
preferences.incognitoMode().asFlow()
.drop(1)
.onEach { if (!it) finish() }
.launchIn(lifecycleScope)
}
/**
@@ -144,6 +144,8 @@ class ReaderPresenter(
hasTrackers = tracks.size > 0
}
private val incognitoMode = preferences.incognitoMode().get()
/**
* Called when the presenter is created. It retrieves the saved active chapter if the process
* was restored.
@@ -375,7 +377,7 @@ class ReaderPresenter(
// Save last page read and mark as read if needed
selectedChapter.chapter.last_page_read = page.index
val shouldTrack = !preferences.incognitoMode().get() || hasTrackers
val shouldTrack = !incognitoMode || hasTrackers
if (selectedChapter.pages?.lastIndex == page.index && shouldTrack) {
selectedChapter.chapter.read = true
updateTrackChapterRead(selectedChapter)
@@ -430,7 +432,7 @@ class ReaderPresenter(
* If incognito mode isn't on or has at least 1 tracker
*/
private fun saveChapterProgress(chapter: ReaderChapter) {
if (!preferences.incognitoMode().get() || hasTrackers) {
if (!incognitoMode || hasTrackers) {
db.updateChapterProgress(chapter.chapter).asRxCompletable()
.onErrorComplete()
.subscribeOn(Schedulers.io())
@@ -442,7 +444,7 @@ class ReaderPresenter(
* Saves this [chapter] last read history if incognito mode isn't on.
*/
private fun saveChapterHistory(chapter: ReaderChapter) {
if (!preferences.incognitoMode().get()) {
if (!incognitoMode) {
val history = History.create(chapter.chapter).apply { last_read = Date().time }
db.updateHistoryLastRead(history).asRxCompletable()
.onErrorComplete()