add option groups

This commit is contained in:
qimiko committed 2022-11-05 10:58:13 -07:00
1 parent ffbee9f0c2
commit 991b66dbae
3 files changed
+46 -9

No files matched your search

@@ -23,6 +23,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.edit import androidx.core.content.edit
import com.geode.geodelauncher.ui.theme.GeodeLauncherTheme import com.geode.geodelauncher.ui.theme.GeodeLauncherTheme
import com.geode.geodelauncher.ui.theme.Typography
class SettingsActivity : ComponentActivity() { class SettingsActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -45,6 +46,8 @@ class SettingsActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun SettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) { fun SettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) {
val context = LocalContext.current
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
@@ -72,7 +75,12 @@ fun SettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) {
.fillMaxWidth(), .fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp) verticalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
OptionsCard(R.string.preference_load_testing_name, R.string.preference_load_testing) OptionsGroup(context.getString(R.string.preference_category_testing)) {
SettingsCard(
title = context.getString(R.string.preference_load_testing_name),
preferenceId = R.string.preference_load_testing
)
}
} }
} }
) )
@@ -102,26 +110,48 @@ fun getSetting(context: Context, @StringRes preferenceId: Int): Boolean {
return preferences.getBoolean(context.getString(preferenceId), false) return preferences.getBoolean(context.getString(preferenceId), false)
} }
@Composable
fun OptionsGroup(title: String, content: @Composable () -> Unit) {
Column {
Text(
title,
style = Typography.titleMedium,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
)
content()
}
}
@Composable @Composable
fun OptionsCard(@StringRes title: Int, @StringRes preferenceId: Int) { fun SettingsCard(title: String, @StringRes preferenceId: Int) {
val context = LocalContext.current val context = LocalContext.current
val settingEnabled = remember { val settingEnabled = remember {
mutableStateOf(getSetting(context, preferenceId)) } mutableStateOf(getSetting(context, preferenceId)) }
Row(
Modifier.fillMaxWidth() OptionsCard(
.height(64.dp) title = title,
.toggleable( modifier = Modifier.toggleable(
value = settingEnabled.value, value = settingEnabled.value,
onValueChange = { settingEnabled.value = toggleSetting(context, preferenceId) }, onValueChange = { settingEnabled.value = toggleSetting(context, preferenceId) },
role = Role.Switch, role = Role.Switch,
) )
) {
Switch(checked = settingEnabled.value, onCheckedChange = null)
}
}
@Composable
fun OptionsCard(title: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
Row(
modifier
.fillMaxWidth()
.height(64.dp)
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
Arrangement.SpaceBetween, Arrangement.SpaceBetween,
Alignment.CenterVertically, Alignment.CenterVertically,
) { ) {
Text(context.getString(title)) Text(title)
Switch(checked = settingEnabled.value, onCheckedChange = null) content()
} }
} }
@@ -129,7 +159,7 @@ fun OptionsCard(@StringRes title: Int, @StringRes preferenceId: Int) {
@Composable @Composable
fun OptionsCardPreview() { fun OptionsCardPreview() {
GeodeLauncherTheme { GeodeLauncherTheme {
OptionsCard(R.string.preference_load_testing_name, R.string.preference_load_testing) SettingsCard("Load files from /test", R.string.preference_load_testing)
} }
} }
@@ -14,6 +14,12 @@ val Typography = Typography(
fontSize = 16.sp, fontSize = 16.sp,
lineHeight = 24.sp, lineHeight = 24.sp,
letterSpacing = 0.5.sp letterSpacing = 0.5.sp
),
titleMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 18.sp,
letterSpacing = 0.5.sp
) )
/* Other default text styles to override /* Other default text styles to override
titleLarge = TextStyle( titleLarge = TextStyle(
+1
View File
@@ -4,6 +4,7 @@
<string name="failed_mod_core">Failed to load mod core.</string> <string name="failed_mod_core">Failed to load mod core.</string>
<string name="no_activity_found">No activity found for this action.</string> <string name="no_activity_found">No activity found for this action.</string>
<string name="preference_file_key">GeodeLauncherPreferencesFileKey</string> <string name="preference_file_key">GeodeLauncherPreferencesFileKey</string>
<string name="preference_category_testing">Testing</string>
<string name="preference_load_testing">PreferenceLoadTesting</string> <string name="preference_load_testing">PreferenceLoadTesting</string>
<string name="preference_load_testing_name">Load files from /test</string> <string name="preference_load_testing_name">Load files from /test</string>
<string name="title_activity_settings">SettingsActivity</string> <string name="title_activity_settings">SettingsActivity</string>