Improved settings dialog UI
This commit is contained in:
parent
84d986587d
commit
8d00141df2
5
src/main/kotlin/app/DropDownOption.kt
Normal file
5
src/main/kotlin/app/DropDownOption.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
interface DropDownOption {
|
||||||
|
val optionName: String
|
||||||
|
}
|
@ -6,6 +6,7 @@ import androidx.compose.material.darkColors
|
|||||||
import androidx.compose.material.lightColors
|
import androidx.compose.material.lightColors
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import app.DropDownOption
|
||||||
|
|
||||||
private val DarkColorPalette = darkColors(
|
private val DarkColorPalette = darkColors(
|
||||||
primary = primaryLight,
|
primary = primaryLight,
|
||||||
@ -125,9 +126,12 @@ val Colors.scrollbarHover: Color
|
|||||||
get() = if (isLight) hoverScrollbarColorLight else hoverScrollbarColorDark
|
get() = if (isLight) hoverScrollbarColorLight else hoverScrollbarColorDark
|
||||||
|
|
||||||
|
|
||||||
enum class Themes(val displayName: String) {
|
enum class Themes(val displayName: String) : DropDownOption {
|
||||||
LIGHT("Light"),
|
LIGHT("Light"),
|
||||||
DARK("Dark")
|
DARK("Dark");
|
||||||
|
|
||||||
|
override val optionName: String
|
||||||
|
get() = displayName
|
||||||
}
|
}
|
||||||
|
|
||||||
val themesList = listOf(
|
val themesList = listOf(
|
||||||
|
@ -7,6 +7,8 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import app.AppPreferences
|
import app.AppPreferences
|
||||||
|
import app.DropDownOption
|
||||||
|
import app.theme.Themes
|
||||||
import app.theme.primaryTextColor
|
import app.theme.primaryTextColor
|
||||||
import app.theme.themesList
|
import app.theme.themesList
|
||||||
|
|
||||||
@ -15,46 +17,23 @@ fun SettingsDialog(
|
|||||||
appPreferences: AppPreferences,
|
appPreferences: AppPreferences,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var showThemeDropdown by remember { mutableStateOf(false) }
|
|
||||||
val currentTheme by appPreferences.themeState.collectAsState()
|
val currentTheme by appPreferences.themeState.collectAsState()
|
||||||
|
|
||||||
MaterialDialog {
|
MaterialDialog {
|
||||||
Column {
|
Column(modifier = Modifier.width(500.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Settings",
|
text = "Settings",
|
||||||
color = MaterialTheme.colors.primaryTextColor,
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
)
|
)
|
||||||
|
|
||||||
Row(
|
SettingDropDown(
|
||||||
modifier = Modifier.padding(top = 8.dp),
|
title = "Theme",
|
||||||
verticalAlignment = Alignment.CenterVertically
|
dropDownOptions = themesList,
|
||||||
) {
|
currentOption = currentTheme,
|
||||||
Text(
|
onOptionSelected = { theme ->
|
||||||
text = "Theme",
|
appPreferences.theme = theme
|
||||||
color = MaterialTheme.colors.primaryTextColor,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(300.dp))
|
|
||||||
OutlinedButton(onClick = { showThemeDropdown = true }) {
|
|
||||||
Text(
|
|
||||||
currentTheme.displayName,
|
|
||||||
color = MaterialTheme.colors.primaryTextColor,
|
|
||||||
)
|
|
||||||
|
|
||||||
DropdownMenu(
|
|
||||||
expanded = showThemeDropdown,
|
|
||||||
onDismissRequest = { showThemeDropdown = false },
|
|
||||||
) {
|
|
||||||
for (theme in themesList) {
|
|
||||||
DropdownMenuItem(
|
|
||||||
onClick = {
|
|
||||||
appPreferences.theme = theme
|
|
||||||
showThemeDropdown = false
|
|
||||||
}
|
|
||||||
) { Text(theme.displayName) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -67,3 +46,93 @@ fun SettingsDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T: DropDownOption> SettingDropDown(
|
||||||
|
title: String,
|
||||||
|
dropDownOptions: List<T>,
|
||||||
|
onOptionSelected: (T) -> Unit,
|
||||||
|
currentOption: T,
|
||||||
|
) {
|
||||||
|
var showThemeDropdown by remember { mutableStateOf(false) }
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp, horizontal = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Box {
|
||||||
|
OutlinedButton(onClick = { showThemeDropdown = true }) {
|
||||||
|
Text(
|
||||||
|
currentOption.optionName,
|
||||||
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = showThemeDropdown,
|
||||||
|
onDismissRequest = { showThemeDropdown = false },
|
||||||
|
) {
|
||||||
|
for (dropDownOption in dropDownOptions) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = {
|
||||||
|
showThemeDropdown = false
|
||||||
|
onOptionSelected(dropDownOption)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(dropDownOption.optionName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T: DropDownOption> SettingTextInput(
|
||||||
|
title: String,
|
||||||
|
dropDownOptions: List<T>,
|
||||||
|
onOptionSelected: (T) -> Unit,
|
||||||
|
currentOption: T,
|
||||||
|
) {
|
||||||
|
var showThemeDropdown by remember { mutableStateOf(false) }
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp, horizontal = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(300.dp))
|
||||||
|
Box {
|
||||||
|
OutlinedButton(onClick = { showThemeDropdown = true }) {
|
||||||
|
Text(
|
||||||
|
currentOption.optionName,
|
||||||
|
color = MaterialTheme.colors.primaryTextColor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = showThemeDropdown,
|
||||||
|
onDismissRequest = { showThemeDropdown = false },
|
||||||
|
) {
|
||||||
|
for (dropDownOption in dropDownOptions) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = {
|
||||||
|
showThemeDropdown = false
|
||||||
|
onOptionSelected(dropDownOption)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(dropDownOption.optionName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user