diff --git a/app/src/main/java/com/geode/launcher/main/UpdateComponents.kt b/app/src/main/java/com/geode/launcher/main/UpdateComponents.kt index 0c39d1c..f19c759 100644 --- a/app/src/main/java/com/geode/launcher/main/UpdateComponents.kt +++ b/app/src/main/java/com/geode/launcher/main/UpdateComponents.kt @@ -183,14 +183,14 @@ fun LauncherUpdateInformation(onDismiss: () -> Unit) { } - HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp)) + if (nextRelease.release.body != null) { + HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp)) - Text( - stringResource(R.string.launcher_update_changelog), - style = Typography.titleLarge - ) + Text( + stringResource(R.string.launcher_update_changelog), + style = Typography.titleLarge + ) - if (nextRelease.release.body != null) { CompositionLocalProvider(LocalBulletListHandler provides { _, _, _ -> "•  " }) { Markdown( content = nextRelease.release.body.replace("\r", ""), diff --git a/app/src/main/java/com/geode/launcher/preferences/DeveloperSettingsActivity.kt b/app/src/main/java/com/geode/launcher/preferences/DeveloperSettingsActivity.kt index cda0cdf..e3d5eaa 100644 --- a/app/src/main/java/com/geode/launcher/preferences/DeveloperSettingsActivity.kt +++ b/app/src/main/java/com/geode/launcher/preferences/DeveloperSettingsActivity.kt @@ -67,13 +67,6 @@ class DeveloperSettingsActivity : ComponentActivity() { } } -@Composable -fun releaseChannelToKey(option: Int): String = when (option) { - 1 -> stringResource(R.string.preference_release_channel_beta) - 2 -> stringResource(R.string.preference_release_channel_nightly) - else -> stringResource(R.string.preference_release_channel_stable) -} - @OptIn(ExperimentalMaterial3Api::class) @Composable fun DeveloperSettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) { @@ -156,9 +149,12 @@ fun DeveloperSettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) { SettingsSelectCard( title = stringResource(R.string.preference_release_channel_tag_name), dialogTitle = stringResource(R.string.preference_release_channel_select), - maxVal = 2, preferenceKey = PreferenceUtils.Key.RELEASE_CHANNEL_TAG, - toLabel = { releaseChannelToKey(it) } + options = linkedMapOf( + 0 to stringResource(R.string.preference_release_channel_stable), + 1 to stringResource(R.string.preference_release_channel_beta), + 2 to stringResource(R.string.preference_release_channel_nightly), + ) ) ElevatedCard(modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp)) { diff --git a/app/src/main/java/com/geode/launcher/preferences/SettingsActivity.kt b/app/src/main/java/com/geode/launcher/preferences/SettingsActivity.kt index 0c48a15..9b955c5 100644 --- a/app/src/main/java/com/geode/launcher/preferences/SettingsActivity.kt +++ b/app/src/main/java/com/geode/launcher/preferences/SettingsActivity.kt @@ -205,24 +205,6 @@ fun UpdateIndicator( } } -@Composable -fun themeToKey(theme: Int): String { - return when (theme) { - 1 -> stringResource(R.string.preference_theme_light) - 2 -> stringResource(R.string.preference_theme_dark) - else -> stringResource(R.string.preference_theme_default) - } -} - -@Composable -fun displayOptionToKey(option: Int): String { - return when (option) { - 1 -> stringResource(R.string.preference_display_mode_legacy) - 2 -> stringResource(R.string.preference_display_mode_fullscreen) - else -> stringResource(R.string.preference_display_mode_default) - } -} - fun updateTheme(context: Context, theme: Int) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager @@ -323,9 +305,12 @@ fun SettingsScreen( SettingsSelectCard( title = stringResource(R.string.preference_theme_name), dialogTitle = stringResource(R.string.preference_theme_select), - maxVal = 2, preferenceKey = PreferenceUtils.Key.THEME, - toLabel = { themeToKey(it) }, + options = linkedMapOf( + 0 to stringResource(R.string.preference_theme_default), + 1 to stringResource(R.string.preference_theme_light), + 2 to stringResource(R.string.preference_theme_dark), + ), extraSelectBehavior = { updateTheme(context, it) } ) SettingsCard( @@ -347,10 +332,16 @@ fun SettingsScreen( SettingsSelectCard( title = stringResource(R.string.preference_display_mode_name), dialogTitle = stringResource(R.string.preference_display_mode_select), - // necessary api doesn't exist on older versions of android - maxVal = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 2 else 1, preferenceKey = PreferenceUtils.Key.DISPLAY_MODE, - toLabel = { displayOptionToKey(it) } + options = buildMap { + put(0, stringResource(R.string.preference_display_mode_default)) + put(1, stringResource(R.string.preference_display_mode_legacy)) + + // necessary api doesn't exist on older versions of android + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + put(2, stringResource(R.string.preference_display_mode_fullscreen)) + } + } ) val currentDisplayMode by PreferenceUtils.useIntPreference(PreferenceUtils.Key.DISPLAY_MODE) diff --git a/app/src/main/java/com/geode/launcher/preferences/SettingsComponents.kt b/app/src/main/java/com/geode/launcher/preferences/SettingsComponents.kt index befcbdb..8fd113c 100644 --- a/app/src/main/java/com/geode/launcher/preferences/SettingsComponents.kt +++ b/app/src/main/java/com/geode/launcher/preferences/SettingsComponents.kt @@ -89,9 +89,8 @@ fun OptionsGroup(title: String, content: @Composable () -> Unit) { fun SettingsSelectCard( title: String, dialogTitle: String, - maxVal: Int, preferenceKey: PreferenceUtils.Key, - toLabel: @Composable (Int) -> String, + options: Map, extraSelectBehavior: ((Int) -> Unit)? = null ) { val preferenceValue by PreferenceUtils.useIntPreference(preferenceKey) @@ -108,7 +107,7 @@ fun SettingsSelectCard( role = Role.Button ) ) { - Text(toLabel(preferenceValue)) + Text(options[preferenceValue] ?: preferenceValue.toString()) } if (showDialog) { @@ -127,8 +126,8 @@ fun SettingsSelectCard( }, initialValue = preferenceValue, ) { - (0..maxVal).forEach { - SelectOption(name = toLabel(it), value = it) + options.forEach { (k, v) -> + SelectOption(name = v, value = k) } } }