mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: enhance map navigation and waypoint handling (#4814)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
802aa09aab
commit
5edb8abd05
15 changed files with 95 additions and 16 deletions
|
|
@ -35,6 +35,7 @@ fun MapScreen(
|
|||
navigateToNodeDetails: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
viewModel: SharedMapViewModel,
|
||||
waypointId: Int? = null,
|
||||
) {
|
||||
val ourNodeInfo by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
|
||||
val isConnected by viewModel.isConnected.collectAsStateWithLifecycle()
|
||||
|
|
@ -58,6 +59,7 @@ fun MapScreen(
|
|||
modifier = Modifier.fillMaxSize().padding(paddingValues),
|
||||
viewModel = viewModel,
|
||||
navigateToNodeDetails = navigateToNodeDetails,
|
||||
waypointId = waypointId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ package org.meshtastic.feature.map.node
|
|||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
|
@ -44,11 +46,19 @@ class NodeMapViewModel(
|
|||
buildConfigProvider: BuildConfigProvider,
|
||||
private val mapPrefs: MapPrefs,
|
||||
) : ViewModel() {
|
||||
private val destNum = savedStateHandle.get<Int>("destNum") ?: 0
|
||||
private val destNumFromRoute = savedStateHandle.get<Int>("destNum")
|
||||
private val manualDestNum = MutableStateFlow<Int?>(null)
|
||||
|
||||
private val destNumFlow =
|
||||
combine(MutableStateFlow(destNumFromRoute), manualDestNum) { route, manual -> manual ?: route ?: 0 }
|
||||
|
||||
fun setDestNum(num: Int) {
|
||||
manualDestNum.value = num
|
||||
}
|
||||
|
||||
val node =
|
||||
nodeRepository.nodeDBbyNum
|
||||
.mapLatest { it[destNum] }
|
||||
destNumFlow
|
||||
.flatMapLatest { destNum -> nodeRepository.nodeDBbyNum.mapLatest { it[destNum] } }
|
||||
.distinctUntilChanged()
|
||||
.stateInWhileSubscribed(initialValue = null)
|
||||
|
||||
|
|
@ -57,8 +67,9 @@ class NodeMapViewModel(
|
|||
private val ourNodeNumFlow = nodeRepository.myNodeInfo.map { it?.myNodeNum }.distinctUntilChanged()
|
||||
|
||||
val positionLogs: StateFlow<List<Position>> =
|
||||
ourNodeNumFlow
|
||||
.map { if (destNum == it) MeshLog.NODE_NUM_LOCAL else destNum }
|
||||
combine(ourNodeNumFlow, destNumFlow) { ourNodeNum, destNum ->
|
||||
if (destNum == ourNodeNum) MeshLog.NODE_NUM_LOCAL else destNum
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.flatMapLatest { logId ->
|
||||
meshLogRepository.getMeshPacketsFrom(logId, PortNum.POSITION_APP.value).map { packets ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue