mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor(NodeItem): replace NodeInfo with NodeEntity
This commit is contained in:
parent
89a3171b58
commit
83dc389d6d
12 changed files with 373 additions and 160 deletions
|
|
@ -3,10 +3,8 @@ package com.geeksville.mesh.model
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.database.dao.NodeInfoDao
|
||||
import com.geeksville.mesh.database.entity.NodeEntity
|
||||
import com.geeksville.mesh.database.entity.toNodeInfo
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
|
@ -26,8 +24,8 @@ class NodeDB @Inject constructor(
|
|||
val myNodeInfo: StateFlow<MyNodeInfo?> get() = _myNodeInfo
|
||||
|
||||
// our node info
|
||||
private val _ourNodeInfo = MutableStateFlow<NodeInfo?>(null)
|
||||
val ourNodeInfo: StateFlow<NodeInfo?> get() = _ourNodeInfo
|
||||
private val _ourNodeInfo = MutableStateFlow<NodeEntity?>(null)
|
||||
val ourNodeInfo: StateFlow<NodeEntity?> get() = _ourNodeInfo
|
||||
|
||||
// The unique userId of our node
|
||||
private val _myId = MutableStateFlow<String?>(null)
|
||||
|
|
@ -47,7 +45,7 @@ class NodeDB @Inject constructor(
|
|||
|
||||
nodeInfoDao.nodeDBbyNum().onEach {
|
||||
_nodeDBbyNum.value = it
|
||||
val ourNodeInfo = it.values.firstOrNull()?.toNodeInfo()
|
||||
val ourNodeInfo = it.values.firstOrNull()
|
||||
_ourNodeInfo.value = ourNodeInfo
|
||||
_myId.value = ourNodeInfo?.user?.id
|
||||
}.launchIn(processLifecycle.coroutineScope)
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ class UIViewModel @Inject constructor(
|
|||
|
||||
// hardware info about our local device (can be null)
|
||||
val myNodeInfo: StateFlow<MyNodeInfo?> get() = nodeDB.myNodeInfo
|
||||
val ourNodeInfo: StateFlow<NodeInfo?> get() = nodeDB.ourNodeInfo
|
||||
val ourNodeInfo: StateFlow<NodeEntity?> get() = nodeDB.ourNodeInfo
|
||||
|
||||
// FIXME only used in MapFragment
|
||||
val initialNodes get() = nodeDB.nodeDBbyNum.value.values.map { it.toNodeInfo() }
|
||||
|
|
@ -545,10 +545,15 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun setOwner(user: MeshUser) {
|
||||
fun setOwner(name: String) {
|
||||
val user = ourNodeInfo.value?.user?.copy {
|
||||
longName = name
|
||||
shortName = getInitials(name)
|
||||
} ?: return
|
||||
|
||||
try {
|
||||
// Note: we use ?. here because we might be running in the emulator
|
||||
meshService?.setOwner(user)
|
||||
meshService?.setRemoteOwner(myNodeNum ?: return, user.toByteArray())
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Can't set username on device, is device offline? ${ex.message}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue