refactor: move activity out of BTScanModel

This commit is contained in:
andrekir 2023-04-03 18:29:41 -03:00
parent b7d91224e4
commit 7fedc2b0e1
3 changed files with 159 additions and 190 deletions

View file

@ -644,6 +644,20 @@ class MainActivity : AppCompatActivity(), Logging {
override fun onStart() {
super.onStart()
scanModel.changeDeviceAddress.observe(this) { newAddr ->
newAddr?.let {
try {
model.meshService?.let { service ->
MeshService.changeDeviceAddress(this, service, newAddr)
}
scanModel.changeSelectedAddress(newAddr) // if it throws the change will be discarded
} catch (ex: RemoteException) {
errormsg("changeDeviceSelection failed, probably it is shutting down $ex.message")
// ignore the failure and the GUI won't be updating anyways
}
}
}
bluetoothViewModel.enabled.observe(this) { enabled ->
if (!enabled && !requestedEnable && scanModel.selectedBluetooth) {
requestedEnable = true