Add "Rotate wide pages to fit" for webtoon reader too

Closes #1977
This commit is contained in:
arkon 2023-11-19 15:03:54 -05:00
parent 29368fc953
commit 4a7c20f5a0
6 changed files with 66 additions and 4 deletions

View File

@ -245,10 +245,12 @@ object SettingsReaderScreen : SearchableSettings {
val navModePref = readerPreferences.navigationModeWebtoon() val navModePref = readerPreferences.navigationModeWebtoon()
val dualPageSplitPref = readerPreferences.dualPageSplitWebtoon() val dualPageSplitPref = readerPreferences.dualPageSplitWebtoon()
val rotateToFitPref = readerPreferences.dualPageRotateToFitWebtoon()
val webtoonSidePaddingPref = readerPreferences.webtoonSidePadding() val webtoonSidePaddingPref = readerPreferences.webtoonSidePadding()
val navMode by navModePref.collectAsState() val navMode by navModePref.collectAsState()
val dualPageSplit by dualPageSplitPref.collectAsState() val dualPageSplit by dualPageSplitPref.collectAsState()
val rotateToFit by rotateToFitPref.collectAsState()
val webtoonSidePadding by webtoonSidePaddingPref.collectAsState() val webtoonSidePadding by webtoonSidePaddingPref.collectAsState()
return Preference.PreferenceGroup( return Preference.PreferenceGroup(
@ -300,6 +302,10 @@ object SettingsReaderScreen : SearchableSettings {
Preference.PreferenceItem.SwitchPreference( Preference.PreferenceItem.SwitchPreference(
pref = dualPageSplitPref, pref = dualPageSplitPref,
title = stringResource(MR.strings.pref_dual_page_split), title = stringResource(MR.strings.pref_dual_page_split),
onValueChanged = {
rotateToFitPref.set(false)
true
},
), ),
Preference.PreferenceItem.SwitchPreference( Preference.PreferenceItem.SwitchPreference(
pref = readerPreferences.dualPageInvertWebtoon(), pref = readerPreferences.dualPageInvertWebtoon(),
@ -307,6 +313,19 @@ object SettingsReaderScreen : SearchableSettings {
subtitle = stringResource(MR.strings.pref_dual_page_invert_summary), subtitle = stringResource(MR.strings.pref_dual_page_invert_summary),
enabled = dualPageSplit, 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( Preference.PreferenceItem.SwitchPreference(
pref = readerPreferences.webtoonDoubleTapZoomEnabled(), pref = readerPreferences.webtoonDoubleTapZoomEnabled(),
title = stringResource(MR.strings.pref_double_tap_zoom), title = stringResource(MR.strings.pref_double_tap_zoom),

View File

@ -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( CheckboxItem(
label = stringResource(MR.strings.pref_double_tap_zoom), label = stringResource(MR.strings.pref_double_tap_zoom),
pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(), pref = screenModel.preferences.webtoonDoubleTapZoomEnabled(),

View File

@ -86,6 +86,10 @@ class ReaderPreferences(
fun dualPageRotateToFitInvert() = preferenceStore.getBoolean("pref_dual_page_rotate_invert", false) 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 // endregion
// region Color filter // region Color filter

View File

@ -62,6 +62,18 @@ class WebtoonConfig(
readerPreferences.dualPageInvertWebtoon() readerPreferences.dualPageInvertWebtoon()
.register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() }) .register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() })
readerPreferences.dualPageRotateToFitWebtoon()
.register(
{ dualPageRotateToFit = it },
{ imagePropertyChangedListener?.invoke() },
)
readerPreferences.dualPageRotateToFitInvertWebtoon()
.register(
{ dualPageRotateToFitInvert = it },
{ imagePropertyChangedListener?.invoke() },
)
readerPreferences.webtoonDoubleTapZoomEnabled() readerPreferences.webtoonDoubleTapZoomEnabled()
.register( .register(
{ doubleTapZoom = it }, { doubleTapZoom = it },

View File

@ -210,6 +210,10 @@ class WebtoonPageHolder(
} }
private fun process(imageStream: BufferedInputStream): InputStream { private fun process(imageStream: BufferedInputStream): InputStream {
if (viewer.config.dualPageRotateToFit) {
return rotateDualPage(imageStream)
}
if (viewer.config.dualPageSplit) { if (viewer.config.dualPageSplit) {
val isDoublePage = ImageUtil.isWideImage(imageStream) val isDoublePage = ImageUtil.isWideImage(imageStream)
if (isDoublePage) { if (isDoublePage) {
@ -221,6 +225,16 @@ class WebtoonPageHolder(
return imageStream 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. * Called when the page has an error.
*/ */

View File

@ -7,7 +7,7 @@ import tachiyomi.core.util.system.logcat
object DeviceUtil { object DeviceUtil {
val isMiui by lazy { val isMiui: Boolean by lazy {
getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false 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. * @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 if (!isMiui) return@lazy null
Build.VERSION.INCREMENTAL Build.VERSION.INCREMENTAL
@ -41,11 +41,11 @@ object DeviceUtil {
} }
} }
val isSamsung by lazy { val isSamsung: Boolean by lazy {
Build.MANUFACTURER.equals("samsung", ignoreCase = true) Build.MANUFACTURER.equals("samsung", ignoreCase = true)
} }
val oneUiVersion by lazy { val oneUiVersion: Double? by lazy {
try { try {
val semPlatformIntField = Build.VERSION::class.java.getDeclaredField("SEM_PLATFORM_INT") val semPlatformIntField = Build.VERSION::class.java.getDeclaredField("SEM_PLATFORM_INT")
val version = semPlatformIntField.getInt(null) - 90000 val version = semPlatformIntField.getInt(null) - 90000