mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add EditListPreference component for lora.ignore_incoming
This commit is contained in:
parent
e6d19d9e6d
commit
902763dba7
2 changed files with 38 additions and 5 deletions
|
|
@ -28,6 +28,7 @@ import com.geeksville.mesh.service.MeshService
|
|||
import com.geeksville.mesh.ui.components.BitwisePreference
|
||||
import com.geeksville.mesh.ui.components.DropDownPreference
|
||||
import com.geeksville.mesh.ui.components.EditIPv4Preference
|
||||
import com.geeksville.mesh.ui.components.EditListPreference
|
||||
import com.geeksville.mesh.ui.components.EditTextPreference
|
||||
import com.geeksville.mesh.ui.components.PreferenceCategory
|
||||
import com.geeksville.mesh.ui.components.PreferenceFooter
|
||||
|
|
@ -809,14 +810,15 @@ fun DeviceSettingsItemList(viewModel: UIViewModel = viewModel()) {
|
|||
item { Divider() }
|
||||
|
||||
item {
|
||||
EditTextPreference(title = "Ignore incoming", // FIXME use proper Composable component
|
||||
value = loraInput.ignoreIncomingList.getOrNull(0) ?: 0,
|
||||
EditListPreference(title = "Ignore incoming",
|
||||
list = loraInput.ignoreIncomingList,
|
||||
maxCount = 3, // ignore_incoming max_count:3
|
||||
enabled = connected,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = {
|
||||
onValuesChanged = { list ->
|
||||
loraInput = loraInput.copy {
|
||||
if (loraInput.ignoreIncomingCount == 0) ignoreIncoming.add(it)
|
||||
else if (it == 0) ignoreIncoming.clear() else ignoreIncoming[0] = it
|
||||
ignoreIncoming.clear()
|
||||
ignoreIncoming.addAll(list.filter { it != 0 })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue