feat: show online and total node count in the title bar (#2209)

pull/2211/head
James Rich 2025-06-22 02:10:36 +00:00 zatwierdzone przez GitHub
rodzic 450014a0f6
commit c4c115b901
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 27 dodań i 1 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ import com.geeksville.mesh.database.entity.NodeEntity
import com.geeksville.mesh.model.Node
import com.geeksville.mesh.model.NodeSortOption
import com.geeksville.mesh.util.onlineTimeThreshold
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
@ -133,4 +134,12 @@ class NodeRepository @Inject constructor(
suspend fun insertMetadata(metadata: MetadataEntity) = withContext(dispatchers.io) {
nodeInfoDao.upsert(metadata)
}
val onlineNodeCount: Flow<Int> = nodeInfoDao.nodeDBbyNum().mapLatest { map ->
map.values.count { it.node.lastHeard > onlineTimeThreshold() }
}.flowOn(dispatchers.io).conflate()
val totalNodeCount: Flow<Int> = nodeInfoDao.nodeDBbyNum().mapLatest { map ->
map.values.count()
}.flowOn(dispatchers.io).conflate()
}

Wyświetl plik

@ -403,6 +403,18 @@ class UIViewModel @Inject constructor(
initialValue = emptyList(),
)
val onlineNodeCount = nodeDB.onlineNodeCount.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = 0,
)
val totalNodeCount = nodeDB.totalNodeCount.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = 0,
)
val filteredNodeList: StateFlow<List<Node>> = nodeList.mapLatest { list ->
list.filter { node ->
!node.isIgnored

Wyświetl plik

@ -376,10 +376,15 @@ private fun MainAppBar(
return
}
val title by viewModel.title.collectAsStateWithLifecycle("")
val onlineNodeCount by viewModel.onlineNodeCount.collectAsStateWithLifecycle(0)
val totalNodeCount by viewModel.totalNodeCount.collectAsStateWithLifecycle(0)
TopAppBar(
title = {
val title = when {
currentDestination == null || isTopLevelRoute -> stringResource(id = R.string.app_name)
currentDestination == null -> stringResource(id = R.string.app_name)
currentDestination.hasRoute<NodesRoutes.Nodes>() -> stringResource(id = R.string.app_name) +
" ($onlineNodeCount/$totalNodeCount)"
currentDestination.hasRoute<Route.DebugPanel>() -> stringResource(id = R.string.debug_panel)