mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: Pref's StringSetValue
This commit is contained in:
parent
bbeaf19a68
commit
3b719f80b4
@ -100,6 +100,20 @@ object Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
class StringSetValue(override val value: Set<String>) : Value<Set<String>>() {
|
||||
override fun get(
|
||||
preferences: SharedPreferences,
|
||||
key: String,
|
||||
defaultValue: Value<Set<String>>,
|
||||
): Set<String> {
|
||||
return preferences.getStringSet(key, defaultValue.value) ?: emptySet()
|
||||
}
|
||||
|
||||
override fun set(preferences: SharedPreferences, key: String, value: Set<String>) {
|
||||
preferences.edit().putStringSet(key, value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
class StringValue(override val value: String) : Value<String>() {
|
||||
override fun get(
|
||||
preferences: SharedPreferences,
|
||||
|
@ -0,0 +1,123 @@
|
||||
package com.machiav3lli.fdroid.ui.compose.components
|
||||
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.FilterChipDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SelectChip(
|
||||
modifier: Modifier = Modifier,
|
||||
text: String,
|
||||
checked: Boolean = false,
|
||||
onClick: () -> Unit = {}
|
||||
) {
|
||||
FilterChip(
|
||||
modifier = modifier,
|
||||
label = { Text(text = text) },
|
||||
selected = checked,
|
||||
onClick = onClick,
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChipsSwitch(
|
||||
firstTextId: Int,
|
||||
firstIconId: Int,
|
||||
secondTextId: Int,
|
||||
secondIconId: Int,
|
||||
firstSelected: Boolean = true,
|
||||
onCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.border(
|
||||
1.dp,
|
||||
MaterialTheme.colorScheme.outline,
|
||||
MaterialTheme.shapes.medium
|
||||
)
|
||||
.padding(horizontal = 6.dp)
|
||||
.fillMaxWidth(),
|
||||
) {
|
||||
val (firstSelected, selectFirst) = remember { mutableStateOf(firstSelected) }
|
||||
FilterChip(
|
||||
modifier = Modifier.weight(1f),
|
||||
border = FilterChipDefaults.filterChipBorder(
|
||||
borderColor = Color.Transparent,
|
||||
borderWidth = 0.dp
|
||||
),
|
||||
selected = firstSelected,
|
||||
onClick = {
|
||||
onCheckedChange(true)
|
||||
selectFirst(true)
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
painter = painterResource(id = firstIconId),
|
||||
contentDescription = stringResource(id = firstTextId)
|
||||
)
|
||||
},
|
||||
label = {
|
||||
Row(
|
||||
Modifier
|
||||
.padding(vertical = 8.dp, horizontal = 4.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = firstTextId),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
FilterChip(
|
||||
modifier = Modifier.weight(1f),
|
||||
border = FilterChipDefaults.filterChipBorder(
|
||||
borderColor = Color.Transparent,
|
||||
borderWidth = 0.dp
|
||||
),
|
||||
selected = !firstSelected,
|
||||
onClick = {
|
||||
onCheckedChange(false)
|
||||
selectFirst(false)
|
||||
},
|
||||
label = {
|
||||
Row(
|
||||
Modifier
|
||||
.padding(vertical = 8.dp, horizontal = 4.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = secondTextId),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
},
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
painter = painterResource(id = secondIconId),
|
||||
contentDescription = stringResource(id = secondTextId)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user