From fe373a95a2a6eaf9792a28b4f2b4f394ae40fba4 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 30 Apr 2021 15:14:20 +0200 Subject: [PATCH 1/3] Fix bugs in dual-page split (#4983) If more bugs appear probably better to go back to the main thread and process dual-pages every time a page is shown as it did before --- .../tachiyomi/ui/reader/ReaderPresenter.kt | 6 +++ .../ui/reader/viewer/pager/PagerPageHolder.kt | 8 +-- .../ui/reader/viewer/pager/PagerViewer.kt | 7 ++- .../reader/viewer/pager/PagerViewerAdapter.kt | 49 +++++++++++++++---- 4 files changed, 56 insertions(+), 14 deletions(-) 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 c318c9596..a61c46afe 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 @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.reader.loader.ChapterLoader +import eu.kanade.tachiyomi.ui.reader.model.InsertPage import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters @@ -367,6 +368,11 @@ class ReaderPresenter( val selectedChapter = page.chapter + // Insert page doesn't change page progress + if (page is InsertPage) { + return + } + // Save last page read and mark as read if needed selectedChapter.chapter.last_page_read = page.index val shouldTrack = !preferences.incognitoMode().get() || hasTrackers diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index f5abc2728..791a8a025 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -230,7 +230,7 @@ class PagerPageHolder( readImageHeaderSubscription = Observable .fromCallable { val stream = streamFn().buffered(16) - openStream = process(stream) + openStream = process(item, stream) ImageUtil.findImageType(stream) == ImageUtil.ImageType.GIF } @@ -249,7 +249,7 @@ class PagerPageHolder( .subscribe({}, {}) } - private fun process(imageStream: InputStream): InputStream { + private fun process(page: ReaderPage, imageStream: InputStream): InputStream { if (!viewer.config.dualPageSplit) { return imageStream } @@ -263,7 +263,7 @@ class PagerPageHolder( return imageStream } - onPageSplit() + onPageSplit(page) return splitInHalf(imageStream) } @@ -287,7 +287,7 @@ class PagerPageHolder( return ImageUtil.splitInHalf(imageStream, side) } - private fun onPageSplit() { + private fun onPageSplit(page: ReaderPage) { val newPage = InsertPage(page) viewer.onPageSplit(page, newPage) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index b5808f4bf..478d7bb42 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -192,6 +192,11 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { Timber.d("onReaderPageSelected: ${page.number}/${pages.size}") activity.onPageSelected(page) + // Skip preload on inserts it causes unwanted page jumping + if (page is InsertPage) { + return + } + // Preload next chapter once we're within the last 5 pages of the current chapter val inPreloadRange = pages.size - page.number < 5 if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) { @@ -387,7 +392,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { fun onPageSplit(currentPage: ReaderPage, newPage: InsertPage) { activity.runOnUiThread { // Need to insert on UI thread else images will go blank - adapter.onPageSplit(currentPage, newPage, this::class.java) + adapter.onPageSplit(currentPage, newPage) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 59a35e5c0..888d83648 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -22,6 +22,11 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { var items: MutableList = mutableListOf() private set + /** + * Holds preprocessed items so they don't get removed when changing chapter + */ + private var preprocessed: MutableMap = mutableMapOf() + var nextTransition: ChapterTransition.Next? = null private set @@ -54,10 +59,25 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) } + var insertPageLastPage: InsertPage? = null + // Add current chapter. val currPages = chapters.currChapter.pages if (currPages != null) { - newItems.addAll(currPages) + val pages = currPages.toMutableList() + + val lastPage = pages.last() + + // Insert preprocessed pages into current page list + preprocessed.keys.sortedDescending() + .forEach { key -> + if (lastPage.index == key) { + insertPageLastPage = preprocessed[key] + } + preprocessed[key]?.let { pages.add(key + 1, it) } + } + + newItems.addAll(pages) } currentChapter = chapters.currChapter @@ -88,8 +108,14 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { newItems.reverse() } + preprocessed = mutableMapOf() items = newItems notifyDataSetChanged() + + // Will skip insert page otherwise + if (insertPageLastPage != null) { + viewer.moveToPage(insertPageLastPage!!) + } } /** @@ -125,20 +151,25 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { return POSITION_NONE } - fun onPageSplit(current: Any?, newPage: InsertPage, clazz: Class) { - if (current !is ReaderPage) return + fun onPageSplit(currentPage: Any?, newPage: InsertPage) { + if (currentPage !is ReaderPage) return - val currentIndex = items.indexOf(current) + val currentIndex = items.indexOf(currentPage) - val placeAtIndex = when { - clazz.isAssignableFrom(L2RPagerViewer::class.java) -> currentIndex + 1 - clazz.isAssignableFrom(VerticalPagerViewer::class.java) -> currentIndex + 1 - clazz.isAssignableFrom(R2LPagerViewer::class.java) -> currentIndex + // Put aside preprocessed pages for next chapter so they don't get removed when changing chapter + if (currentPage.chapter.chapter.id != currentChapter?.chapter?.id) { + preprocessed[newPage.index] = newPage + return + } + + val placeAtIndex = when (viewer) { + is L2RPagerViewer, + is VerticalPagerViewer -> currentIndex + 1 else -> currentIndex } // It will enter a endless cycle of insert pages - if (clazz.isAssignableFrom(R2LPagerViewer::class.java) && items[placeAtIndex - 1] is InsertPage) { + if (viewer is R2LPagerViewer && placeAtIndex - 1 >= 0 && items[placeAtIndex - 1] is InsertPage) { return } From 908c9bc6247462c4a18d605bbabc3ebb6520774d Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 30 Apr 2021 22:35:49 -0400 Subject: [PATCH 2/3] Reader grayscale filter (closes #2822) --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/reader/ReaderActivity.kt | 23 +++ .../setting/ReaderColorFilterSettings.kt | 20 +- .../layout/reader_color_filter_settings.xml | 190 +++++++++--------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 131 insertions(+), 107 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index abf35341a..c30c4da48 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -49,6 +49,8 @@ object PreferenceKeys { const val colorFilterMode = "color_filter_mode" + const val grayscale = "pref_grayscale" + const val defaultReadingMode = "pref_default_reading_mode_key" const val defaultOrientationType = "pref_default_orientation_type_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 91ccd83f0..5340ae67c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -121,6 +121,8 @@ class PreferencesHelper(val context: Context) { fun colorFilterMode() = flowPrefs.getInt(Keys.colorFilterMode, 0) + fun grayscale() = flowPrefs.getBoolean(Keys.grayscale, false) + fun defaultReadingMode() = prefs.getInt(Keys.defaultReadingMode, ReadingModeType.RIGHT_TO_LEFT.flagValue) fun defaultOrientationType() = prefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 8f7461bbc..1adb6bd9e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -8,12 +8,16 @@ import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.graphics.Color +import android.graphics.ColorMatrix +import android.graphics.ColorMatrixColorFilter +import android.graphics.Paint import android.os.Build import android.os.Bundle import android.view.KeyEvent import android.view.Menu import android.view.MenuItem import android.view.MotionEvent +import android.view.View.LAYER_TYPE_HARDWARE import android.view.WindowManager import android.view.animation.Animation import android.view.animation.AnimationUtils @@ -789,6 +793,16 @@ class ReaderActivity : BaseRxActivity() */ private inner class ReaderConfig { + private val grayscalePaint by lazy { + Paint().apply { + colorFilter = ColorMatrixColorFilter( + ColorMatrix().apply { + setSaturation(0f) + } + ) + } + } + /** * Initializes the reader subscriptions. */ @@ -827,6 +841,10 @@ class ReaderActivity : BaseRxActivity() preferences.colorFilterMode().asFlow() .onEach { setColorFilter(preferences.colorFilter().get()) } .launchIn(lifecycleScope) + + preferences.grayscale().asFlow() + .onEach { setGrayscale(it) } + .launchIn(lifecycleScope) } /** @@ -934,5 +952,10 @@ class ReaderActivity : BaseRxActivity() binding.colorOverlay.isVisible = true binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get()) } + + private fun setGrayscale(enabled: Boolean) { + val paint = if (enabled) grayscalePaint else null + binding.viewerContainer.setLayerType(LAYER_TYPE_HARDWARE, paint) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt index 1a71fed83..2985cdd3b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderColorFilterSettings.kt @@ -14,7 +14,7 @@ import androidx.lifecycle.lifecycleScope import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ReaderColorFilterSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener +import eu.kanade.tachiyomi.util.preference.bindToPreference import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -63,20 +63,10 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr binding.seekbarColorFilterBlue.progress = argb[3] // Set listeners - binding.switchColorFilter.isChecked = preferences.colorFilter().get() - binding.switchColorFilter.setOnCheckedChangeListener { _, isChecked -> - preferences.colorFilter().set(isChecked) - } - - binding.customBrightness.isChecked = preferences.customBrightness().get() - binding.customBrightness.setOnCheckedChangeListener { _, isChecked -> - preferences.customBrightness().set(isChecked) - } - - binding.colorFilterMode.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> - preferences.colorFilterMode().set(position) - } - binding.colorFilterMode.setSelection(preferences.colorFilterMode().get(), false) + binding.switchColorFilter.bindToPreference(preferences.colorFilter()) + binding.customBrightness.bindToPreference(preferences.customBrightness()) + binding.colorFilterMode.bindToPreference(preferences.colorFilterMode()) + binding.grayscale.bindToPreference(preferences.grayscale()) binding.seekbarColorFilterAlpha.setOnSeekBarChangeListener( object : SimpleSeekBarListener() { diff --git a/app/src/main/res/layout/reader_color_filter_settings.xml b/app/src/main/res/layout/reader_color_filter_settings.xml index 80899cf9b..9701574f7 100644 --- a/app/src/main/res/layout/reader_color_filter_settings.xml +++ b/app/src/main/res/layout/reader_color_filter_settings.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="16dp"> + android:layout_height="wrap_content"> + + - - + app:layout_constraintTop_toTopOf="@id/seekbar_color_filter_red" + tools:text="255" /> + + - - + app:layout_constraintTop_toTopOf="@id/seekbar_color_filter_green" + tools:text="255" /> + + - - + app:layout_constraintTop_toTopOf="@id/seekbar_color_filter_blue" + tools:text="255" /> + + - - + app:layout_constraintTop_toTopOf="@id/seekbar_color_filter_alpha" + tools:text="255" /> - - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/seekbar_color_filter_alpha" + app:title="@string/pref_color_filter_mode" /> + + + + @@ -185,11 +200,25 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" + android:paddingEnd="16dp" + android:paddingStart="16dp" android:text="@string/pref_custom_brightness" - app:layout_constraintTop_toBottomOf="@id/color_filter_mode_text" /> + app:layout_constraintTop_toBottomOf="@id/grayscale" /> + + - - + app:layout_constraintTop_toTopOf="@id/brightness_seekbar" + tools:text="50" /> - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c2d861a80..bbce163f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -271,6 +271,7 @@ Reduces banding, but impacts performance Crop borders Custom brightness + Grayscale Custom color filter Color filter blend mode Default From cb203ef02cc3c078d5e5717b98ef1db1cf570586 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 1 May 2021 09:36:54 +0700 Subject: [PATCH 3/3] 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 --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 65 +++++++++++++++++++ .../data/notification/Notifications.kt | 11 ++++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 13 +++- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 6 ++ .../tachiyomi/ui/reader/ReaderPresenter.kt | 8 ++- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 101 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index c8fefff86..7292b81b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -2,14 +2,20 @@ package eu.kanade.tachiyomi import android.app.ActivityManager import android.app.Application +import android.app.PendingIntent +import android.content.BroadcastReceiver import android.content.Context +import android.content.Intent +import android.content.IntentFilter import android.content.res.Configuration import android.os.Build +import androidx.core.app.NotificationManagerCompat import androidx.core.content.getSystemService import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.OnLifecycleEvent import androidx.lifecycle.ProcessLifecycleOwner +import androidx.lifecycle.lifecycleScope import androidx.multidex.MultiDex import coil.ImageLoader import coil.ImageLoaderFactory @@ -22,6 +28,9 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.system.notification +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import org.acra.ACRA import org.acra.annotation.AcraCore import org.acra.annotation.AcraHttpSender @@ -45,6 +54,8 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory { private val preferences: PreferencesHelper by injectLazy() + private val disableIncognitoReceiver = DisableIncognitoReceiver() + override fun onCreate() { super.onCreate() if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) @@ -65,6 +76,34 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory { // Reset Incognito Mode on relaunch preferences.incognitoMode().set(false) + + // Show notification to disable Incognito Mode when it's enabled + preferences.incognitoMode().asFlow() + .onEach { enabled -> + val notificationManager = NotificationManagerCompat.from(this) + if (enabled) { + disableIncognitoReceiver.register() + val notification = notification(Notifications.CHANNEL_INCOGNITO_MODE) { + setContentTitle(getString(R.string.pref_incognito_mode)) + setContentText(getString(R.string.notification_incognito_text)) + setSmallIcon(R.drawable.ic_glasses_black_24dp) + setOngoing(true) + + val pendingIntent = PendingIntent.getBroadcast( + this@App, + 0, + Intent(ACTION_DISABLE_INCOGNITO_MODE), + PendingIntent.FLAG_ONE_SHOT + ) + setContentIntent(pendingIntent) + } + notificationManager.notify(Notifications.ID_INCOGNITO_MODE, notification) + } else { + disableIncognitoReceiver.unregister() + notificationManager.cancel(Notifications.ID_INCOGNITO_MODE) + } + } + .launchIn(ProcessLifecycleOwner.get().lifecycleScope) } override fun attachBaseContext(base: Context) { @@ -111,4 +150,30 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory { protected open fun setupNotificationChannels() { Notifications.createChannels(this) } + + private inner class DisableIncognitoReceiver : BroadcastReceiver() { + private var registered = false + + override fun onReceive(context: Context, intent: Intent) { + preferences.incognitoMode().set(false) + } + + fun register() { + if (!registered) { + registerReceiver(this, IntentFilter(ACTION_DISABLE_INCOGNITO_MODE)) + registered = true + } + } + + fun unregister() { + if (registered) { + unregisterReceiver(this) + registered = false + } + } + } + + companion object { + private const val ACTION_DISABLE_INCOGNITO_MODE = "tachi.action.DISABLE_INCOGNITO_MODE" + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt index 97a4b2ef3..4a37b1243 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt @@ -68,6 +68,12 @@ object Notifications { const val CHANNEL_CRASH_LOGS = "crash_logs_channel" const val ID_CRASH_LOGS = -601 + /** + * Notification channel used for Incognito Mode + */ + const val CHANNEL_INCOGNITO_MODE = "incognito_mode_channel" + const val ID_INCOGNITO_MODE = -701 + private val deprecatedChannels = listOf( "downloader_channel", "backup_restore_complete_channel" @@ -154,6 +160,11 @@ object Notifications { CHANNEL_CRASH_LOGS, context.getString(R.string.channel_crash_logs), NotificationManager.IMPORTANCE_HIGH + ), + NotificationChannel( + CHANNEL_INCOGNITO_MODE, + context.getString(R.string.pref_incognito_mode), + NotificationManager.IMPORTANCE_LOW ) ).forEach(context.notificationManager::createNotificationChannel) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 1d8d93d55..4f8359d08 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -41,6 +41,7 @@ import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController +import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.library.LibraryController @@ -224,7 +225,17 @@ class MainActivity : BaseViewBindingActivity() { .launchIn(lifecycleScope) preferences.incognitoMode() - .asImmediateFlow { binding.incognitoMode.isVisible = it } + .asImmediateFlow { + binding.incognitoMode.isVisible = it + + // Close BrowseSourceController and its MangaController child when incognito mode is disabled + if (!it) { + val fg = router.backstack.last().controller() + if (fg is BrowseSourceController || fg is MangaController && fg.fromSource) { + router.popToRoot() + } + } + } .launchIn(lifecycleScope) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index c12d8aaa5..153672316 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -127,7 +127,7 @@ class MangaController : var source: Source? = null private set - private val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false) + val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false) private val preferences: PreferencesHelper by injectLazy() private val coverCache: CoverCache by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 1adb6bd9e..6b4d0cfd5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -167,6 +167,12 @@ class ReaderActivity : BaseRxActivity() window.decorView.setOnSystemUiVisibilityChangeListener { setMenuVisibility(menuVisible, animate = false) } + + // Finish when incognito mode is disabled + preferences.incognitoMode().asFlow() + .drop(1) + .onEach { if (!it) finish() } + .launchIn(lifecycleScope) } /** 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 a61c46afe..f6cee19c6 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 @@ -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() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bbce163f9..e480943b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -467,6 +467,7 @@ Downloaded only Incognito mode Pauses reading history + Disable incognito mode Filters all manga in your library 1 remaining @@ -776,5 +777,4 @@ Previous page Next page -