From bdbdf211e23fa9a70f9513c4a699544f46fc03c1 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 29 Mar 2021 22:54:20 +0200 Subject: [PATCH] Remove insert page when dual page split get turned off (#4739) --- .../tachiyomi/ui/reader/viewer/pager/PagerConfig.kt | 10 +++++++++- .../tachiyomi/ui/reader/viewer/pager/PagerViewer.kt | 10 ++++++++++ .../ui/reader/viewer/pager/PagerViewerAdapter.kt | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index dba0e1c4e5..40ca79a52a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -20,6 +20,8 @@ class PagerConfig( preferences: PreferencesHelper = Injekt.get() ) : ViewerConfig(preferences, scope) { + var dualPageSplitChangedListener: ((Boolean) -> Unit)? = null + var imageScaleType = 1 private set @@ -52,7 +54,13 @@ class PagerConfig( ) preferences.dualPageSplitPaged() - .register({ dualPageSplit = it }, { imagePropertyChangedListener?.invoke() }) + .register( + { dualPageSplit = it }, + { + imagePropertyChangedListener?.invoke() + dualPageSplitChangedListener?.invoke(it) + } + ) preferences.dualPageInvertPaged() .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) 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 039d1e63b2..0ca303bf41 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 @@ -116,6 +116,12 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { false } + config.dualPageSplitChangedListener = { enabled -> + if (!enabled) { + cleanupPageSplit() + } + } + config.imagePropertyChangedListener = { refreshAdapter() } @@ -381,4 +387,8 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { fun onPageSplit(currentPage: ReaderPage, newPage: InsertPage) { adapter.onPageSplit(currentPage, newPage, this::class.java) } + + private fun cleanupPageSplit() { + adapter.cleanupPageSplit() + } } 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 d15d744f3a..59a35e5c0c 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 @@ -151,4 +151,10 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { notifyDataSetChanged() } + + fun cleanupPageSplit() { + val insertPages = items.filterIsInstance(InsertPage::class.java) + items.removeAll(insertPages) + notifyDataSetChanged() + } }