@@ -49,6 +49,7 @@ import androidx.core.content.edit
4949import helium314.keyboard.latin.settings.Settings
5050import helium314.keyboard.latin.settings.getProfileAwarePrefKey
5151import helium314.keyboard.latin.utils.ScreenProfile
52+ import helium314.keyboard.latin.utils.ScreenProfileProvider
5253import helium314.keyboard.latin.utils.WallpaperFetcher
5354import kotlinx.coroutines.flow.MutableStateFlow
5455import java.util.Locale
@@ -68,8 +69,10 @@ fun AppearanceScreen(
6869 val popupOnEnabled = prefs.getBoolean(Settings .PREF_POPUP_ON , Defaults .PREF_POPUP_ON )
6970 val showHintsEnabled = prefs.getBoolean(Settings .PREF_SHOW_HINTS , Defaults .PREF_SHOW_HINTS )
7071 val narrowGapsEnabled = prefs.getBoolean(Settings .PREF_NARROW_KEY_GAPS , Defaults .PREF_NARROW_KEY_GAPS )
71- val splitEnabled = prefs.getBoolean(Settings .PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE , Defaults .PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE )
72- || prefs.getBoolean(Settings .PREF_ENABLE_SPLIT_KEYBOARD , Defaults .PREF_ENABLE_SPLIT_KEYBOARD )
72+ val isTablet = ScreenProfileProvider .isTablet(ctx)
73+ val splitProfile = if (isTablet) ScreenProfile .LARGE else ScreenProfile .COMPACT
74+ val splitEnabled = Settings .readSplitKeyboardEnabled(prefs, false , splitProfile)
75+ || Settings .readSplitKeyboardEnabled(prefs, true , splitProfile)
7376
7477 val fineTuneThemeExpanded = fineTuneExpanded(prefs, Settings .PREF_EXPAND_FINE_TUNE_THEME , Defaults .PREF_EXPAND_FINE_TUNE_THEME )
7578 val fineTuneKeyPreviewsExpanded = fineTuneExpanded(prefs, Settings .PREF_EXPAND_FINE_TUNE_KEY_PREVIEWS , Defaults .PREF_EXPAND_FINE_TUNE_KEY_PREVIEWS )
@@ -114,8 +117,8 @@ fun AppearanceScreen(
114117 Settings .PREF_SPACE_BAR_TEXT ,
115118 Settings .PREF_EXPAND_FINE_TUNE_FOLDABLE ,
116119 if (fineTuneFoldableExpanded) Settings .PREF_UNFOLDED_KEYBOARD_HEIGHT_SCALE_PREFIX else null ,
117- if (fineTuneFoldableExpanded) Settings .PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED else null ,
118- if (fineTuneFoldableExpanded) Settings .PREF_UNFOLDED_SPLIT_SPACER_SCALE_PREFIX else null ,
120+ if (fineTuneFoldableExpanded && ! isTablet ) Settings .PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED else null ,
121+ if (fineTuneFoldableExpanded && ! isTablet ) Settings .PREF_UNFOLDED_SPLIT_SPACER_SCALE_PREFIX else null ,
119122 if (fineTuneFoldableExpanded) Settings .PREF_UNFOLDED_BOTTOM_PADDING_SCALE_PREFIX else null ,
120123 if (fineTuneFoldableExpanded) Settings .PREF_UNFOLDED_SIDE_PADDING_SCALE_PREFIX else null ,
121124 Settings .PREF_EXPAND_FINE_TUNE_KEYBOARD_LAYOUT ,
@@ -162,6 +165,47 @@ fun AppearanceScreen(
162165 )
163166}
164167
168+ @Composable
169+ private fun SplitSwitch (
170+ setting : Setting ,
171+ landscape : Boolean ,
172+ profile : ScreenProfile ,
173+ beforeChange : () -> Unit = {},
174+ afterSave : () -> Unit = {},
175+ ) {
176+ val prefs = LocalContext .current.prefs()
177+ val baseKey = if (landscape) Settings .PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE else Settings .PREF_ENABLE_SPLIT_KEYBOARD
178+ SwitchPreference (
179+ name = setting.title,
180+ description = setting.description,
181+ // show and save the value the keyboard actually reads, which the toolbar key may have set
182+ key = getProfileAwarePrefKey(baseKey, profile),
183+ default = Settings .readSplitKeyboardEnabled(prefs, landscape, profile),
184+ allowCheckedChange = {
185+ beforeChange()
186+ true
187+ },
188+ ) {
189+ Settings .saveSplitKeyboardEnabled(prefs, it, landscape, profile)
190+ afterSave()
191+ KeyboardSwitcher .getInstance().reloadKeyboard()
192+ }
193+ }
194+
195+ /* * The regular split switches control the large screen values only on tablets, which can't be folded. */
196+ @Composable
197+ private fun RegularSplitSwitch (setting : Setting , landscape : Boolean ) {
198+ val ctx = LocalContext .current
199+ val isTablet = ScreenProfileProvider .isTablet(ctx)
200+ SplitSwitch (
201+ setting = setting,
202+ landscape = landscape,
203+ profile = if (isTablet) ScreenProfile .LARGE else ScreenProfile .COMPACT ,
204+ // runs before the new value is saved, while the landscape state can still be read
205+ beforeChange = { if (isTablet && ! landscape) Settings .pinLargeLandscapeSplit(ctx.prefs()) },
206+ )
207+ }
208+
165209fun createAppearanceSettings (context : Context ) = listOf (
166210 Setting (context, Settings .PREF_THEME_STYLE , R .string.theme_style) { setting ->
167211 val ctx = LocalContext .current
@@ -371,13 +415,7 @@ fun createAppearanceSettings(context: Context) = listOf(
371415 }
372416 },
373417 Setting (context, Settings .PREF_ENABLE_SPLIT_KEYBOARD , R .string.enable_split_keyboard) {
374- SwitchPreference (it, Defaults .PREF_ENABLE_SPLIT_KEYBOARD ) {
375- val prefs = context.prefs()
376- val enabled = prefs.getBoolean(Settings .PREF_ENABLE_SPLIT_KEYBOARD , Defaults .PREF_ENABLE_SPLIT_KEYBOARD )
377- val profilePref = getProfileAwarePrefKey(Settings .PREF_ENABLE_SPLIT_KEYBOARD , ScreenProfile .COMPACT )
378- prefs.edit().putBoolean(profilePref, enabled).apply ()
379- KeyboardSwitcher .getInstance().reloadKeyboard()
380- }
418+ RegularSplitSwitch (it, landscape = false )
381419 },
382420 Setting (context, Settings .PREF_EXPAND_FINE_TUNE_FOLDABLE ,
383421 R .string.fine_tune_foldable_title, R .string.fine_tune_foldable_summary
@@ -395,15 +433,16 @@ fun createAppearanceSettings(context: Context) = listOf(
395433 ) { KeyboardSwitcher .getInstance().setThemeNeedsReload() }
396434 },
397435 Setting (context, Settings .PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED , R .string.unfolded_split_keyboard) {
398- SwitchPreference (it, Defaults . PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED ) {
399- val prefs = context.prefs()
400- val enabled = prefs.getBoolean( Settings . PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED , Defaults . PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED )
401- val profilePref = getProfileAwarePrefKey( Settings . PREF_ENABLE_SPLIT_KEYBOARD , ScreenProfile .LARGE )
402- prefs.edit().putBoolean(profilePref, enabled). apply ()
403- KeyboardSwitcher .getInstance().reloadKeyboard()
404- }
436+ // returning early also hides it from settings search
437+ if ( ScreenProfileProvider .isTablet( LocalContext .current)) return @Setting
438+ val prefs = LocalContext .current.prefs( )
439+ SplitSwitch (it, landscape = false , profile = ScreenProfile .LARGE , afterSave = {
440+ // a landscape value saved by the toolbar key would otherwise keep overriding this switch
441+ prefs.edit { remove(getProfileAwarePrefKey( Settings . PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE , ScreenProfile . LARGE )) }
442+ })
405443 },
406444 Setting (context, Settings .PREF_UNFOLDED_SPLIT_SPACER_SCALE_PREFIX , R .string.unfolded_split_spacer_scale) { setting ->
445+ if (ScreenProfileProvider .isTablet(LocalContext .current)) return @Setting
407446 MultiSliderPreference (
408447 name = setting.title,
409448 baseKey = setting.key,
@@ -516,17 +555,20 @@ fun createAppearanceSettings(context: Context) = listOf(
516555 ) { KeyboardSwitcher .getInstance().reloadKeyboard() }
517556 },
518557 Setting (context, Settings .PREF_SPLIT_SPACER_SCALE_PREFIX , R .string.split_spacer_scale) { setting ->
558+ val ctx = LocalContext .current
559+ val isTablet = ScreenProfileProvider .isTablet(ctx)
519560 MultiSliderPreference (
520561 name = setting.title,
521- baseKey = setting.key,
562+ // large screens prefer these keys over the regular ones
563+ baseKey = if (isTablet) Settings .PREF_UNFOLDED_SPLIT_SPACER_SCALE_PREFIX else setting.key,
522564 dimensions = listOf (stringResource(R .string.landscape)),
523- defaults = Defaults .PREF_SPLIT_SPACER_SCALE ,
565+ defaults = if (isTablet) Settings .readRegularSplitSpacerScales(ctx.prefs()) else Defaults .PREF_SPLIT_SPACER_SCALE ,
524566 range = 0.5f .. 2f ,
525567 description = { " ${(100 * it).roundToInt()} %" }
526568 ) { KeyboardSwitcher .getInstance().setThemeNeedsReload() }
527569 },
528570 Setting (context, Settings .PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE , R .string.enable_split_keyboard_landscape) {
529- SwitchPreference (it, Defaults . PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE ) { KeyboardSwitcher .getInstance().reloadKeyboard() }
571+ RegularSplitSwitch (it, landscape = true )
530572 },
531573 Setting (context, Settings .PREF_NARROW_KEY_GAPS , R .string.prefs_narrow_key_gaps) {
532574 SwitchPreference (it, Defaults .PREF_NARROW_KEY_GAPS ) { KeyboardSwitcher .getInstance().setThemeNeedsReload() }
0 commit comments