if we lose device connection at a bad time, don't leave UI confused (autobug)

This commit is contained in:
Kevin Hester 2021-01-08 14:51:19 +08:00
parent 53b4f59e29
commit 633200ac44

View file

@ -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() {