Skip to content

Commit

Permalink
Fix lat/lng/alt config validation errors when position is null (mesht…
Browse files Browse the repository at this point in the history
  • Loading branch information
djholt authored Sep 19, 2024
1 parent 7be602d commit dc9e780
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
import com.geeksville.mesh.R
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.config
Expand Down Expand Up @@ -413,12 +414,12 @@ fun RadioConfigNavHost(
}
composable(ConfigRoute.POSITION.name) {
PositionConfigItemList(
location = node?.position,
location = node?.position ?: Position(0.0, 0.0, 0),
positionConfig = radioConfigState.radioConfig.position,
enabled = connected,
onSaveClicked = { locationInput, positionInput ->
if (positionInput.fixedPosition) {
if (locationInput != null && locationInput != node?.position) {
if (locationInput != node?.position) {
viewModel.setFixedPosition(destNum, locationInput)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import com.geeksville.mesh.ui.components.SwitchPreference
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Composable
fun PositionConfigItemList(
location: Position?,
location: Position,
positionConfig: PositionConfig,
enabled: Boolean,
onSaveClicked: (position: Position?, config: PositionConfig) -> Unit,
onSaveClicked: (position: Position, config: PositionConfig) -> Unit,
) {
val focusManager = LocalFocusManager.current
var locationInput by rememberSaveable { mutableStateOf(location) }
Expand Down Expand Up @@ -93,31 +93,31 @@ fun PositionConfigItemList(
if (positionInput.fixedPosition) {
item {
EditTextPreference(title = "Latitude",
value = locationInput?.latitude ?: 0.0,
value = locationInput.latitude,
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { value ->
if (value >= -90 && value <= 90.0)
locationInput?.let { locationInput = it.copy(latitude = value) }
locationInput = locationInput.copy(latitude = value)
})
}
item {
EditTextPreference(title = "Longitude",
value = locationInput?.longitude ?: 0.0,
value = locationInput.longitude,
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { value ->
if (value >= -180 && value <= 180.0)
locationInput?.let { locationInput = it.copy(longitude = value) }
locationInput = locationInput.copy(longitude = value)
})
}
item {
EditTextPreference(title = "Altitude (meters)",
value = locationInput?.altitude ?: 0,
value = locationInput.altitude,
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { value ->
locationInput?.let { locationInput = it.copy(altitude = value) }
locationInput = locationInput.copy(altitude = value)
})
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ fun PositionConfigItemList(
@Composable
private fun PositionConfigPreview() {
PositionConfigItemList(
location = null,
location = Position(0.0, 0.0, 0),
positionConfig = PositionConfig.getDefaultInstance(),
enabled = true,
onSaveClicked = { _, _ -> },
Expand Down

0 comments on commit dc9e780

Please sign in to comment.