kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
feat: add MQTT `mapReportSettings` config
rodzic
59b67d429d
commit
40aae19b45
|
@ -0,0 +1,44 @@
|
|||
package com.geeksville.mesh.ui.components
|
||||
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
|
||||
private enum class PositionPrecision(val value: Int) {
|
||||
HIGH_PRECISION(32),
|
||||
MED_PRECISION(16),
|
||||
LOW_PRECISION(11),
|
||||
DISABLED(0),
|
||||
;
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PositionPrecisionPreference(
|
||||
title: String,
|
||||
value: Int,
|
||||
enabled: Boolean,
|
||||
onValueChanged: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
val useDropDown = PositionPrecision.entries.any { it.value == value }
|
||||
|
||||
if (useDropDown) {
|
||||
DropDownPreference(
|
||||
title = title,
|
||||
enabled = enabled,
|
||||
items = PositionPrecision.entries.map { it.value to it.name },
|
||||
selectedItem = value,
|
||||
onItemSelected = onValueChanged,
|
||||
)
|
||||
} else {
|
||||
EditTextPreference(
|
||||
title = title,
|
||||
value = value,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = onValueChanged,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -38,21 +38,13 @@ import com.geeksville.mesh.R
|
|||
import com.geeksville.mesh.channelSettings
|
||||
import com.geeksville.mesh.copy
|
||||
import com.geeksville.mesh.model.Channel
|
||||
import com.geeksville.mesh.ui.components.DropDownPreference
|
||||
import com.geeksville.mesh.ui.components.EditTextPreference
|
||||
import com.geeksville.mesh.ui.components.PositionPrecisionPreference
|
||||
import com.google.accompanist.themeadapter.appcompat.AppCompatTheme
|
||||
import com.google.protobuf.ByteString
|
||||
import com.google.protobuf.kotlin.toByteString
|
||||
import java.security.SecureRandom
|
||||
|
||||
private enum class PositionPrecision(val value: Int) {
|
||||
HIGH_PRECISION(32),
|
||||
MED_PRECISION(16),
|
||||
LOW_PRECISION(11),
|
||||
DISABLED(0),
|
||||
;
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EditChannelDialog(
|
||||
channelSettings: ChannelProtos.ChannelSettings,
|
||||
|
@ -68,8 +60,6 @@ fun EditChannelDialog(
|
|||
var channelInput by remember(channelSettings) { mutableStateOf(channelSettings) }
|
||||
var pskString by remember(channelInput) { mutableStateOf(encodeToString(channelInput.psk)) }
|
||||
val pskError = pskString != encodeToString(channelInput.psk)
|
||||
val useDropDown = PositionPrecision.entries
|
||||
.any { it.value == channelInput.moduleSettings.positionPrecision }
|
||||
|
||||
fun getRandomKey() {
|
||||
val random = SecureRandom()
|
||||
|
@ -167,20 +157,10 @@ fun EditChannelDialog(
|
|||
)
|
||||
}
|
||||
|
||||
if (useDropDown) DropDownPreference(
|
||||
PositionPrecisionPreference(
|
||||
title = "Position",
|
||||
enabled = true,
|
||||
items = PositionPrecision.entries.map { it.value to it.name },
|
||||
selectedItem = channelInput.moduleSettings.positionPrecision,
|
||||
onItemSelected = {
|
||||
val module = channelInput.moduleSettings.copy { positionPrecision = it }
|
||||
channelInput = channelInput.copy { moduleSettings = module }
|
||||
}
|
||||
) else EditTextPreference(
|
||||
title = "Position precision",
|
||||
value = channelInput.moduleSettings.positionPrecision,
|
||||
enabled = true,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = {
|
||||
val module = channelInput.moduleSettings.copy { positionPrecision = it }
|
||||
channelInput = channelInput.copy { moduleSettings = module }
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.geeksville.mesh.ModuleConfigProtos.ModuleConfig.MQTTConfig
|
|||
import com.geeksville.mesh.copy
|
||||
import com.geeksville.mesh.ui.components.EditPasswordPreference
|
||||
import com.geeksville.mesh.ui.components.EditTextPreference
|
||||
import com.geeksville.mesh.ui.components.PositionPrecisionPreference
|
||||
import com.geeksville.mesh.ui.components.PreferenceCategory
|
||||
import com.geeksville.mesh.ui.components.PreferenceFooter
|
||||
import com.geeksville.mesh.ui.components.SwitchPreference
|
||||
|
@ -107,7 +108,7 @@ fun MQTTConfigItemList(
|
|||
item {
|
||||
EditTextPreference(title = "Root topic",
|
||||
value = mqttInput.root,
|
||||
maxSize = 15, // root max_size:16
|
||||
maxSize = 31, // root max_size:32
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
|
@ -125,6 +126,34 @@ fun MQTTConfigItemList(
|
|||
}
|
||||
item { Divider() }
|
||||
|
||||
item {
|
||||
PositionPrecisionPreference(
|
||||
title = "Map reporting",
|
||||
enabled = enabled,
|
||||
value = mqttInput.mapReportSettings.positionPrecision,
|
||||
onValueChanged = {
|
||||
val settings = mqttInput.mapReportSettings.copy { positionPrecision = it }
|
||||
mqttInput = mqttInput.copy {
|
||||
mapReportingEnabled = settings.positionPrecision > 0
|
||||
mapReportSettings = settings
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
item { Divider() }
|
||||
|
||||
item {
|
||||
EditTextPreference(title = "Map reporting interval (seconds)",
|
||||
value = mqttInput.mapReportSettings.publishIntervalSecs,
|
||||
enabled = enabled && mqttInput.mapReportingEnabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = {
|
||||
val settings = mqttInput.mapReportSettings.copy { publishIntervalSecs = it }
|
||||
mqttInput = mqttInput.copy { mapReportSettings = settings }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = mqttInput != mqttConfig,
|
||||
|
|
Ładowanie…
Reference in New Issue