Fix city selection vs dashboard; Map/Manage updates; workspace and API logging

Made-with: Cursor
This commit is contained in:
2026-04-06 23:49:35 +02:00
parent 34ad7e4af7
commit 0a79ee5e04
7 changed files with 50 additions and 19 deletions

View File

@@ -79,7 +79,12 @@ class CityViewModel @Inject constructor(
private fun selectCity(city: org.db3.airmq.sdk.city.domain.City) {
viewModelScope.launch(Dispatchers.IO) {
cityService.setSelectedCity(city.id)
_actions.tryEmit(CityScreenContract.Action.NavigateBack)
.onSuccess { _actions.tryEmit(CityScreenContract.Action.NavigateBack) }
.onFailure {
_actions.tryEmit(
CityScreenContract.Action.ShowToast(appContext.getString(R.string.toast_error))
)
}
}
}
@@ -93,8 +98,8 @@ class CityViewModel @Inject constructor(
private fun enableDetectAutomaticallyWithLocation(location: Location?) {
viewModelScope.launch(Dispatchers.IO) {
if (location != null) {
cityService.refreshCityFromLocation(location)
cityService.setDetectAutomatically(true)
cityService.refreshCityFromLocation(location)
val selectedCity = cityService.getSelectedCity()
_uiState.value = _uiState.value.copy(
detectAutomatically = true,

View File

@@ -1,5 +1,6 @@
package org.db3.airmq.features.manage
import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
@@ -67,6 +68,7 @@ fun ManageScreen(
viewModel: ManageViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()
Log.d("MANAGE_DEBUG", uiState.toString())
val lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifecycleOwner, viewModel) {
val observer = LifecycleEventObserver { _, event ->

View File

@@ -301,21 +301,28 @@ private fun AirMQMap(
}
}
// Overlay rebuild must be keyed off composable inputs: AndroidView's `update` runs without
// recording snapshot reads when values are only read inside View.post {}, so map items can
// load without a rebuild until something else (e.g. pan → debounced rebuild) retriggers it.
LaunchedEffect(items, centerOnMarker, clusterEnabled) {
val snapshotItems = items
val snapshotCenter = centerOnMarker
val snapshotCluster = clusterEnabled
mapView.post {
rebuildAirMqMapOverlays(
map = mapView,
items = snapshotItems,
onMarkerClick = latestOnMarkerClick.value,
clusterEnabled = snapshotCluster,
centerOnMarker = snapshotCenter,
initialCameraDone = initialCameraDone
)
}
}
AndroidView(
modifier = modifier.fillMaxSize(),
factory = { mapView },
update = { map ->
map.post {
rebuildAirMqMapOverlays(
map = map,
items = latestItems.value,
onMarkerClick = latestOnMarkerClick.value,
clusterEnabled = latestClusterEnabled.value,
centerOnMarker = latestCenterOnMarker.value,
initialCameraDone = initialCameraDone
)
}
}
factory = { mapView }
)
}