mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Fix lat/lng/alt config validation errors when position is null (#1260)
This commit is contained in:
parent
7be602d652
commit
dc9e780663
2 changed files with 12 additions and 11 deletions
|
|
@ -57,6 +57,7 @@ import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import com.geeksville.mesh.NodeInfo
|
import com.geeksville.mesh.NodeInfo
|
||||||
|
import com.geeksville.mesh.Position
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
import com.geeksville.mesh.config
|
import com.geeksville.mesh.config
|
||||||
|
|
@ -413,12 +414,12 @@ fun RadioConfigNavHost(
|
||||||
}
|
}
|
||||||
composable(ConfigRoute.POSITION.name) {
|
composable(ConfigRoute.POSITION.name) {
|
||||||
PositionConfigItemList(
|
PositionConfigItemList(
|
||||||
location = node?.position,
|
location = node?.position ?: Position(0.0, 0.0, 0),
|
||||||
positionConfig = radioConfigState.radioConfig.position,
|
positionConfig = radioConfigState.radioConfig.position,
|
||||||
enabled = connected,
|
enabled = connected,
|
||||||
onSaveClicked = { locationInput, positionInput ->
|
onSaveClicked = { locationInput, positionInput ->
|
||||||
if (positionInput.fixedPosition) {
|
if (positionInput.fixedPosition) {
|
||||||
if (locationInput != null && locationInput != node?.position) {
|
if (locationInput != node?.position) {
|
||||||
viewModel.setFixedPosition(destNum, locationInput)
|
viewModel.setFixedPosition(destNum, locationInput)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ import com.geeksville.mesh.ui.components.SwitchPreference
|
||||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||||
@Composable
|
@Composable
|
||||||
fun PositionConfigItemList(
|
fun PositionConfigItemList(
|
||||||
location: Position?,
|
location: Position,
|
||||||
positionConfig: PositionConfig,
|
positionConfig: PositionConfig,
|
||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
onSaveClicked: (position: Position?, config: PositionConfig) -> Unit,
|
onSaveClicked: (position: Position, config: PositionConfig) -> Unit,
|
||||||
) {
|
) {
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
var locationInput by rememberSaveable { mutableStateOf(location) }
|
var locationInput by rememberSaveable { mutableStateOf(location) }
|
||||||
|
|
@ -93,31 +93,31 @@ fun PositionConfigItemList(
|
||||||
if (positionInput.fixedPosition) {
|
if (positionInput.fixedPosition) {
|
||||||
item {
|
item {
|
||||||
EditTextPreference(title = "Latitude",
|
EditTextPreference(title = "Latitude",
|
||||||
value = locationInput?.latitude ?: 0.0,
|
value = locationInput.latitude,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||||
onValueChanged = { value ->
|
onValueChanged = { value ->
|
||||||
if (value >= -90 && value <= 90.0)
|
if (value >= -90 && value <= 90.0)
|
||||||
locationInput?.let { locationInput = it.copy(latitude = value) }
|
locationInput = locationInput.copy(latitude = value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
EditTextPreference(title = "Longitude",
|
EditTextPreference(title = "Longitude",
|
||||||
value = locationInput?.longitude ?: 0.0,
|
value = locationInput.longitude,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||||
onValueChanged = { value ->
|
onValueChanged = { value ->
|
||||||
if (value >= -180 && value <= 180.0)
|
if (value >= -180 && value <= 180.0)
|
||||||
locationInput?.let { locationInput = it.copy(longitude = value) }
|
locationInput = locationInput.copy(longitude = value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
EditTextPreference(title = "Altitude (meters)",
|
EditTextPreference(title = "Altitude (meters)",
|
||||||
value = locationInput?.altitude ?: 0,
|
value = locationInput.altitude,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||||
onValueChanged = { value ->
|
onValueChanged = { value ->
|
||||||
locationInput?.let { locationInput = it.copy(altitude = value) }
|
locationInput = locationInput.copy(altitude = value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +196,7 @@ fun PositionConfigItemList(
|
||||||
@Composable
|
@Composable
|
||||||
private fun PositionConfigPreview() {
|
private fun PositionConfigPreview() {
|
||||||
PositionConfigItemList(
|
PositionConfigItemList(
|
||||||
location = null,
|
location = Position(0.0, 0.0, 0),
|
||||||
positionConfig = PositionConfig.getDefaultInstance(),
|
positionConfig = PositionConfig.getDefaultInstance(),
|
||||||
enabled = true,
|
enabled = true,
|
||||||
onSaveClicked = { _, _ -> },
|
onSaveClicked = { _, _ -> },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue