Decouple MapView from UiViewModel (#3213)

This commit is contained in:
Phil Oliver 2025-09-26 16:34:36 -04:00 committed by GitHub
parent 3d94391bb1
commit af8e1daa5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 102 additions and 86 deletions

View file

@ -386,32 +386,6 @@ constructor(
initialValue = emptyList(),
)
fun generatePacketId(): Int? {
return try {
meshService?.packetId
} catch (ex: RemoteException) {
errormsg("RemoteException: ${ex.message}")
return null
}
}
fun sendWaypoint(wpt: MeshProtos.Waypoint, contactKey: String = "0${DataPacket.ID_BROADCAST}") {
// contactKey: unique contact key filter (channel)+(nodeId)
val channel = contactKey[0].digitToIntOrNull()
val dest = if (channel != null) contactKey.substring(1) else contactKey
val p = DataPacket(dest, channel ?: 0, wpt)
if (wpt.id != 0) sendDataPacket(p)
}
private fun sendDataPacket(p: DataPacket) {
try {
meshService?.send(p)
} catch (ex: RemoteException) {
errormsg("Send DataPacket error: ${ex.message}")
}
}
private val _sharedContactRequested: MutableStateFlow<AdminProtos.SharedContact?> = MutableStateFlow(null)
val sharedContactRequested: StateFlow<AdminProtos.SharedContact?>
get() = _sharedContactRequested.asStateFlow()
@ -426,8 +400,6 @@ constructor(
fun deleteContacts(contacts: List<String>) =
viewModelScope.launch(Dispatchers.IO) { packetRepository.deleteContacts(contacts) }
fun deleteWaypoint(id: Int) = viewModelScope.launch(Dispatchers.IO) { packetRepository.deleteWaypoint(id) }
// Connection state to our radio device
val connectionState
get() = serviceRepository.connectionState
@ -470,9 +442,6 @@ constructor(
val isManaged: Boolean
get() = config.device.isManaged || config.security.isManaged
val myNodeNum
get() = myNodeInfo.value?.myNodeNum
override fun onCleared() {
super.onCleared()
debug("ViewModel cleared")