sforkowany z mirror/meshtastic-android
add fields for position fixed (#524)
rodzic
57030f90b6
commit
0c783dfbff
|
@ -80,7 +80,7 @@ interface IMeshService {
|
|||
void setChannel(in byte []payload);
|
||||
|
||||
/// Send position packet with wantResponse to nodeNum
|
||||
void requestPosition(in int idNum);
|
||||
void requestPosition(in int idNum, in double lat, in double lon, in int alt);
|
||||
|
||||
/// Send Shutdown admin packet to nodeNum
|
||||
void requestShutdown(in int idNum);
|
||||
|
|
|
@ -157,9 +157,9 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun requestPosition(destNum: Int) {
|
||||
fun requestPosition(destNum: Int, lat: Double = 0.0, lon: Double = 0.0, alt: Int = 0) {
|
||||
try {
|
||||
meshService?.requestPosition(destNum)
|
||||
meshService?.requestPosition(destNum, lat, lon, alt)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Request position error: ${ex.message}")
|
||||
}
|
||||
|
|
|
@ -1353,10 +1353,6 @@ class MeshService : Service(), Logging {
|
|||
})
|
||||
}
|
||||
|
||||
private fun requestPosition(idNum: Int) {
|
||||
sendPosition(time = 0, destNum = idNum, wantResponse = true)
|
||||
}
|
||||
|
||||
private fun requestShutdown(idNum: Int) {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
shutdownSeconds = 5
|
||||
|
@ -1697,9 +1693,13 @@ class MeshService : Service(), Logging {
|
|||
stopLocationRequests()
|
||||
}
|
||||
|
||||
override fun requestPosition(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestPosition(idNum)
|
||||
}
|
||||
override fun requestPosition(idNum: Int, lat: Double, lon: Double, alt: Int) =
|
||||
toRemoteExceptions {
|
||||
// request position
|
||||
if (idNum != 0) sendPosition(time = 0, destNum = idNum, wantResponse = true)
|
||||
// set local node's fixed position
|
||||
else sendPosition(time = 0, destNum = null, lat = lat, lon = lon, alt = alt)
|
||||
}
|
||||
|
||||
override fun requestShutdown(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestShutdown(idNum)
|
||||
|
|
|
@ -42,6 +42,7 @@ fun PreferenceItemList(viewModel: UIViewModel) {
|
|||
val localConfig by viewModel.localConfig.collectAsState()
|
||||
val ourNodeInfo by viewModel.nodeDB.ourNodeInfo.observeAsState()
|
||||
var userInput by remember(ourNodeInfo?.user) { mutableStateOf(ourNodeInfo?.user) }
|
||||
var positionInfo by remember(ourNodeInfo?.position) { mutableStateOf(ourNodeInfo?.position) }
|
||||
|
||||
// Temporary [ConfigProtos.Config] state holders
|
||||
var deviceInput by remember(localConfig.device) { mutableStateOf(localConfig.device) }
|
||||
|
@ -197,6 +198,38 @@ fun PreferenceItemList(viewModel: UIViewModel) {
|
|||
}
|
||||
item { Divider() }
|
||||
|
||||
if (positionInput.fixedPosition) {
|
||||
item {
|
||||
EditTextPreference(title = "Latitude",
|
||||
value = positionInfo?.latitude ?: 0.0,
|
||||
enabled = connected,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
if (value >= -180 && value <= 180.0)
|
||||
positionInfo?.let { positionInfo = it.copy(latitude = value) }
|
||||
})
|
||||
}
|
||||
item {
|
||||
EditTextPreference(title = "Longitude",
|
||||
value = positionInfo?.longitude ?: 0.0,
|
||||
enabled = connected,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
if (value >= -90 && value <= 90.0)
|
||||
positionInfo?.let { positionInfo = it.copy(longitude = value) }
|
||||
})
|
||||
}
|
||||
item {
|
||||
EditTextPreference(title = "Altitude",
|
||||
value = positionInfo?.altitude ?: 0,
|
||||
enabled = connected,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
positionInfo?.let { positionInfo = it.copy(altitude = value) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
SwitchPreference(title = "GPS enabled",
|
||||
checked = positionInput.gpsEnabled,
|
||||
|
@ -235,14 +268,18 @@ fun PreferenceItemList(viewModel: UIViewModel) {
|
|||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = positionInput != localConfig.position,
|
||||
enabled = positionInput != localConfig.position || positionInfo != ourNodeInfo?.position,
|
||||
onCancelClicked = {
|
||||
focusManager.clearFocus()
|
||||
positionInput = localConfig.position
|
||||
positionInfo = ourNodeInfo?.position
|
||||
},
|
||||
onSaveClicked = {
|
||||
focusManager.clearFocus()
|
||||
viewModel.updatePositionConfig { positionInput }
|
||||
if (positionInfo != ourNodeInfo?.position && positionInput.fixedPosition) positionInfo?.let {
|
||||
viewModel.requestPosition(0, it.latitude, it.longitude, it.altitude)
|
||||
}
|
||||
if (positionInput != localConfig.position) viewModel.updatePositionConfig { positionInput }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
holder.coordsView.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
val ourNodeInfo = model.nodeDB.ourNodeInfo.value
|
||||
val ourNodeInfo = model.nodeDB.nodes.value?.get(model.nodeDB.myId.value)
|
||||
val distance = ourNodeInfo?.distanceStr(n)
|
||||
if (distance != null) {
|
||||
holder.distanceView.text = distance
|
||||
|
|
|
@ -76,7 +76,9 @@ fun RegularPreference(
|
|||
trailingIcon, "trailingIcon",
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentWidth(Alignment.End)
|
||||
.wrapContentWidth(Alignment.End),
|
||||
tint = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
|
||||
else MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.medium),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue