2020-02-17 13:34:52 -08:00
|
|
|
package com.geeksville.mesh.model
|
|
|
|
|
|
2020-04-08 09:53:04 -07:00
|
|
|
import androidx.lifecycle.MutableLiveData
|
2021-03-14 11:42:04 +08:00
|
|
|
import com.geeksville.mesh.MeshProtos
|
2020-02-17 13:34:52 -08:00
|
|
|
import com.geeksville.mesh.MeshUser
|
|
|
|
|
import com.geeksville.mesh.NodeInfo
|
|
|
|
|
import com.geeksville.mesh.Position
|
|
|
|
|
|
2020-04-08 09:53:04 -07:00
|
|
|
|
|
|
|
|
/// NodeDB lives inside the UIViewModel, but it needs a backpointer to reach the service
|
|
|
|
|
class NodeDB(private val ui: UIViewModel) {
|
2020-02-17 13:34:52 -08:00
|
|
|
private val testPositions = arrayOf(
|
2022-03-26 17:44:59 -03:00
|
|
|
Position(32.776665, -96.796989, 35, 123), // dallas
|
|
|
|
|
Position(32.960758, -96.733521, 35, 456), // richardson
|
|
|
|
|
Position(32.912901, -96.781776, 35, 789) // north dallas
|
2020-02-17 13:34:52 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val testNodeNoPosition = NodeInfo(
|
|
|
|
|
8,
|
|
|
|
|
MeshUser(
|
|
|
|
|
"+16508765308".format(8),
|
|
|
|
|
"Kevin MesterNoLoc",
|
2021-03-14 11:42:04 +08:00
|
|
|
"KLO",
|
|
|
|
|
MeshProtos.HardwareModel.ANDROID_SIM
|
2020-02-17 13:34:52 -08:00
|
|
|
),
|
2020-02-19 10:53:36 -08:00
|
|
|
null
|
2020-02-17 13:34:52 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val testNodes = testPositions.mapIndexed { index, it ->
|
|
|
|
|
NodeInfo(
|
|
|
|
|
9 + index,
|
|
|
|
|
MeshUser(
|
|
|
|
|
"+165087653%02d".format(9 + index),
|
|
|
|
|
"Kevin Mester$index",
|
2021-03-14 11:42:04 +08:00
|
|
|
"KM$index",
|
|
|
|
|
MeshProtos.HardwareModel.ANDROID_SIM
|
2020-02-17 13:34:52 -08:00
|
|
|
),
|
2020-02-19 10:53:36 -08:00
|
|
|
it
|
2020-02-17 13:34:52 -08:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 10:56:47 +08:00
|
|
|
private val seedWithTestNodes = false
|
2020-02-25 10:48:54 -08:00
|
|
|
|
2020-02-17 13:34:52 -08:00
|
|
|
/// The unique ID of our node
|
2021-02-01 10:56:47 +08:00
|
|
|
val myId = object : MutableLiveData<String?>(if (seedWithTestNodes) "+16508765309" else null) {}
|
2020-02-17 13:34:52 -08:00
|
|
|
|
|
|
|
|
/// A map from nodeid to to nodeinfo
|
2020-02-25 10:48:54 -08:00
|
|
|
val nodes =
|
2020-04-08 09:53:04 -07:00
|
|
|
object :
|
2021-02-01 10:56:47 +08:00
|
|
|
MutableLiveData<Map<String, NodeInfo>>(mapOf(*(if (seedWithTestNodes) testNodes else listOf()).map { it.user!!.id to it }
|
2020-04-08 09:53:04 -07:00
|
|
|
.toTypedArray())) {}
|
2020-02-17 13:46:13 -08:00
|
|
|
|
2020-02-17 15:56:04 -08:00
|
|
|
/// Could be null if we haven't received our node DB yet
|
2020-04-19 12:31:27 -07:00
|
|
|
val ourNodeInfo get() = nodes.value?.get(myId.value)
|
2020-02-17 13:34:52 -08:00
|
|
|
}
|