mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
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:
1 parent
602b1553a2
commit
6e95f111fe
1 file changed
+20
-2
@@ -65,8 +65,8 @@ class RadarViewModel(
|
|||||||
private val showToast: IShowToast
|
private val showToast: IShowToast
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val stationPos = settingsRepo.stationPosition.value
|
private var stationPos = settingsRepo.stationPosition.value
|
||||||
private val magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
private var magDeclination = sensorsRepo.getMagDeclination(stationPos)
|
||||||
private var compassOffset = settingsRepo.otherSettings.value.radarCompassOffset
|
private var compassOffset = settingsRepo.otherSettings.value.radarCompassOffset
|
||||||
private var compassOffsetElev = settingsRepo.otherSettings.value.radarCompassOffsetElev
|
private var compassOffsetElev = settingsRepo.otherSettings.value.radarCompassOffsetElev
|
||||||
private var transponders: List<SatRadio> = emptyList()
|
private var transponders: List<SatRadio> = emptyList()
|
||||||
@@ -92,6 +92,7 @@ class RadarViewModel(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
collectSettingsChanges() // also handles initial sensor subscription
|
collectSettingsChanges() // also handles initial sensor subscription
|
||||||
|
collectStationPositionChanges()
|
||||||
collectPassAndStartTickLoop()
|
collectPassAndStartTickLoop()
|
||||||
collectRadioTrackingState()
|
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 ---
|
// --- Pass loading split into focused functions ---
|
||||||
|
|
||||||
private fun collectPassAndStartTickLoop() {
|
private fun collectPassAndStartTickLoop() {
|
||||||
|
|||||||
Reference in new issue
Block a user