mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: getContacts() DAO using Map return type
This commit is contained in:
parent
84a8162f5f
commit
1c5e2dbefc
4 changed files with 15 additions and 13 deletions
|
|
@ -198,9 +198,14 @@ class UIViewModel @Inject constructor(
|
|||
}.asLiveData()
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
val contacts: LiveData<Map<String, Packet>> = _packets.mapLatest { list ->
|
||||
list.filter { it.port_num == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE }
|
||||
.associateBy { packet -> packet.contact_key }
|
||||
val contacts: LiveData<Map<String, Packet>> = packetRepository.getContacts().mapLatest {
|
||||
// Add empty channel placeholders (always show Broadcast contacts, even when empty)
|
||||
val placeholder = (0 until channelSet.settingsCount).associate { ch ->
|
||||
val contactKey = "$ch${DataPacket.ID_BROADCAST}"
|
||||
val data = DataPacket(bytes = null, dataType = 1, time = 0L, channel = ch)
|
||||
contactKey to Packet(0L, 1, contactKey, 0L, data)
|
||||
}
|
||||
it + (placeholder - it.keys)
|
||||
}.asLiveData()
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue