feat(settings): add options for displaying e number list information

This commit is contained in:
Anthony Berg 2024-08-10 23:23:37 +02:00
parent 1a77654d29
commit 6c3d2b1258
3 changed files with 42 additions and 3 deletions

View File

@ -4,4 +4,12 @@ import androidx.compose.runtime.mutableIntStateOf
object SettingsVar {
val theme = mutableIntStateOf(0)
/**
* - 0 - E Number Main, Full name Secondary
* - 1 - Full name Main, E Number Secondary
* - 2 - E Number only
* - 3 - Full name only
*/
val eNumberStyle = mutableIntStateOf(0)
}

View File

@ -25,6 +25,7 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import data.EGroup
import data.ENumber
import data.SettingsVar
class ENumberList(private val eNumbers: List<EGroup>, private val searchText: MutableState<String>) : Screen {
@ -79,11 +80,21 @@ class ENumberList(private val eNumbers: List<EGroup>, private val searchText: Mu
)
}
// Fun fact, these settings were added whilst on a plane
@Composable
private fun ItemList(eNumber: ENumber) {
/*
Checks if the settings affect the order of what is displayed
Even - E Number is headline
Odd - Full name is headline
*/
val headline = if (SettingsVar.eNumberStyle.value % 2 == 0) eNumber.number else eNumber.name
val supporting = if (SettingsVar.eNumberStyle.value % 2 == 0) eNumber.name else eNumber.number
ListItem(
headlineContent = { Text(text = eNumber.name) },
supportingContent = { Text(text = eNumber.number) },
headlineContent = { Text(text = headline) },
// Checks if the supporting text is wanted in the settings
supportingContent = { if (SettingsVar.eNumberStyle.value < 2) Text(text = supporting) },
leadingContent = {
VeganStatusIcon(
vegan = eNumber.vegan,

View File

@ -49,7 +49,7 @@ object Settings : Screen {
@Composable
private fun SettingsContent() {
Theme()
Text("List Style")
ENumberStyle()
}
/**
@ -77,4 +77,24 @@ object Settings : Screen {
}
}
}
@Composable
private fun ENumberStyle() {
var mode by rememberSaveable { SettingsVar.eNumberStyle }
val modes = listOf("E Number Main", "Full Name Main", "E Number Only", "Full Name Only")
Text("List Style")
for ((index, value) in modes.withIndex()) {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
RadioButton(
selected = mode == index,
onClick = { mode = index }
)
Text(value)
}
}
}
}