mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
fix: sync dialogs use typed values directly (save+sync in one step); LoTW card wording; center map on station grid when entering grid mode; center grid labels in cells; update-check falls back to GitHub accelerator mirrors
This commit is contained in:
1 parent
be6473e692
commit
c7ca77a943
10 files changed
+113
-43
No files matched your search
+13
-8
@@ -124,8 +124,8 @@ class MaidenheadGridOverlay : Overlay() {
|
||||
canvas.drawLine(0f, y, canvas.width.toFloat(), y, linePaint)
|
||||
}
|
||||
|
||||
// Labels: place at the top-left corner of each cell, only when the cell
|
||||
// is large enough on screen to hold a label (avoid clutter at low zoom)
|
||||
// Labels: centered in each cell, only when the cell is large enough on
|
||||
// screen to hold a label (avoid clutter at low zoom)
|
||||
val showLabels = when {
|
||||
zoom >= GRID_ZOOM_SUB -> true
|
||||
zoom >= FIELD_ZOOM_LABELS -> true
|
||||
@@ -140,20 +140,25 @@ class MaidenheadGridOverlay : Overlay() {
|
||||
val pixelsPerDegree = Math.abs(y2 - y1)
|
||||
if (pixelsPerDegree * cellLat < MIN_LABEL_CELL_PX) return
|
||||
|
||||
val labelOffset = 8f
|
||||
labelPaint.textAlign = Paint.Align.CENTER
|
||||
val fontMetrics = labelPaint.fontMetrics
|
||||
val textHalfHeight = (fontMetrics.descent + fontMetrics.ascent) / 2f
|
||||
for (row in firstRow..lastRow) {
|
||||
val lat = row * cellLat
|
||||
if (lat < -90.0 || lat >= 90.0) continue
|
||||
val topLatCell = lat + cellLat
|
||||
if (topLatCell > 90.0) continue
|
||||
val y = projectionToY(projection, topLatCell) ?: continue
|
||||
if (y < -labelPaint.textSize || y > canvas.height) continue
|
||||
val yTop = projectionToY(projection, topLatCell) ?: continue
|
||||
val yBottom = projectionToY(projection, lat) ?: continue
|
||||
val yCenter = (yTop + yBottom) / 2f - textHalfHeight
|
||||
if (yBottom < 0f || yTop > canvas.height) continue
|
||||
for (col in firstCol..lastCol) {
|
||||
val lon = col * cellLon
|
||||
val x = projectionToX(projection, lon, centerLon) ?: continue
|
||||
if (x < -200f || x > canvas.width) continue
|
||||
val xLeft = projectionToX(projection, lon, centerLon) ?: continue
|
||||
val xRight = projectionToX(projection, lon + cellLon, centerLon) ?: continue
|
||||
if (xRight < 0f || xLeft > canvas.width) continue
|
||||
val label = cellLabel(lat, lon, zoom)
|
||||
canvas.drawText(label, x + labelOffset, y + labelPaint.textSize + labelOffset, labelPaint)
|
||||
canvas.drawText(label, (xLeft + xRight) / 2f, yCenter, labelPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ 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.rotate
|
||||
@@ -159,8 +161,15 @@ private fun MapScreen(uiState: MapState, onAction: (MapAction) -> Unit, mapView:
|
||||
}
|
||||
ElevatedCard(modifier = Modifier.weight(1f)) {
|
||||
Box(contentAlignment = Alignment.BottomCenter) {
|
||||
// Track grid-mode transitions so the map only re-centers when the
|
||||
// mode is switched ON, not on every recomposition.
|
||||
var prevGridMode by remember { mutableStateOf(uiState.isGridMode) }
|
||||
AndroidView({ mapView }) { view ->
|
||||
setGridMode(uiState.isGridMode, uiState.workedGrids, view)
|
||||
setGridMode(
|
||||
uiState.isGridMode, uiState.workedGrids, view,
|
||||
if (uiState.isGridMode && !prevGridMode) uiState.stationPosition else null
|
||||
)
|
||||
prevGridMode = uiState.isGridMode
|
||||
if (!uiState.isGridMode) {
|
||||
uiState.stationPosition?.let { setStationPosition(it, view) }
|
||||
uiState.track?.let { setSatelliteTrack(it, view) }
|
||||
@@ -269,7 +278,12 @@ private fun MapDataCards(data: MapData) {
|
||||
// region Map overlay helpers
|
||||
|
||||
/** Toggle the grid-mode layer visibility on/off without recreating any overlay. */
|
||||
private fun setGridMode(gridMode: Boolean, workedGrids: Set<String>, mapView: MapView) {
|
||||
private fun setGridMode(
|
||||
gridMode: Boolean,
|
||||
workedGrids: Set<String>,
|
||||
mapView: MapView,
|
||||
stationPosition: GeoPos?
|
||||
) {
|
||||
try {
|
||||
val gridOverlay = mapView.overlays[OVERLAY_GRID]
|
||||
if (gridOverlay is MaidenheadGridOverlay) {
|
||||
@@ -286,6 +300,18 @@ private fun setGridMode(gridMode: Boolean, workedGrids: Set<String>, mapView: Ma
|
||||
for (index in OVERLAY_STATION..OVERLAY_MOON) {
|
||||
mapView.overlays.getOrNull(index)?.isEnabled = !gridMode
|
||||
}
|
||||
// Entering grid mode: center on the station's current grid square,
|
||||
// keeping the current zoom level unchanged.
|
||||
if (gridMode) {
|
||||
val pos = stationPosition ?: return
|
||||
val lat = pos.latitude
|
||||
val lon = pos.longitude
|
||||
val fieldLat = ((lat + 90.0) / 10.0).toInt().coerceIn(0, 17)
|
||||
val fieldLon = ((lon + 180.0) / 20.0).toInt().coerceIn(0, 17)
|
||||
val centerLat = fieldLat * 10.0 + 5.0
|
||||
val centerLon = fieldLon * 20.0 + 10.0
|
||||
mapView.controller.setCenter(GeoPoint(centerLat, centerLon))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println(e)
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ class MapViewModel(
|
||||
}
|
||||
val (selectedCatNum, _) = satelliteRepo.selectedPass.value
|
||||
selectDefaultSatellite(if (selectedCatNum != 0) selectedCatNum else -1)
|
||||
getStationPosition()
|
||||
}
|
||||
|
||||
fun onAction(action: MapAction) {
|
||||
|
||||
+14
-5
@@ -164,7 +164,7 @@ fun WavelogDialog(
|
||||
message: String?,
|
||||
dismiss: () -> Unit,
|
||||
onSave: (com.rtbishop.look4sat.core.domain.model.WavelogSettings) -> Unit,
|
||||
onSync: () -> Unit
|
||||
onSync: (com.rtbishop.look4sat.core.domain.model.WavelogSettings) -> Unit
|
||||
) {
|
||||
val url = rememberSaveable { mutableStateOf(initialSettings.url) }
|
||||
val token = rememberSaveable { mutableStateOf(initialSettings.token) }
|
||||
@@ -205,12 +205,16 @@ fun WavelogDialog(
|
||||
modifier = Modifier.padding(horizontal = LocalSpacing.current.large)
|
||||
)
|
||||
}
|
||||
// Sync button row (inside dialog content so token must be saved first)
|
||||
// Sync uses the values typed in the fields directly — saving and syncing
|
||||
// happen in one step, no need to close and reopen the dialog.
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.End,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = LocalSpacing.current.large)
|
||||
) {
|
||||
TextButton(onClick = onSync, enabled = !isSyncing) {
|
||||
TextButton(
|
||||
onClick = { onSync(com.rtbishop.look4sat.core.domain.model.WavelogSettings(url.value, token.value)) },
|
||||
enabled = !isSyncing
|
||||
) {
|
||||
Text(text = if (isSyncing) stringResource(R.string.prefs_wavelog_syncing)
|
||||
else stringResource(R.string.prefs_wavelog_sync))
|
||||
}
|
||||
@@ -227,7 +231,7 @@ fun LoTWDialog(
|
||||
message: String?,
|
||||
dismiss: () -> Unit,
|
||||
onSave: (com.rtbishop.look4sat.core.domain.model.LoTWSettings) -> Unit,
|
||||
onSync: () -> Unit
|
||||
onSync: (com.rtbishop.look4sat.core.domain.model.LoTWSettings) -> Unit
|
||||
) {
|
||||
val call = rememberSaveable { mutableStateOf(initialSettings.callsign) }
|
||||
val pass = rememberSaveable { mutableStateOf(initialSettings.password) }
|
||||
@@ -269,11 +273,16 @@ fun LoTWDialog(
|
||||
modifier = Modifier.padding(horizontal = LocalSpacing.current.large)
|
||||
)
|
||||
}
|
||||
// Sync uses the values typed in the fields directly — saving and syncing
|
||||
// happen in one step, no need to close and reopen the dialog.
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.End,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = LocalSpacing.current.large)
|
||||
) {
|
||||
TextButton(onClick = onSync, enabled = !isSyncing) {
|
||||
TextButton(
|
||||
onClick = { onSync(com.rtbishop.look4sat.core.domain.model.LoTWSettings(call.value, pass.value)) },
|
||||
enabled = !isSyncing
|
||||
) {
|
||||
Text(text = if (isSyncing) stringResource(R.string.prefs_lotw_syncing)
|
||||
else stringResource(R.string.prefs_lotw_sync))
|
||||
}
|
||||
|
||||
+3
-3
@@ -211,7 +211,7 @@ private fun SettingsScreen(uiState: SettingsState, onAction: (SettingsAction) ->
|
||||
message = uiState.wavelogMessage,
|
||||
dismiss = { dialogs.wavelog = false },
|
||||
onSave = { onAction(SettingsAction.UpdateWavelog(it)) },
|
||||
onSync = { onAction(SettingsAction.SyncWorkedGrids) }
|
||||
onSync = { onAction(SettingsAction.SyncWorkedGrids(it)) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ private fun SettingsScreen(uiState: SettingsState, onAction: (SettingsAction) ->
|
||||
message = uiState.lotwMessage,
|
||||
dismiss = { dialogs.lotw = false },
|
||||
onSave = { onAction(SettingsAction.UpdateLoTW(it)) },
|
||||
onSync = { onAction(SettingsAction.SyncLoTWGrids) }
|
||||
onSync = { onAction(SettingsAction.SyncLoTWGrids(it)) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ private fun LoTWCard(
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
Text(
|
||||
text = if (settings.isConfigured) {
|
||||
stringResource(R.string.prefs_wavelog_configured, workedGridsCount)
|
||||
stringResource(R.string.prefs_lotw_configured, workedGridsCount)
|
||||
} else {
|
||||
stringResource(R.string.prefs_lotw_not_configured)
|
||||
},
|
||||
|
||||
+2
-2
@@ -96,11 +96,11 @@ sealed interface SettingsAction {
|
||||
|
||||
// Wavelog worked grids
|
||||
data class UpdateWavelog(val settings: WavelogSettings) : SettingsAction
|
||||
data object SyncWorkedGrids : SettingsAction
|
||||
data class SyncWorkedGrids(val settings: WavelogSettings) : SettingsAction
|
||||
|
||||
// LoTW confirmed grids
|
||||
data class UpdateLoTW(val settings: com.rtbishop.look4sat.core.domain.model.LoTWSettings) : SettingsAction
|
||||
data object SyncLoTWGrids : SettingsAction
|
||||
data class SyncLoTWGrids(val settings: com.rtbishop.look4sat.core.domain.model.LoTWSettings) : SettingsAction
|
||||
|
||||
// Update checker
|
||||
data object CheckForUpdate : SettingsAction
|
||||
|
||||
+9
-6
@@ -23,6 +23,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.rtbishop.look4sat.core.domain.repository.IDatabaseRepo
|
||||
import com.rtbishop.look4sat.core.domain.model.WavelogSettings
|
||||
import com.rtbishop.look4sat.core.domain.repository.IMainContainer
|
||||
import com.rtbishop.look4sat.core.domain.repository.ISettingsRepo
|
||||
import com.rtbishop.look4sat.core.domain.repository.IUpdateRepository
|
||||
@@ -155,10 +156,10 @@ class SettingsViewModel(
|
||||
is SettingsAction.UpdateDataSources -> settingsRepo.updateDataSourcesSettings(action.settings)
|
||||
// Wavelog worked grids
|
||||
is SettingsAction.UpdateWavelog -> settingsRepo.updateWavelogSettings(action.settings)
|
||||
SettingsAction.SyncWorkedGrids -> syncWorkedGrids()
|
||||
is SettingsAction.SyncWorkedGrids -> syncWorkedGrids(action.settings)
|
||||
// LoTW confirmed grids
|
||||
is SettingsAction.UpdateLoTW -> settingsRepo.updateLoTWSettings(action.settings)
|
||||
SettingsAction.SyncLoTWGrids -> syncLoTWGrids()
|
||||
is SettingsAction.SyncLoTWGrids -> syncLoTWGrids(action.settings)
|
||||
// Update checker
|
||||
SettingsAction.CheckForUpdate -> checkForUpdate()
|
||||
SettingsAction.DownloadUpdate -> downloadUpdate()
|
||||
@@ -170,12 +171,13 @@ class SettingsViewModel(
|
||||
|
||||
// region Wavelog worked grids
|
||||
|
||||
private fun syncWorkedGrids() {
|
||||
val settings = _uiState.value.wavelogSettings
|
||||
private fun syncWorkedGrids(settings: WavelogSettings) {
|
||||
if (!settings.isConfigured) {
|
||||
_uiState.update { it.copy(wavelogMessage = "Wavelog URL/token not configured") }
|
||||
return
|
||||
}
|
||||
// Persist the credentials first, then sync with the freshly-typed values.
|
||||
settingsRepo.updateWavelogSettings(settings)
|
||||
_uiState.update { it.copy(wavelogSyncing = true, wavelogMessage = null) }
|
||||
viewModelScope.launch {
|
||||
val grids = wavelogRepo.fetchWorkedGrids(settings.url, settings.token)
|
||||
@@ -190,12 +192,13 @@ class SettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncLoTWGrids() {
|
||||
val settings = _uiState.value.lotwSettings
|
||||
private fun syncLoTWGrids(settings: com.rtbishop.look4sat.core.domain.model.LoTWSettings) {
|
||||
if (!settings.isConfigured) {
|
||||
_uiState.update { it.copy(lotwMessage = "LoTW callsign/password not configured") }
|
||||
return
|
||||
}
|
||||
// Persist the credentials first, then sync with the freshly-typed values.
|
||||
settingsRepo.updateLoTWSettings(settings)
|
||||
_uiState.update { it.copy(lotwSyncing = true, lotwMessage = null) }
|
||||
viewModelScope.launch {
|
||||
val lotwGrids = lotwRepo.fetchConfirmedGrids(settings.callsign, settings.password)
|
||||
|
||||
Reference in new issue
Block a user