Support reverse physical key controls in reader

This commit is contained in:
FooIbar committed 2024-12-01 17:46:13 +08:00
1 parent 02d607817a
commit e0b1b18299
6 files changed
+12 -2

No files matched your search

@@ -195,6 +195,7 @@ object Settings : DataStorePreferences(null) {
val keepScreenOn = boolPref("pref_keep_screen_on_key", true)
val readerLongTapAction = boolPref("reader_long_tap", true)
val pageTransitions = boolPref("pref_enable_transitions_key", true)
val readerReverseControls = boolPref("reader_volume_keys_inverted", false)
val grayScale = boolPref("pref_grayscale", false)
val invertedColors = boolPref("pref_inverted_colors", false)
val readerWebtoonNav = intPref("reader_navigation_mode_webtoon", 0)
@@ -9,13 +9,14 @@ import androidx.compose.ui.input.key.type
fun Modifier.keyEventHandler(
enabled: () -> Boolean,
reverse: () -> Boolean,
movePrevious: () -> Unit,
moveNext: () -> Unit,
) = onPreviewKeyEvent {
if (enabled() && it.type == KeyEventType.KeyDown) {
when (it.key) {
Key.DirectionUp, Key.PageUp, Key.VolumeUp -> movePrevious()
Key.DirectionDown, Key.PageDown, Key.VolumeDown -> moveNext()
Key.DirectionUp, Key.PageUp, Key.VolumeUp -> if (reverse()) moveNext() else movePrevious()
Key.DirectionDown, Key.PageDown, Key.VolumeDown -> if (reverse()) movePrevious() else moveNext()
else -> return@onPreviewKeyEvent false
}
true
@@ -63,4 +63,8 @@ fun ReaderGeneralSetting() = Column(modifier = Modifier.verticalScroll(rememberS
title = stringResource(id = R.string.pref_page_transitions),
field = Settings.pageTransitions.asMutableState(),
)
SwitchChoice(
title = stringResource(id = R.string.settings_read_reverse_controls),
field = Settings.readerReverseControls.asMutableState(),
)
}
@@ -188,6 +188,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle
}
val showSeekbar by Settings.showReaderSeekbar.collectAsState()
val readingMode by Settings.readingMode.collectAsState { ReadingModeType.fromPreference(it) }
val reverseControls by Settings.readerReverseControls.collectAsState()
val fullscreen by Settings.fullscreen.collectAsState()
val cutoutShort by Settings.cutoutShort.collectAsState()
val uiController = rememberSystemUiController()
@@ -207,6 +208,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle
Box(
Modifier.keyEventHandler(
enabled = { !appbarVisible },
reverse = { reverseControls },
movePrevious = {
launch {
if (isWebtoon) lazyListState.scrollUp() else pagerState.moveToPrevious()
@@ -312,6 +312,7 @@
<string name="settings_eh_tag_translations_source_url">https://github.com/EhTagTranslation/Editor/wiki</string>
<string name="settings_eh_filter">屏蔽列表</string>
<string name="settings_eh_filter_summary">根据标题、上传者、标签、评论者屏蔽画廊或评论</string>
<string name="settings_read_reverse_controls">反转物理按键控制</string>
<string name="settings_block_extraneous_ads">[实验性] 屏蔽外部广告</string>
<string name="settings_ads_placeholder">[可选] 选择替换外部广告的图片</string>
<string name="settings_download">下载</string>
+1
View File
@@ -328,6 +328,7 @@
<string name="settings_eh_tag_translations_source_url">https://placeholder</string>
<string name="settings_eh_filter">Blockers</string>
<string name="settings_eh_filter_summary">Block gallery or comment by title, uploader, tags and commenter</string>
<string name="settings_read_reverse_controls">Reverse physical key controls</string>
<string name="settings_block_extraneous_ads">[Experimental] Block extraneous ads</string>
<string name="settings_ads_placeholder">[Optional] Pick placeholder to replace ads</string>
<string name="settings_download">Download</string>