kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
use modelMapOf and modelListOf - much nicer!
rodzic
8311eb1a4d
commit
59d28b75c1
|
@ -304,9 +304,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
// We only care about nodes that have user info
|
||||
info.user?.id?.let {
|
||||
val newnodes = NodeDB.nodes.value.toMutableMap()
|
||||
newnodes[it] = info
|
||||
NodeDB.nodes.value = newnodes
|
||||
NodeDB.nodes[it] = info
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,11 +350,13 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
debug("connected to mesh service, isConnected=${UIState.isConnected.value}")
|
||||
|
||||
// make some placeholder nodeinfos
|
||||
NodeDB.nodes.value =
|
||||
m.nodes.toList().map {
|
||||
// Update our nodeinfos based on data from the device
|
||||
NodeDB.nodes.clear()
|
||||
NodeDB.nodes.putAll(
|
||||
m.nodes.map {
|
||||
it.user?.id!! to it
|
||||
}.toMap()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import android.os.RemoteException
|
||||
import androidx.compose.mutableStateOf
|
||||
import androidx.compose.frames.modelListOf
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.utf8
|
||||
|
@ -21,7 +21,7 @@ data class TextMessage(
|
|||
|
||||
|
||||
object MessagesState : Logging {
|
||||
val testTexts = listOf(
|
||||
private val testTexts = arrayOf(
|
||||
TextMessage(
|
||||
"+16508765310",
|
||||
"I found the cache"
|
||||
|
@ -34,15 +34,11 @@ object MessagesState : Logging {
|
|||
|
||||
// If the following (unused otherwise) line is commented out, the IDE preview window works.
|
||||
// if left in the preview always renders as empty.
|
||||
val messages = mutableStateOf(testTexts, { a, b ->
|
||||
a.size == b.size // If the # of messages changes, consider it important for rerender
|
||||
})
|
||||
val messages = modelListOf(*testTexts)
|
||||
|
||||
/// add a message our GUI list of past msgs
|
||||
fun addMessage(m: TextMessage) {
|
||||
val l = messages.value.toMutableList()
|
||||
l.add(m)
|
||||
messages.value = l
|
||||
messages.add(m)
|
||||
}
|
||||
|
||||
/// Send a message and added it to our GUI log
|
||||
|
|
|
@ -44,8 +44,8 @@ object NodeDB {
|
|||
val myId = mutableStateOf("+16508765309")
|
||||
|
||||
/// A map from nodeid to to nodeinfo
|
||||
val nodes = mutableStateOf(testNodes.map { it.user!!.id to it }.toMap())
|
||||
val nodes = mutableMapOf(* testNodes.map { it.user!!.id to it }.toTypedArray())
|
||||
|
||||
/// Could be null if we haven't received our node DB yet
|
||||
val ourNodeInfo get() = nodes.value[myId.value!!]
|
||||
val ourNodeInfo get() = nodes[myId.value!!]
|
||||
}
|
|
@ -40,7 +40,7 @@ fun HomeContent() {
|
|||
Text(if (UIState.isConnected.value) "Connected" else "Not Connected")
|
||||
}
|
||||
|
||||
NodeDB.nodes.value.values.forEach {
|
||||
NodeDB.nodes.values.forEach {
|
||||
NodeInfoCard(it)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@ val TimestampEmphasis = object : Emphasis {
|
|||
@Composable
|
||||
fun MessageCard(msg: TextMessage, modifier: Modifier = Modifier.None) {
|
||||
Row(modifier = modifier) {
|
||||
UserIcon(NodeDB.nodes.value[msg.from])
|
||||
UserIcon(NodeDB.nodes[msg.from])
|
||||
|
||||
Column(modifier = LayoutPadding(left = 12.dp)) {
|
||||
Row {
|
||||
val nodes = NodeDB.nodes.value
|
||||
val nodes = NodeDB.nodes
|
||||
|
||||
// If we can't find the sender, just use the ID
|
||||
val node = nodes?.get(msg.from)
|
||||
|
@ -78,7 +78,7 @@ fun MessagesContent() {
|
|||
modifier = LayoutFlexible(1f)
|
||||
) {
|
||||
Column {
|
||||
messages.value.forEach { msg ->
|
||||
messages.forEach { msg ->
|
||||
MessageCard(
|
||||
msg, modifier = LayoutPadding(
|
||||
left = sidePad,
|
||||
|
|
Ładowanie…
Reference in New Issue