mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-22 00:42:38 +00:00
original select code cleanup
This commit is contained in:
4 files changed
+30
-44
No files matched your search
@@ -183,14 +183,14 @@ fun LauncherUpdateInformation(onDismiss: () -> Unit) {
|
||||
|
||||
}
|
||||
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
|
||||
|
||||
Text(
|
||||
stringResource(R.string.launcher_update_changelog),
|
||||
style = Typography.titleLarge
|
||||
)
|
||||
|
||||
if (nextRelease.release.body != null) {
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
|
||||
|
||||
Text(
|
||||
stringResource(R.string.launcher_update_changelog),
|
||||
style = Typography.titleLarge
|
||||
)
|
||||
|
||||
CompositionLocalProvider(LocalBulletListHandler provides { _, _, _ -> "• " }) {
|
||||
Markdown(
|
||||
content = nextRelease.release.body.replace("\r", ""),
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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<Int, String>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user