fix: recalculate radar track when station position changes

The station position (stationPos) was captured once at ViewModel construction
and never updated when the user clicked on the map or changed the QTH grid.
This caused the radar track line to simply translate instead of being
recalculated from the new position.

Fix:
- Change stationPos and magDeclination from val to var
- Add collectStationPositionChanges() that observes settingsRepo.stationPosition
- On position change: update stationPos, magDeclination, force celestial
  recompute, and recalculate the satellite track
This commit is contained in:
atsunatsu committed 2026-08-06 09:41:46 +08:00
1 parent 602b1553a2
commit 6e95f111fe
1 file changed
+20 -2
@@ -65,8 +65,8 @@ class RadarViewModel(
private val showToast: IShowToast
) : ViewModel() {
private val stationPos = settingsRepo.stationPosition.value
private val magDeclination = sensorsRepo.getMagDeclination(stationPos)
private var stationPos = settingsRepo.stationPosition.value
private var magDeclination = sensorsRepo.getMagDeclination(stationPos)
private var compassOffset = settingsRepo.otherSettings.value.radarCompassOffset
private var compassOffsetElev = settingsRepo.otherSettings.value.radarCompassOffsetElev
private var transponders: List<SatRadio> = emptyList()
@@ -92,6 +92,7 @@ class RadarViewModel(
init {
collectSettingsChanges() // also handles initial sensor subscription
collectStationPositionChanges()
collectPassAndStartTickLoop()
collectRadioTrackingState()
}
@@ -138,6 +139,23 @@ class RadarViewModel(
}
}
private fun collectStationPositionChanges() {
viewModelScope.launch {
settingsRepo.stationPosition.collect { newPos ->
if (stationPos != newPos) {
stationPos = newPos
magDeclination = sensorsRepo.getMagDeclination(stationPos)
lastCelestialUpdateMs = 0L // force celestial recompute on next tick
val pass = _uiState.value.currentPass ?: return@collect
if (!pass.isDeepSpace) {
val track = satelliteRepo.getTrack(pass.orbitalObject, stationPos, pass.aosTime, pass.losTime)
_uiState.update { it.copy(satTrack = track) }
}
}
}
}
}
// --- Pass loading split into focused functions ---
private fun collectPassAndStartTickLoop() {