mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
new cleaner approach of not whacking services seems to aprox work
This commit is contained in:
parent
dabda9d29e
commit
62a64dd782
5 changed files with 21 additions and 10 deletions
|
|
@ -479,14 +479,14 @@ class MeshService : Service(), Logging {
|
|||
private fun loadSettings() {
|
||||
try {
|
||||
getPrefs().getString("json", null)?.let { asString ->
|
||||
discardNodeDB() // Get rid of any old state
|
||||
|
||||
val json = Json(JsonConfiguration.Default)
|
||||
val settings = json.parse(SavedSettings.serializer(), asString)
|
||||
myNodeInfo = settings.myInfo
|
||||
|
||||
// put our node array into our two different map representations
|
||||
nodeDBbyNodeNum.clear()
|
||||
nodeDBbyNodeNum.putAll(settings.nodeDB.map { Pair(it.num, it) })
|
||||
nodeDBbyID.clear()
|
||||
nodeDBbyID.putAll(settings.nodeDB.mapNotNull {
|
||||
it.user?.let { user -> // ignore records that don't have a valid user
|
||||
Pair(
|
||||
|
|
@ -497,7 +497,6 @@ class MeshService : Service(), Logging {
|
|||
})
|
||||
// Note: we do not haveNodeDB = true because that means we've got a valid db from a real device (rather than this possibly stale hint)
|
||||
|
||||
recentDataPackets.clear()
|
||||
recentDataPackets.addAll(settings.messages)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
|
|
@ -505,6 +504,17 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* discard entire node db & message state - used when changing radio channels
|
||||
*/
|
||||
private fun discardNodeDB() {
|
||||
myNodeInfo = null
|
||||
nodeDBbyNodeNum.clear()
|
||||
nodeDBbyID.clear()
|
||||
recentDataPackets.clear()
|
||||
haveNodeDB = false
|
||||
}
|
||||
|
||||
var myNodeInfo: MyNodeInfo? = null
|
||||
|
||||
private var radioConfig: MeshProtos.RadioConfig? = null
|
||||
|
|
@ -1067,6 +1077,7 @@ class MeshService : Service(), Logging {
|
|||
|
||||
override fun setDeviceAddress(deviceAddr: String?) {
|
||||
debug("Passing through device change to radio service: $deviceAddr")
|
||||
discardNodeDB()
|
||||
connectedRadio.setDeviceAddress(deviceAddr)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue