From 4a7c20f5a088be75e2a7644d6268f9e21a98d147 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Nov 2023 15:03:54 -0500 Subject: [PATCH] Add "Rotate wide pages to fit" for webtoon reader too Closes #1977 --- .../settings/screen/SettingsReaderScreen.kt | 19 +++++++++++++++++++ .../reader/settings/ReadingModePage.kt | 13 +++++++++++++ .../ui/reader/setting/ReaderPreferences.kt | 4 ++++ .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 12 ++++++++++++ .../viewer/webtoon/WebtoonPageHolder.kt | 14 ++++++++++++++ .../tachiyomi/util/system/DeviceUtil.kt | 8 ++++---- 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index 0e254d8a66..aac9259a1b 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -245,10 +245,12 @@ object SettingsReaderScreen : SearchableSettings { val navModePref = readerPreferences.navigationModeWebtoon() val dualPageSplitPref = readerPreferences.dualPageSplitWebtoon() + val rotateToFitPref = readerPreferences.dualPageRotateToFitWebtoon() val webtoonSidePaddingPref = readerPreferences.webtoonSidePadding() val navMode by navModePref.collectAsState() val dualPageSplit by dualPageSplitPref.collectAsState() + val rotateToFit by rotateToFitPref.collectAsState() val webtoonSidePadding by webtoonSidePaddingPref.collectAsState() return Preference.PreferenceGroup( @@ -300,6 +302,10 @@ object SettingsReaderScreen : SearchableSettings { Preference.PreferenceItem.SwitchPreference( pref = dualPageSplitPref, title = stringResource(MR.strings.pref_dual_page_split), + onValueChanged = { + rotateToFitPref.set(false) + true + }, ), Preference.PreferenceItem.SwitchPreference( pref = readerPreferences.dualPageInvertWebtoon(), @@ -307,6 +313,19 @@ object SettingsReaderScreen : SearchableSettings { subtitle = stringResource(MR.strings.pref_dual_page_invert_summary), enabled = dualPageSplit, ), + Preference.PreferenceItem.SwitchPreference( + pref = rotateToFitPref, + title = stringResource(MR.strings.pref_page_rotate), + onValueChanged = { + dualPageSplitPref.set(false) + true + }, + ), + Preference.PreferenceItem.SwitchPreference( + pref = readerPreferences.dualPageRotateToFitInvertWebtoon(), + title = stringResource(MR.strings.pref_page_rotate_invert), + enabled = rotateToFit, + ), Preference.PreferenceItem.SwitchPreference( pref = readerPreferences.webtoonDoubleTapZoomEnabled(), title = stringResource(MR.strings.pref_double_tap_zoom), diff --git a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt index 89fcac78ab..ee2eb854f7 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/settings/ReadingModePage.kt @@ -180,6 +180,19 @@ private fun ColumnScope.WebtoonViewerSettings(screenModel: ReaderSettingsScreenM ) } + val dualPageRotateToFitWebtoon by screenModel.preferences.dualPageRotateToFitWebtoon().collectAsState() + CheckboxItem( + label = stringResource(MR.strings.pref_page_rotate), + pref = screenModel.preferences.dualPageRotateToFitWebtoon(), + ) + + if (dualPageRotateToFitWebtoon) { + CheckboxItem( + label = stringResource(MR.strings.pref_page_rotate_invert), + pref = screenModel.preferences.dualPageRotateToFitInvertWebtoon(), + ) + } + CheckboxItem( label = stringResource(MR.strings.pref_double_tap_zoom), pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt index ec47364e14..f4992dbc02 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt @@ -86,6 +86,10 @@ class ReaderPreferences( fun dualPageRotateToFitInvert() = preferenceStore.getBoolean("pref_dual_page_rotate_invert", false) + fun dualPageRotateToFitWebtoon() = preferenceStore.getBoolean("pref_dual_page_rotate_webtoon", false) + + fun dualPageRotateToFitInvertWebtoon() = preferenceStore.getBoolean("pref_dual_page_rotate_invert_webtoon", false) + // endregion // region Color filter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index a64826ab1d..28ad91a51d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -62,6 +62,18 @@ class WebtoonConfig( readerPreferences.dualPageInvertWebtoon() .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) + readerPreferences.dualPageRotateToFitWebtoon() + .register( + { dualPageRotateToFit = it }, + { imagePropertyChangedListener?.invoke() }, + ) + + readerPreferences.dualPageRotateToFitInvertWebtoon() + .register( + { dualPageRotateToFitInvert = it }, + { imagePropertyChangedListener?.invoke() }, + ) + readerPreferences.webtoonDoubleTapZoomEnabled() .register( { doubleTapZoom = it }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index aeb25d9057..6503457c47 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -210,6 +210,10 @@ class WebtoonPageHolder( } private fun process(imageStream: BufferedInputStream): InputStream { + if (viewer.config.dualPageRotateToFit) { + return rotateDualPage(imageStream) + } + if (viewer.config.dualPageSplit) { val isDoublePage = ImageUtil.isWideImage(imageStream) if (isDoublePage) { @@ -221,6 +225,16 @@ class WebtoonPageHolder( return imageStream } + private fun rotateDualPage(imageStream: BufferedInputStream): InputStream { + val isDoublePage = ImageUtil.isWideImage(imageStream) + return if (isDoublePage) { + val rotation = if (viewer.config.dualPageRotateToFitInvert) -90f else 90f + ImageUtil.rotateImage(imageStream, rotation) + } else { + imageStream + } + } + /** * Called when the page has an error. */ diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt b/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 57950eda34..9e01771295 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -7,7 +7,7 @@ import tachiyomi.core.util.system.logcat object DeviceUtil { - val isMiui by lazy { + val isMiui: Boolean by lazy { getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false } @@ -16,7 +16,7 @@ object DeviceUtil { * * @return MIUI major version code (e.g., 13) or null if can't be parsed. */ - val miuiMajorVersion by lazy { + val miuiMajorVersion: Int? by lazy { if (!isMiui) return@lazy null Build.VERSION.INCREMENTAL @@ -41,11 +41,11 @@ object DeviceUtil { } } - val isSamsung by lazy { + val isSamsung: Boolean by lazy { Build.MANUFACTURER.equals("samsung", ignoreCase = true) } - val oneUiVersion by lazy { + val oneUiVersion: Double? by lazy { try { val semPlatformIntField = Build.VERSION::class.java.getDeclaredField("SEM_PLATFORM_INT") val version = semPlatformIntField.getInt(null) - 90000