From 6e95f111fe244ef3a5d369faced582cdda584480 Mon Sep 17 00:00:00 2001 From: atsunatsu Date: Thu, 6 Aug 2026 09:41:46 +0800 Subject: [PATCH] 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 --- .../look4sat/feature/radar/RadarViewModel.kt | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt b/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt index be89d4b6..6ddd57d2 100644 --- a/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt +++ b/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt @@ -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 = 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() {