Option to invert double pages

Closes #725
This commit is contained in:
Jays2Kings 2021-04-12 13:48:10 -04:00
parent 652c935062
commit 443887c89a
8 changed files with 63 additions and 27 deletions

View File

@ -71,6 +71,8 @@ object PreferenceKeys {
const val pageLayout = "page_layout"
const val invertDoublePages = "invert_double_pages"
const val showNavigationOverlayNewUser = "reader_navigation_overlay_new_user"
const val showNavigationOverlayNewUserWebtoon = "reader_navigation_overlay_new_user_webtoon"

View File

@ -154,6 +154,8 @@ class PreferencesHelper(val context: Context) {
fun pageLayout() = flowPrefs.getInt(Keys.pageLayout, PageLayout.AUTOMATIC)
fun invertDoublePages() = flowPrefs.getBoolean(Keys.invertDoublePages, false)
fun showNavigationOverlayNewUser() = flowPrefs.getBoolean(Keys.showNavigationOverlayNewUser, true)
fun showNavigationOverlayNewUserWebtoon() = flowPrefs.getBoolean(Keys.showNavigationOverlayNewUserWebtoon, true)

View File

@ -3,10 +3,12 @@ package eu.kanade.tachiyomi.ui.reader.settings
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import androidx.core.view.isVisible
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ReaderPagedLayoutBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
import eu.kanade.tachiyomi.util.bindToPreference
import eu.kanade.tachiyomi.util.lang.addBetaTag
import eu.kanade.tachiyomi.util.view.visibleIf
@ -17,35 +19,45 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
override fun inflateBinding() = ReaderPagedLayoutBinding.bind(this)
override fun initGeneralPreferences() {
binding.scaleType.bindToPreference(preferences.imageScaleType(), 1) {
with(binding) {
scaleType.bindToPreference(preferences.imageScaleType(), 1) {
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
updatePagedGroup(!isWebtoonView)
}
binding.zoomStart.bindToPreference(preferences.zoomStart(), 1)
binding.cropBorders.bindToPreference(preferences.cropBorders())
binding.pageTransitions.bindToPreference(preferences.pageTransitions())
binding.pagerNav.bindToPreference(preferences.navigationModePager())
binding.pagerInvert.bindToPreference(preferences.pagerNavInverted())
binding.extendPastCutout.bindToPreference(preferences.pagerCutoutBehavior())
binding.pageLayout.bindToPreference(preferences.pageLayout())
zoomStart.bindToPreference(preferences.zoomStart(), 1)
cropBorders.bindToPreference(preferences.cropBorders())
pageTransitions.bindToPreference(preferences.pageTransitions())
pagerNav.bindToPreference(preferences.navigationModePager())
pagerInvert.bindToPreference(preferences.pagerNavInverted())
extendPastCutout.bindToPreference(preferences.pagerCutoutBehavior())
pageLayout.bindToPreference(preferences.pageLayout()) {
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
updatePagedGroup(!isWebtoonView)
}
invertDoublePages.bindToPreference(preferences.invertDoublePages())
binding.pageLayout.title = binding.pageLayout.title.toString().addBetaTag(context)
pageLayout.title = pageLayout.title.toString().addBetaTag(context)
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val isWebtoonView =
mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
val hasMargins = mangaViewer == ReaderActivity.VERTICAL_PLUS
binding.cropBordersWebtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon())
binding.webtoonSidePadding.bindToIntPreference(
cropBordersWebtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon())
webtoonSidePadding.bindToIntPreference(
preferences.webtoonSidePadding(),
R.array.webtoon_side_padding_values
)
binding.webtoonEnableZoomOut.bindToPreference(preferences.webtoonEnableZoomOut())
binding.webtoonNav.bindToPreference(preferences.navigationModeWebtoon())
binding.webtoonInvert.bindToPreference(preferences.webtoonNavInverted())
webtoonEnableZoomOut.bindToPreference(preferences.webtoonEnableZoomOut())
webtoonNav.bindToPreference(preferences.navigationModeWebtoon())
webtoonInvert.bindToPreference(preferences.webtoonNavInverted())
updatePagedGroup(!isWebtoonView)
}
}
fun updatePrefs() {
val mangaViewer = activity.presenter.getMangaViewer()
@ -84,6 +96,7 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
} else {
false
}
binding.extendPastCutout.visibleIf(show && isFullFit && hasCutout)
binding.extendPastCutout.isVisible = show && isFullFit && hasCutout
binding.invertDoublePages.isVisible = show && preferences.pageLayout().get() != PageLayout.SINGLE_PAGE
}
}

View File

@ -48,6 +48,8 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
}
}
var invertDoublePages = false
var autoDoublePages = preferences.pageLayout().get() == PageLayout.AUTOMATIC
init {
@ -87,6 +89,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
preferences.readerTheme()
.register({ readerTheme = it }, { imagePropertyChangedListener?.invoke() })
preferences.invertDoublePages()
.register({ invertDoublePages = it }, { imagePropertyChangedListener?.invoke() })
preferences.pageLayout()
.asFlow()
.drop(1)

View File

@ -689,7 +689,7 @@ class PagerPageHolder(
val result = Bitmap.createBitmap(width + width2, max(height, height2), Bitmap.Config.ARGB_8888)
val canvas = Canvas(result)
canvas.drawColor(if (viewer.config.readerTheme >= 2 || viewer.config.readerTheme == 0) Color.WHITE else Color.BLACK)
val isLTR = viewer !is R2LPagerViewer
val isLTR = (viewer !is R2LPagerViewer).xor(viewer.config.invertDoublePages)
val upperPart = Rect(
if (isLTR) 0 else width2,
(maxHeight - imageBitmap.height) / 2,

View File

@ -244,6 +244,11 @@ class SettingsReaderController : SettingsController() {
infoPreference(R.string.automatic_can_still_switch).apply {
preferences.pageLayout().asImmediateFlow { isVisible = it == PageLayout.AUTOMATIC }.launchIn(viewScope)
}
switchPreference {
key = Keys.invertDoublePages
titleRes = R.string.invert_double_pages
defaultValue = false
}
}
preferenceCategory {
titleRes = R.string.webtoon

View File

@ -64,6 +64,14 @@
app:title="@string/zoom_start_position"
android:entries="@array/zoom_start" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/invert_double_pages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/invert_double_pages"
android:textColor="?android:attr/textColorPrimary" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/crop_borders"
android:layout_width="match_parent"

View File

@ -322,6 +322,7 @@
<string name="amount_of_pages_to_preload">The amount of pages to preload when reading. Higher values will result in a smoother reading experience, at the cost of higher cache and network usage.</string>
<string name="reduces_banding_impacts_performance">Reduces banding, but impacts
performance</string>
<string name="invert_double_pages">Invert double pages</string>
<string name="crop_borders">Crop borders</string>
<string name="use_custom_brightness">Use custom brightness</string>
<string name="use_custom_color_filter">Use custom color filter</string>