Skip to content

Commit

Permalink
original select code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 20, 2025
1 parent 824d439 commit dacabda
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 43 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/com/geode/launcher/main/UpdateComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -108,7 +107,7 @@ fun SettingsSelectCard(
role = Role.Button
)
) {
Text(toLabel(preferenceValue))
Text(options[preferenceValue] ?: preferenceValue.toString())
}

if (showDialog) {
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit dacabda

Please sign in to comment.