mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
if we lose device connection at a bad time, don't leave UI confused (autobug)
This commit is contained in:
parent
53b4f59e29
commit
633200ac44
1 changed files with 37 additions and 20 deletions
|
|
@ -606,34 +606,46 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
/// Called when we gain/lose a connection to our mesh radio
|
||||
private fun onMeshConnectionChanged(connected: MeshService.ConnectionState) {
|
||||
model.isConnected.value = connected
|
||||
debug("connchange ${model.isConnected.value}")
|
||||
|
||||
if (connected == MeshService.ConnectionState.CONNECTED) {
|
||||
|
||||
model.meshService?.let { service ->
|
||||
|
||||
val oldConnection = model.isConnected.value
|
||||
model.isConnected.value = connected
|
||||
|
||||
debug("Getting latest radioconfig from service")
|
||||
model.radioConfig.value =
|
||||
MeshProtos.RadioConfig.parseFrom(service.radioConfig)
|
||||
try {
|
||||
model.radioConfig.value =
|
||||
MeshProtos.RadioConfig.parseFrom(service.radioConfig)
|
||||
|
||||
val info = service.myNodeInfo
|
||||
model.myNodeInfo.value = info
|
||||
val info = service.myNodeInfo
|
||||
model.myNodeInfo.value = info
|
||||
|
||||
val isOld = info.minAppVersion > BuildConfig.VERSION_CODE
|
||||
if (isOld)
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(getString(R.string.app_too_old))
|
||||
.setMessage(getString(R.string.must_update))
|
||||
.setPositiveButton("Okay") { _, _ ->
|
||||
info("User acknowledged app is old")
|
||||
}
|
||||
.show()
|
||||
val isOld = info.minAppVersion > BuildConfig.VERSION_CODE
|
||||
if (isOld)
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(getString(R.string.app_too_old))
|
||||
.setMessage(getString(R.string.must_update))
|
||||
.setPositiveButton("Okay") { _, _ ->
|
||||
info("User acknowledged app is old")
|
||||
}
|
||||
.show()
|
||||
|
||||
updateNodesFromDevice()
|
||||
updateNodesFromDevice()
|
||||
|
||||
// we have a connection to our device now, do the channel change
|
||||
perhapsChangeChannel()
|
||||
// we have a connection to our device now, do the channel change
|
||||
perhapsChangeChannel()
|
||||
} catch (ex: RemoteException) {
|
||||
warn("Abandoning connect $ex, because we probably just lost device connection")
|
||||
model.isConnected.value = oldConnection
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// For other connection states, just slam them in
|
||||
model.isConnected.value = connected
|
||||
}
|
||||
}
|
||||
|
||||
private fun perhapsChangeChannel() {
|
||||
|
|
@ -803,7 +815,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
registerMeshReceiver()
|
||||
|
||||
// Init our messages table with the service's record of past text messages (ignore all other message types)
|
||||
val msgs = service.oldMessages.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE }
|
||||
val msgs =
|
||||
service.oldMessages.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE }
|
||||
debug("Service provided ${msgs.size} messages")
|
||||
model.messagesState.setMessages(msgs)
|
||||
val connectionState =
|
||||
|
|
@ -853,7 +866,11 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
}
|
||||
|
||||
// ALSO bind so we can use the api
|
||||
mesh.connect(this, MeshService.createIntent(), Context.BIND_AUTO_CREATE + Context.BIND_ABOVE_CLIENT)
|
||||
mesh.connect(
|
||||
this,
|
||||
MeshService.createIntent(),
|
||||
Context.BIND_AUTO_CREATE + Context.BIND_ABOVE_CLIENT
|
||||
)
|
||||
}
|
||||
|
||||
private fun unbindMeshService() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue