feat: add EditListPreference component for lora.ignore_incoming

This commit is contained in:
andrekir 2023-04-01 06:46:18 -03:00
parent e6d19d9e6d
commit 902763dba7
2 changed files with 38 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.twotone.Info
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@ -161,6 +162,36 @@ fun EditIPv4Preference(
)
}
@Composable
fun EditListPreference(
title: String,
list: List<Int>,
maxCount: Int,
enabled: Boolean,
keyboardActions: KeyboardActions,
onValuesChanged: (List<Int>) -> Unit,
modifier: Modifier = Modifier,
) {
val listState = remember(list) { mutableStateListOf<Int>().apply { addAll(list) } }
Column(modifier = modifier) {
for (i in 0..list.size.coerceAtMost(maxCount - 1)) {
val value = listState.getOrNull(i)
EditTextPreference(
title = "$title ${i + 1}/$maxCount",
value = value ?: 0,
enabled = enabled,
keyboardActions = keyboardActions,
onValueChanged = {
if (value == null) listState.add(it) else listState[i] = it
onValuesChanged(listState)
},
modifier = modifier.fillMaxWidth()
)
}
}
}
@Composable
fun EditTextPreference(
title: String,