kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
add placeholders for broadcast channels
rodzic
2b8b10a8cf
commit
a9f9be0981
|
@ -170,17 +170,22 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when our contacts DB changes
|
fun onContactsChanged(contacts: Map<String, Packet>) {
|
||||||
fun onContactsChanged(contacts: Collection<Packet>) {
|
// Add empty channel placeholders (always show Broadcast contacts, even when empty)
|
||||||
this.contacts = contacts.sortedByDescending { it.received_time }.toTypedArray()
|
val mutableMap = contacts.toMutableMap()
|
||||||
|
for (ch in 0 until model.channels.value.protobuf.settingsCount) {
|
||||||
|
val contactKey = "$ch${DataPacket.ID_BROADCAST}"
|
||||||
|
if (mutableMap[contactKey] == null) mutableMap[contactKey] = Packet(
|
||||||
|
0L, 1, contactKey, 0L,
|
||||||
|
DataPacket(bytes = null, dataType = 1, time = 0L, channel = ch)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
this.contacts = mutableMap.values.sortedByDescending { it.received_time }.toTypedArray()
|
||||||
notifyDataSetChanged() // FIXME, this is super expensive and redraws all nodes
|
notifyDataSetChanged() // FIXME, this is super expensive and redraws all nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onChannelsChanged() {
|
fun onChannelsChanged() {
|
||||||
val oldBroadcast = contacts.find { it.contact_key == DataPacket.ID_BROADCAST }
|
onContactsChanged(contacts.associateBy { it.contact_key })
|
||||||
if (oldBroadcast != null) {
|
|
||||||
notifyItemChanged(contacts.indexOf(oldBroadcast))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,21 +218,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
||||||
|
|
||||||
model.contacts.observe(viewLifecycleOwner) {
|
model.contacts.observe(viewLifecycleOwner) {
|
||||||
debug("New contacts received: ${it.size}")
|
debug("New contacts received: ${it.size}")
|
||||||
fun emptyDataPacket(channel: Int = 0): DataPacket {
|
contactsAdapter.onContactsChanged(it)
|
||||||
return DataPacket(bytes = null, dataType = 1, time = 0L, channel = channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun emptyPacket(contactKey: String, channel: Int = 0): Packet {
|
|
||||||
return Packet(0L, 1, contactKey, 0L, emptyDataPacket(channel))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add empty channel placeholders
|
|
||||||
val mutableContacts = it.toMutableMap()
|
|
||||||
val all = DataPacket.ID_BROADCAST // always show Broadcast contacts, even when empty
|
|
||||||
for (ch in 0 until model.channels.value.protobuf.settingsCount)
|
|
||||||
if (it["$ch$all"] == null) mutableContacts["$ch$all"] = emptyPacket("$ch$all", ch)
|
|
||||||
|
|
||||||
contactsAdapter.onContactsChanged(mutableContacts.values)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue