Remove insert page when dual page split get turned off (#4739)

This commit is contained in:
Andreas 2021-03-29 22:54:20 +02:00 committed by GitHub
parent 0437703cbf
commit bdbdf211e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -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() })

View file

@ -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()
}
}

View file

@ -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()
}
}