From 443887c89a39a051cfe549f2d8f21c806727c6ff Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 12 Apr 2021 13:48:10 -0400 Subject: [PATCH] Option to invert double pages Closes #725 --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../ui/reader/settings/ReaderPagedView.kt | 65 +++++++++++-------- .../ui/reader/viewer/pager/PagerConfig.kt | 5 ++ .../ui/reader/viewer/pager/PagerPageHolder.kt | 2 +- .../ui/setting/SettingsReaderController.kt | 5 ++ .../main/res/layout/reader_paged_layout.xml | 8 +++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 63 insertions(+), 27 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 98234c3420..4cbca1968a 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 @@ -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" 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 06aeadcb2d..4e78d1a8cd 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 @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt index d00d58c95d..6190b1d3c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderPagedView.kt @@ -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,34 +19,44 @@ 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 + updatePagedGroup(!isWebtoonView) + } + 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()) + + 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 + cropBordersWebtoon.bindToPreference(if (hasMargins) preferences.cropBorders() else preferences.cropBordersWebtoon()) + webtoonSidePadding.bindToIntPreference( + preferences.webtoonSidePadding(), + R.array.webtoon_side_padding_values + ) + webtoonEnableZoomOut.bindToPreference(preferences.webtoonEnableZoomOut()) + webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) + webtoonInvert.bindToPreference(preferences.webtoonNavInverted()) + 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()) - - binding.pageLayout.title = binding.pageLayout.title.toString().addBetaTag(context) - - val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0 - 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( - preferences.webtoonSidePadding(), - R.array.webtoon_side_padding_values - ) - binding.webtoonEnableZoomOut.bindToPreference(preferences.webtoonEnableZoomOut()) - binding.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) - binding.webtoonInvert.bindToPreference(preferences.webtoonNavInverted()) - - updatePagedGroup(!isWebtoonView) } fun updatePrefs() { @@ -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 } } 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 f1fd44c871..c03487ab00 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 @@ -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) 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 017fde4ba5..f857ad3f1a 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 @@ -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, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index a6f91fe1d9..8f4a002df0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -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 diff --git a/app/src/main/res/layout/reader_paged_layout.xml b/app/src/main/res/layout/reader_paged_layout.xml index adcd858b5c..90321be092 100644 --- a/app/src/main/res/layout/reader_paged_layout.xml +++ b/app/src/main/res/layout/reader_paged_layout.xml @@ -64,6 +64,14 @@ app:title="@string/zoom_start_position" android:entries="@array/zoom_start" /> + + 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. Reduces banding, but impacts performance + Invert double pages Crop borders Use custom brightness Use custom color filter