From 97c6d609acca7a46694ffbc6a76beae0bd247259 Mon Sep 17 00:00:00 2001 From: QIU Date: Mon, 3 Aug 2026 12:24:07 +0000 Subject: [PATCH] fix(roaming): drop auto GPS polling, show station position directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts the auto-update machinery after review — the page now simply mirrors the station position (站位) from the shared settingsRepo.stationPosition StateFlow, exactly what the Settings page shows: - RoamingScreen: removed the LocationManager listeners, the 30s re-request loop, the provider filter and the location-disabled hint. No polling, no auto-updates; coordinates are whatever the station GPS says. - Settings: removed the '漫游位置实时更新' toggle (stateOfRoamingLive, key, action, strings en/zh/tr) that caused the 'Other' card to overflow — the sixth unlabeled switch clipped past the card's rounded bottom edge was that row overflowing a fixed-height card. Card height back to 268.dp, five rows fit again. Verified: core:domain tests, roaming/settings/app compile clean; zero references to RoamingLive remain. --- .../core/data/repository/SettingsRepo.kt | 3 - .../look4sat/core/domain/model/Settings.kt | 1 - .../src/main/res/values-tr/strings.xml | 1 - .../src/main/res/values-zh/strings.xml | 1 - .../src/main/res/values/strings.xml | 1 - .../look4sat/feature/roaming/RoamingScreen.kt | 117 ++---------------- .../feature/settings/SettingsScreen.kt | 5 +- .../feature/settings/SettingsState.kt | 1 - .../feature/settings/SettingsViewModel.kt | 1 - 9 files changed, 10 insertions(+), 121 deletions(-) diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt index f1dd7e9d..815fb997 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt @@ -76,7 +76,6 @@ class SettingsRepo( private val keyStateOfUtc = "stateOfUtc" private val keyStateOfLightTheme = "stateOfLightTheme" private val keyStateOfNightMode = "stateOfNightMode" - private val keyStateOfRoamingLive = "stateOfRoamingLive" private val keyStationAltitude = "stationAltitude" private val keyStationLatitude = "stationLatitude" private val keyStationLongitude = "stationLongitude" @@ -352,7 +351,6 @@ class SettingsRepo( putBoolean(keyStateOfUtc, new.stateOfUtc) putBoolean(keyStateOfLightTheme, new.stateOfLightTheme) putBoolean(keyStateOfNightMode, new.stateOfNightMode) - putBoolean(keyStateOfRoamingLive, new.stateOfRoamingLive) putBoolean(keyShouldSeeWarning, new.shouldSeeWarning) putBoolean(keyShouldSeeWhatsNew, new.shouldSeeWhatsNew) putString(keySstvMode, new.sstvMode) @@ -370,7 +368,6 @@ class SettingsRepo( stateOfUtc = preferences.getBoolean(keyStateOfUtc, false), stateOfLightTheme = preferences.getBoolean(keyStateOfLightTheme, false), stateOfNightMode = preferences.getBoolean(keyStateOfNightMode, false), - stateOfRoamingLive = preferences.getBoolean(keyStateOfRoamingLive, true), shouldSeeWarning = preferences.getBoolean(keyShouldSeeWarning, true), shouldSeeWhatsNew = preferences.getBoolean(keyShouldSeeWhatsNew, true), sstvMode = preferences.getString(keySstvMode, null) ?: "Auto", diff --git a/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/model/Settings.kt b/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/model/Settings.kt index 610d8b11..ef830eb4 100644 --- a/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/model/Settings.kt +++ b/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/model/Settings.kt @@ -58,7 +58,6 @@ data class OtherSettings( val stateOfUtc: Boolean, val stateOfLightTheme: Boolean, val stateOfNightMode: Boolean = false, - val stateOfRoamingLive: Boolean = true, val shouldSeeWarning: Boolean, val shouldSeeWhatsNew: Boolean, val sstvMode: String = "Auto", diff --git a/core/presentation/src/main/res/values-tr/strings.xml b/core/presentation/src/main/res/values-tr/strings.xml index 775b4b41..a9ff9f22 100644 --- a/core/presentation/src/main/res/values-tr/strings.xml +++ b/core/presentation/src/main/res/values-tr/strings.xml @@ -186,7 +186,6 @@ Radar taramasını etkinleştir Radar görünümünü döndürmek için sensörleri kullan Kırmızı gece filtresini etkinleştir - Roaming konumunu canlı güncelle Elevasyon vurgusu Düşük < %1$d° diff --git a/core/presentation/src/main/res/values-zh/strings.xml b/core/presentation/src/main/res/values-zh/strings.xml index fab23541..743200fd 100644 --- a/core/presentation/src/main/res/values-zh/strings.xml +++ b/core/presentation/src/main/res/values-zh/strings.xml @@ -162,7 +162,6 @@ 启用雷达扫描动画 使用传感器旋转雷达视图 启用红色夜间模式 - 漫游位置实时更新 仰角高亮 低 < %1$d° diff --git a/core/presentation/src/main/res/values/strings.xml b/core/presentation/src/main/res/values/strings.xml index 01ef7861..ca7ae6a0 100644 --- a/core/presentation/src/main/res/values/strings.xml +++ b/core/presentation/src/main/res/values/strings.xml @@ -197,7 +197,6 @@ Enable radar sweep animation Use sensors to rotate radar view Enable red night mode filter - Update Roaming position live Elevation highlight Low < %1$d° diff --git a/feature/roaming/src/main/java/com/rtbishop/look4sat/feature/roaming/RoamingScreen.kt b/feature/roaming/src/main/java/com/rtbishop/look4sat/feature/roaming/RoamingScreen.kt index 92fea02e..f433b756 100644 --- a/feature/roaming/src/main/java/com/rtbishop/look4sat/feature/roaming/RoamingScreen.kt +++ b/feature/roaming/src/main/java/com/rtbishop/look4sat/feature/roaming/RoamingScreen.kt @@ -17,18 +17,7 @@ */ package com.rtbishop.look4sat.feature.roaming -import android.Manifest -import android.annotation.SuppressLint -import android.content.Intent -import android.content.pm.PackageManager -import android.location.Location -import android.location.LocationListener -import android.location.LocationManager -import android.os.Bundle -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.background -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints @@ -47,12 +36,8 @@ import androidx.compose.material3.ElevatedCard import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -63,12 +48,8 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import androidx.core.content.ContextCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.rtbishop.look4sat.core.domain.repository.IContainerProvider -import com.rtbishop.look4sat.core.domain.utility.positionToQth -import com.rtbishop.look4sat.core.domain.utility.qthNeighbors -import com.rtbishop.look4sat.core.domain.utility.qthToSquare import com.rtbishop.look4sat.core.presentation.LocalSpacing import com.rtbishop.look4sat.core.presentation.ScreenColumn import com.rtbishop.look4sat.core.presentation.TopBar @@ -83,78 +64,21 @@ import java.util.Locale * and row are wider/taller, matching the reference app). Styled with the * Look4Sat Material 3 theme. * - * Live GPS: while the screen is shown (and the "漫游位置实时更新" setting is on) - * a LocationManager listener requests gps+network fixes every 10s / 10m, - * exactly like the reference app; each fix is pushed through the shared - * settingsRepo.stationPosition StateFlow, so the Settings page and every - * other consumer update in lockstep. The red marker is placed at the - * fractional position derived from the 3rd character pair of the locator - * (ported from the QTH定位器 app), scaled to the actual cell size, so it - * stays accurate on any screen (phones, tablets, wide/narrow). + * Coordinates are read straight from the shared settingsRepo.stationPosition + * StateFlow — the same source the Settings page uses — so the page shows + * exactly the station position (站位), whatever the GPS says there. No + * automatic location polling on this page. */ -@SuppressLint("MissingPermission") @Composable fun RoamingScreen() { val context = LocalContext.current val container = (context.applicationContext as IContainerProvider).getMainContainer() - val settingsRepo = container.settingsRepo - val stationPos by settingsRepo.stationPosition.collectAsStateWithLifecycle() - val otherSettings by settingsRepo.otherSettings.collectAsStateWithLifecycle() + val stationPos by container.settingsRepo.stationPosition.collectAsStateWithLifecycle() - val state = remember(stationPos, otherSettings.stateOfRoamingLive) { + val state = remember(stationPos) { RoamingState.fromPosition(stationPos) } - // Real-time location updates, ported from the reference app's onResume/onPause: - // register gps+network listeners while visible, remove them when leaving. - var gpsAvailable by remember { mutableStateOf(false) } - DisposableEffect(Unit) { - val locationManager = context.getSystemService(LocationManager::class.java) - val hasPermission = ContextCompat.checkSelfPermission( - context, Manifest.permission.ACCESS_FINE_LOCATION - ) == PackageManager.PERMISSION_GRANTED - gpsAvailable = hasPermission && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) - val listener = object : LocationListener { - override fun onLocationChanged(location: Location) { - // Accept only real gps/network fixes, like the reference app - if (location.provider != LocationManager.GPS_PROVIDER && - location.provider != LocationManager.NETWORK_PROVIDER - ) return - settingsRepo.setStationPosition(location.latitude, location.longitude, location.altitude) - } - - override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) = Unit - override fun onProviderEnabled(provider: String) { - if (provider == LocationManager.GPS_PROVIDER) gpsAvailable = true - } - - override fun onProviderDisabled(provider: String) { - if (provider == LocationManager.GPS_PROVIDER) gpsAvailable = false - } - } - if (hasPermission) { - // Listen continuously while the page is visible (10s / 10m, like the reference) - locationManager.requestLocationUpdates( - LocationManager.GPS_PROVIDER, 10_000L, 10f, listener - ) - locationManager.requestLocationUpdates( - LocationManager.NETWORK_PROVIDER, 10_000L, 10f, listener - ) - } - onDispose { - if (hasPermission) locationManager.removeUpdates(listener) - } - } - - // Periodic refresh when live updates are enabled: re-request a fix every 30s - // so the page also recovers after the GPS chip falls idle. - LaunchedEffect(otherSettings.stateOfRoamingLive) { - while (otherSettings.stateOfRoamingLive) { - settingsRepo.setStationPosition() - kotlinx.coroutines.delay(30_000L) - } - } - ScreenColumn( topBar = { TopBar { Text(text = "漫游", fontSize = 20.sp, fontWeight = FontWeight.Bold) } @@ -165,16 +89,15 @@ fun RoamingScreen() { modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(spacing.medium) ) { - InfoCard(state = state, gpsAvailable = gpsAvailable) + InfoCard(state = state) GridCard(state = state, modifier = Modifier.weight(1f)) } } } @Composable -private fun InfoCard(state: RoamingState, gpsAvailable: Boolean) { +private fun InfoCard(state: RoamingState) { val colorScheme = MaterialTheme.colorScheme - val context = LocalContext.current ElevatedCard(modifier = Modifier.fillMaxWidth()) { Column( modifier = Modifier @@ -195,13 +118,7 @@ private fun InfoCard(state: RoamingState, gpsAvailable: Boolean) { modifier = Modifier .size(10.dp) .clip(CircleShape) - .background( - when { - state.gpsEnabled -> colorScheme.primary - gpsAvailable -> colorScheme.error - else -> colorScheme.outline - } - ) + .background(if (state.gpsEnabled) colorScheme.primary else colorScheme.outline) ) Spacer(modifier = Modifier.weight(1f)) Text( @@ -217,22 +134,6 @@ private fun InfoCard(state: RoamingState, gpsAvailable: Boolean) { color = colorScheme.onSurface ) } - // GPS disabled hint, ported from the reference app's btnLocationSettings: - // opens the system location settings so the user can re-enable GPS. - if (!gpsAvailable) { - Text( - text = "定位未开启,点击前往系统设置", - fontSize = 13.sp, - color = colorScheme.error, - modifier = Modifier - .fillMaxWidth() - .clip(MaterialTheme.shapes.small) - .clickable { - context.startActivity(Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) - } - .padding(vertical = 6.dp) - ) - } // Coordinates: DMS + decimal CoordinateRow(label = "纬度", value = state.latitude, isLat = true) CoordinateRow(label = "经度", value = state.longitude, isLat = false) diff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsScreen.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsScreen.kt index af632496..cabcad4d 100644 --- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsScreen.kt +++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsScreen.kt @@ -488,7 +488,7 @@ private fun OtherCard(settings: OtherSettings, onAction: (SettingsAction) -> Uni ElevatedCard( modifier = Modifier .fillMaxWidth() - .height(296.dp) + .height(268.dp) ) { Column( modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), @@ -513,9 +513,6 @@ private fun OtherCard(settings: OtherSettings, onAction: (SettingsAction) -> Uni SwitchRow(R.string.prefs_other_switch_night_mode, settings.stateOfNightMode) { onAction(SettingsAction.ToggleNightMode(it)) } - SwitchRow(R.string.prefs_other_switch_roaming_live, settings.stateOfRoamingLive) { - onAction(SettingsAction.ToggleRoamingLive(it)) - } } } } diff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsState.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsState.kt index 4b7e667f..928cf60b 100644 --- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsState.kt +++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsState.kt @@ -64,7 +64,6 @@ sealed interface SettingsAction { data class ToggleSensor(val value: Boolean) : SettingsAction data class ToggleLightTheme(val value: Boolean) : SettingsAction data class ToggleNightMode(val value: Boolean) : SettingsAction - data class ToggleRoamingLive(val value: Boolean) : SettingsAction // Remote control data class UpdateRC(val settings: RCSettings) : SettingsAction diff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsViewModel.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsViewModel.kt index fc646d14..f43e91f6 100644 --- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsViewModel.kt +++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsViewModel.kt @@ -121,7 +121,6 @@ class SettingsViewModel( is SettingsAction.ToggleSensor -> settingsRepo.updateOtherSettings { it.copy(stateOfSensors = action.value) } is SettingsAction.ToggleLightTheme -> settingsRepo.updateOtherSettings { it.copy(stateOfLightTheme = action.value) } is SettingsAction.ToggleNightMode -> settingsRepo.updateOtherSettings { it.copy(stateOfNightMode = action.value) } - is SettingsAction.ToggleRoamingLive -> settingsRepo.updateOtherSettings { it.copy(stateOfRoamingLive = action.value) } // Remote control & data sources is SettingsAction.UpdateRC -> settingsRepo.updateRCSettings(action.settings) is SettingsAction.UpdateRadioControl -> settingsRepo.updateRadioControlSettings(action.settings)