mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-13 05:37:48 +02:00
ui: save config
This commit is contained in:
@ -10,22 +10,32 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.SnackbarHost
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.OpenInNew
|
||||
import androidx.compose.material.icons.rounded.Save
|
||||
import androidx.compose.material.rememberScaffoldState
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.FilledIconButton
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.launch
|
||||
import me.rhunk.snapenhance.config.ConfigProperty
|
||||
import me.rhunk.snapenhance.config.impl.ConfigIntegerValue
|
||||
import me.rhunk.snapenhance.config.impl.ConfigStateListValue
|
||||
@ -109,7 +119,7 @@ class FeaturesSection : Section() {
|
||||
.weight(1f, fill = true)
|
||||
.padding(all = 10.dp)
|
||||
) {
|
||||
Text(text = manager.translation.propertyName(item), fontSize = 16.sp)
|
||||
Text(text = manager.translation.propertyName(item), fontSize = 16.sp, fontWeight = FontWeight.Bold)
|
||||
Text(
|
||||
text = manager.translation.propertyDescription(item),
|
||||
fontSize = 12.sp,
|
||||
@ -132,28 +142,56 @@ class FeaturesSection : Section() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
override fun Content() {
|
||||
val configItems = remember {
|
||||
ConfigProperty.sortedByCategory()
|
||||
}
|
||||
Column {
|
||||
Text(
|
||||
text = "Features",
|
||||
modifier = Modifier.padding(all = 15.dp),
|
||||
fontSize = 20.sp
|
||||
)
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
items(configItems) { item ->
|
||||
PropertyCard(item)
|
||||
val scope = rememberCoroutineScope()
|
||||
val scaffoldState = rememberScaffoldState()
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(scaffoldState.snackbarHostState) },
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(
|
||||
onClick = {
|
||||
manager.config.save()
|
||||
scope.launch {
|
||||
scaffoldState.snackbarHostState.showSnackbar("Saved")
|
||||
}
|
||||
},
|
||||
containerColor = MaterialTheme.colors.primary,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Save,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(innerPadding)
|
||||
) {
|
||||
Text(
|
||||
text = "Features",
|
||||
modifier = Modifier.padding(all = 10.dp),
|
||||
fontSize = 20.sp
|
||||
)
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
items(configItems) { item ->
|
||||
PropertyCard(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
@ -35,6 +35,10 @@ class ConfigWrapper: ConfigAccessor() {
|
||||
}
|
||||
}
|
||||
|
||||
fun save() {
|
||||
writeConfig()
|
||||
}
|
||||
|
||||
private fun loadConfig() {
|
||||
val configContent = file.read()
|
||||
|
||||
|
Reference in New Issue
Block a user