mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8fdd2e93e | ||
|
|
dc013f920d | ||
|
|
f36a426855 | ||
|
|
4da59bdd17 | ||
|
|
b8138c948b | ||
|
|
0e28231c4a | ||
|
|
d6bdf5ecb6 | ||
|
|
6962a4bfa1 | ||
|
|
94a1a4f7b7 | ||
|
|
dbf2229774 | ||
|
|
f2fc1b7b28 | ||
|
|
d600836e19 | ||
|
|
94bffe80b0 | ||
|
|
4260fbb096 | ||
|
|
3d5b55faa3 | ||
|
|
466f2f6088 |
No files matched your search
@@ -177,6 +177,28 @@ fun MainScreen(
|
|||||||
factory = MapFilterViewModel.factory()
|
factory = MapFilterViewModel.factory()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Map grid-QSO dialog "Match" button: pre-fill the match page for that
|
||||||
|
// grid and run the query BEFORE navigating, so the page's first frame
|
||||||
|
// already contains the results (time-range card at the top, pass curves
|
||||||
|
// right below — no scroll flicker). Navigation happens once the query
|
||||||
|
// finishes (see the collector below).
|
||||||
|
val mutualState by mutualViewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
val matchCalculating = mutualState.pendingNavigation && mutualState.isCalculating
|
||||||
|
|
||||||
|
LaunchedEffect(mutualViewModel) {
|
||||||
|
mutualViewModel.uiState.collect { state ->
|
||||||
|
if (state.pendingNavigation && !state.isCalculating) {
|
||||||
|
mutualViewModel.consumePendingNavigation()
|
||||||
|
// Push Mutual on top of the Map entry instead of replacing the
|
||||||
|
// stack (bottom-nav style): the system back gesture then pops
|
||||||
|
// back to the map page, which is the page the user came from.
|
||||||
|
if (backStack.lastOrNull() !is Screen.Mutual) {
|
||||||
|
backStack.add(Screen.Mutual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalElevationThresholds provides ElevationThresholds(
|
LocalElevationThresholds provides ElevationThresholds(
|
||||||
low = otherSettings.lowElevation,
|
low = otherSettings.lowElevation,
|
||||||
@@ -246,12 +268,14 @@ fun MainScreen(
|
|||||||
entry<Screen.Map> {
|
entry<Screen.Map> {
|
||||||
MapDestination(
|
MapDestination(
|
||||||
mapFilterViewModel = mapFilterViewModel,
|
mapFilterViewModel = mapFilterViewModel,
|
||||||
|
matchCalculating = matchCalculating,
|
||||||
onMatchGrid = { grid ->
|
onMatchGrid = { grid ->
|
||||||
// Grid-QSO dialog "Match" button: pre-fill the
|
// Grid-QSO dialog "Match" button: pre-fill
|
||||||
// match page for that grid and switch to its tab.
|
// the match page for that grid and start the
|
||||||
|
// query. Navigation to the match page is
|
||||||
|
// handled by the uiState collector above,
|
||||||
|
// once the query finishes.
|
||||||
mutualViewModel.prefillMatchFromGrid(grid)
|
mutualViewModel.prefillMatchFromGrid(grid)
|
||||||
while (backStack.size > 1) backStack.removeAt(backStack.size - 1)
|
|
||||||
backStack.add(Screen.Mutual)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,6 +269,43 @@ class SettingsRepo(
|
|||||||
preferences.edit { putString(keyRoamedGrids, array.toString()) }
|
preferences.edit { putString(keyRoamedGrids, array.toString()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marked stations in unworked gridsquares, persisted as a single JSON
|
||||||
|
// object: {"OL62":{"c":call,"t":epochMs}}. One mark per grid.
|
||||||
|
private val keyMarkedGridStations = "markedGridStations"
|
||||||
|
|
||||||
|
override fun getMarkedGridStations(): Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> {
|
||||||
|
val json = preferences.getString(keyMarkedGridStations, null).orEmpty()
|
||||||
|
if (json.isBlank()) return emptyMap()
|
||||||
|
return try {
|
||||||
|
val root = org.json.JSONObject(json)
|
||||||
|
val result = mutableMapOf<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>()
|
||||||
|
for (grid in root.keys()) {
|
||||||
|
val o = root.optJSONObject(grid) ?: continue
|
||||||
|
val call = o.optString("c").ifBlank { continue }
|
||||||
|
result[grid] = com.rtbishop.look4sat.core.domain.model.MarkedStation(
|
||||||
|
call = call,
|
||||||
|
epochMs = o.optLong("t")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
result
|
||||||
|
} catch (_: Exception) {
|
||||||
|
emptyMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setMarkedGridStations(stations: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>) {
|
||||||
|
val root = org.json.JSONObject()
|
||||||
|
for ((grid, station) in stations) {
|
||||||
|
root.put(
|
||||||
|
grid,
|
||||||
|
org.json.JSONObject()
|
||||||
|
.put("c", station.call)
|
||||||
|
.put("t", station.epochMs)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
preferences.edit { putString(keyMarkedGridStations, root.toString()) }
|
||||||
|
}
|
||||||
|
|
||||||
// LoTW credentials (stored locally on the device only)
|
// LoTW credentials (stored locally on the device only)
|
||||||
private val keyLoTWCall = "lotwCallsign"
|
private val keyLoTWCall = "lotwCallsign"
|
||||||
private val keyLoTWPass = "lotwPassword"
|
private val keyLoTWPass = "lotwPassword"
|
||||||
|
|||||||
@@ -312,6 +312,10 @@ private class FakeSettingsRepo(dataSources: DataSourcesSettings = defaultDataSou
|
|||||||
override fun setRoamedGrids(grids: Set<String>) {
|
override fun setRoamedGrids(grids: Set<String>) {
|
||||||
roamedGrids.value = grids
|
roamedGrids.value = grids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getMarkedGridStations(): Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap()
|
||||||
|
|
||||||
|
override fun setMarkedGridStations(stations: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>) = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultDataSourcesSettings(): DataSourcesSettings {
|
private fun defaultDataSourcesSettings(): DataSourcesSettings {
|
||||||
|
|||||||
+2
@@ -189,6 +189,8 @@ private class FakeSettingsRepoForSearch : ISettingsRepo {
|
|||||||
override fun setWorkedGridQsos(qsos: Map<String, List<com.rtbishop.look4sat.core.domain.model.GridQso>>) = Unit
|
override fun setWorkedGridQsos(qsos: Map<String, List<com.rtbishop.look4sat.core.domain.model.GridQso>>) = Unit
|
||||||
override fun getRoamedGrids(): Set<String> = emptySet()
|
override fun getRoamedGrids(): Set<String> = emptySet()
|
||||||
override fun setRoamedGrids(grids: Set<String>) = Unit
|
override fun setRoamedGrids(grids: Set<String>) = Unit
|
||||||
|
override fun getMarkedGridStations(): Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap()
|
||||||
|
override fun setMarkedGridStations(stations: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>) = Unit
|
||||||
override fun updateLoTWSettings(settings: com.rtbishop.look4sat.core.domain.model.LoTWSettings) = Unit
|
override fun updateLoTWSettings(settings: com.rtbishop.look4sat.core.domain.model.LoTWSettings) = Unit
|
||||||
override fun getLastLotwSyncDate(): String = ""
|
override fun getLastLotwSyncDate(): String = ""
|
||||||
override fun setLastLotwSyncDate(date: String) = Unit
|
override fun setLastLotwSyncDate(date: String) = Unit
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||||
|
* Copyright (C) 2019-2026 Arty Bishop and contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.rtbishop.look4sat.core.domain.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A station the user marked in a gridsquare they have NOT yet worked — a
|
||||||
|
* reminder to try to contact that callsign. Stored per 4-char grid (one mark
|
||||||
|
* per grid).
|
||||||
|
*
|
||||||
|
* @param call the callsign the user wants to work (uppercase)
|
||||||
|
* @param epochMs the moment the mark was created, UTC milliseconds
|
||||||
|
*/
|
||||||
|
data class MarkedStation(
|
||||||
|
val call: String,
|
||||||
|
val epochMs: Long
|
||||||
|
)
|
||||||
+5
@@ -105,6 +105,11 @@ interface ISettingsRepo {
|
|||||||
/** Distinct 4-char gridsquares the account operated from (LoTW <MY_GRIDSQUARE>). */
|
/** Distinct 4-char gridsquares the account operated from (LoTW <MY_GRIDSQUARE>). */
|
||||||
fun getRoamedGrids(): Set<String>
|
fun getRoamedGrids(): Set<String>
|
||||||
fun setRoamedGrids(grids: Set<String>)
|
fun setRoamedGrids(grids: Set<String>)
|
||||||
|
/** Stations the user marked as "want to contact" in unworked gridsquares
|
||||||
|
* (grid -> mark). One mark per grid; cleared automatically when the grid
|
||||||
|
* becomes worked. */
|
||||||
|
fun getMarkedGridStations(): Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>
|
||||||
|
fun setMarkedGridStations(stations: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>)
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region # LoTW confirmed-grids settings
|
//region # LoTW confirmed-grids settings
|
||||||
|
|||||||
+4
@@ -21,6 +21,7 @@ import com.rtbishop.look4sat.core.domain.model.DatabaseState
|
|||||||
import com.rtbishop.look4sat.core.domain.model.DataSourcesSettings
|
import com.rtbishop.look4sat.core.domain.model.DataSourcesSettings
|
||||||
import com.rtbishop.look4sat.core.domain.model.GridQso
|
import com.rtbishop.look4sat.core.domain.model.GridQso
|
||||||
import com.rtbishop.look4sat.core.domain.model.LoTWSettings
|
import com.rtbishop.look4sat.core.domain.model.LoTWSettings
|
||||||
|
import com.rtbishop.look4sat.core.domain.model.MarkedStation
|
||||||
import com.rtbishop.look4sat.core.domain.model.OtherSettings
|
import com.rtbishop.look4sat.core.domain.model.OtherSettings
|
||||||
import com.rtbishop.look4sat.core.domain.model.PassesSettings
|
import com.rtbishop.look4sat.core.domain.model.PassesSettings
|
||||||
import com.rtbishop.look4sat.core.domain.model.RCSettings
|
import com.rtbishop.look4sat.core.domain.model.RCSettings
|
||||||
@@ -261,6 +262,9 @@ class LoTWGridSyncTest {
|
|||||||
override fun setWorkedGridQsos(qsos: Map<String, List<GridQso>>) { workedGridQsos = qsos }
|
override fun setWorkedGridQsos(qsos: Map<String, List<GridQso>>) { workedGridQsos = qsos }
|
||||||
override fun getRoamedGrids(): Set<String> = roamedGrids
|
override fun getRoamedGrids(): Set<String> = roamedGrids
|
||||||
override fun setRoamedGrids(grids: Set<String>) { roamedGrids = grids }
|
override fun setRoamedGrids(grids: Set<String>) { roamedGrids = grids }
|
||||||
|
private var markedGridStations: Map<String, MarkedStation> = emptyMap()
|
||||||
|
override fun getMarkedGridStations(): Map<String, MarkedStation> = markedGridStations
|
||||||
|
override fun setMarkedGridStations(stations: Map<String, MarkedStation>) { markedGridStations = stations }
|
||||||
override fun getLastLotwSyncDate(): String = lastSyncDate
|
override fun getLastLotwSyncDate(): String = lastSyncDate
|
||||||
override fun setLastLotwSyncDate(date: String) { lastSyncDate = date }
|
override fun setLastLotwSyncDate(date: String) { lastSyncDate = date }
|
||||||
override fun getLastLotwSyncCallsign(): String = lastSyncCallsign
|
override fun getLastLotwSyncCallsign(): String = lastSyncCallsign
|
||||||
|
|||||||
@@ -131,6 +131,12 @@
|
|||||||
<string name="grid_qso_first">首通</string>
|
<string name="grid_qso_first">首通</string>
|
||||||
<string name="grid_qso_no_sat">卫星未知</string>
|
<string name="grid_qso_no_sat">卫星未知</string>
|
||||||
<string name="grid_qso_match">匹配</string>
|
<string name="grid_qso_match">匹配</string>
|
||||||
|
<!-- 未通联网格中的“标记想通联的电台”提醒 -->
|
||||||
|
<string name="grid_mark_station">标记你想通联的电台</string>
|
||||||
|
<string name="grid_mark_callsign">呼号</string>
|
||||||
|
<string name="grid_mark_confirm">标记</string>
|
||||||
|
<string name="grid_mark_label">标记</string>
|
||||||
|
<string name="grid_mark_delete">删除标记</string>
|
||||||
<string name="map_visible">日照中</string>
|
<string name="map_visible">日照中</string>
|
||||||
|
|
||||||
<!-- Settings screen -->
|
<!-- Settings screen -->
|
||||||
|
|||||||
@@ -151,6 +151,12 @@
|
|||||||
<string name="grid_qso_first">First</string>
|
<string name="grid_qso_first">First</string>
|
||||||
<string name="grid_qso_no_sat">satellite unknown</string>
|
<string name="grid_qso_no_sat">satellite unknown</string>
|
||||||
<string name="grid_qso_match">Match</string>
|
<string name="grid_qso_match">Match</string>
|
||||||
|
<!-- Mark-a-station reminder in unworked grids -->
|
||||||
|
<string name="grid_mark_station">Mark a station you want to contact</string>
|
||||||
|
<string name="grid_mark_callsign">Callsign</string>
|
||||||
|
<string name="grid_mark_confirm">Mark</string>
|
||||||
|
<string name="grid_mark_label">Marked</string>
|
||||||
|
<string name="grid_mark_delete">Remove mark</string>
|
||||||
<string name="map_visible">Visible</string>
|
<string name="map_visible">Visible</string>
|
||||||
|
|
||||||
<!-- Settings screen -->
|
<!-- Settings screen -->
|
||||||
|
|||||||
+36
-4
@@ -64,6 +64,11 @@ class MaidenheadGridOverlay : Overlay() {
|
|||||||
style = android.graphics.Paint.Style.FILL
|
style = android.graphics.Paint.Style.FILL
|
||||||
color = Color.argb(90, 76, 217, 100)
|
color = Color.argb(90, 76, 217, 100)
|
||||||
}
|
}
|
||||||
|
// 标记(想通联)网格填充: 红色, 透明度与绿色 workedPaint 一致(alpha 90).
|
||||||
|
private val markedPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
style = android.graphics.Paint.Style.FILL
|
||||||
|
color = Color.argb(90, 255, 59, 48)
|
||||||
|
}
|
||||||
private val roamStripePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
private val roamStripePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
style = Paint.Style.STROKE
|
style = Paint.Style.STROKE
|
||||||
strokeWidth = 14f
|
strokeWidth = 14f
|
||||||
@@ -87,6 +92,11 @@ class MaidenheadGridOverlay : Overlay() {
|
|||||||
/** Worked gridsquares (4-char, uppercase) to highlight, e.g. {"OL62", "PM95"}. */
|
/** Worked gridsquares (4-char, uppercase) to highlight, e.g. {"OL62", "PM95"}. */
|
||||||
var workedGrids: Set<String> = emptySet()
|
var workedGrids: Set<String> = emptySet()
|
||||||
|
|
||||||
|
/** Marked gridsquares (4-char, uppercase) — unworked grids the user has
|
||||||
|
* marked a station they want to contact in; drawn red, same alpha as the
|
||||||
|
* green worked fill. Value carries the marked callsign for label mode. */
|
||||||
|
var markedGrids: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap()
|
||||||
|
|
||||||
/** Grid-mode first-call labels: label worked (green) cells with the first
|
/** Grid-mode first-call labels: label worked (green) cells with the first
|
||||||
* callsign worked in that grid instead of the Maidenhead code; non-worked
|
* callsign worked in that grid instead of the Maidenhead code; non-worked
|
||||||
* cells get no label at all. Only meaningful at sub-square zoom. */
|
* cells get no label at all. Only meaningful at sub-square zoom. */
|
||||||
@@ -189,6 +199,9 @@ class MaidenheadGridOverlay : Overlay() {
|
|||||||
if (cellLabel(lat, lon, zoom) in workedGrids) {
|
if (cellLabel(lat, lon, zoom) in workedGrids) {
|
||||||
canvas.drawRect(xLeft, yTop, xRight, yBottom, workedPaint)
|
canvas.drawRect(xLeft, yTop, xRight, yBottom, workedPaint)
|
||||||
}
|
}
|
||||||
|
if (cellLabel(lat, lon, zoom) in markedGrids) {
|
||||||
|
canvas.drawRect(xLeft, yTop, xRight, yBottom, markedPaint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -215,6 +228,22 @@ class MaidenheadGridOverlay : Overlay() {
|
|||||||
canvas.drawRect(xLeft, yTop, xRight, yBottom, workedPaint)
|
canvas.drawRect(xLeft, yTop, xRight, yBottom, workedPaint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (grid in markedGrids.keys) {
|
||||||
|
val cell = gridCellBounds(grid) ?: continue
|
||||||
|
for (turn in -colRepeats..colRepeats) {
|
||||||
|
val dLon = turn * 360.0
|
||||||
|
if (cell.lonRight + dLon <= leftLon || cell.lonLeft + dLon >= rightLon) continue
|
||||||
|
val yTop = projectionToY(projection, cell.latTop) ?: continue
|
||||||
|
val yBottom = projectionToY(projection, cell.latBottom) ?: continue
|
||||||
|
val xLeftBase = projectionToX(projection, cell.lonLeft, centerLon, worldWidthPx) ?: continue
|
||||||
|
val xRightBase = projectionToX(projection, cell.lonRight, centerLon, worldWidthPx) ?: continue
|
||||||
|
val xLeft = xLeftBase + turn * worldWidthPx.toFloat()
|
||||||
|
val xRight = xRightBase + turn * worldWidthPx.toFloat()
|
||||||
|
if (xRight < 0f || xLeft > canvas.width) continue
|
||||||
|
if (yBottom < 0f || yTop > canvas.height) continue
|
||||||
|
canvas.drawRect(xLeft, yTop, xRight, yBottom, markedPaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,12 +443,15 @@ class MaidenheadGridOverlay : Overlay() {
|
|||||||
if (xRight < 0f || xLeft > canvas.width) continue
|
if (xRight < 0f || xLeft > canvas.width) continue
|
||||||
val label = cellLabel(lat, lon, zoom)
|
val label = cellLabel(lat, lon, zoom)
|
||||||
if (showFirstCallLabels) {
|
if (showFirstCallLabels) {
|
||||||
// 首通呼号模式: 只有绿格(worked)标注该格第一个通联的呼号,
|
// 首通呼号模式: 绿格(worked)标注该格第一个通联的呼号, 红格(marked)
|
||||||
// 非绿格空着不写网格字符.
|
// 标注用户标记想通联的呼号, 均淡黄文字; 其它格空着不写网格字符.
|
||||||
if (label in workedGrids) {
|
when {
|
||||||
firstCallsByGrid[label]?.let { call ->
|
label in workedGrids -> firstCallsByGrid[label]?.let { call ->
|
||||||
canvas.drawText(call, (xLeft + xRight) / 2f, yCenter, firstCallPaint)
|
canvas.drawText(call, (xLeft + xRight) / 2f, yCenter, firstCallPaint)
|
||||||
}
|
}
|
||||||
|
label in markedGrids -> markedGrids[label]?.let { station ->
|
||||||
|
canvas.drawText(station.call, (xLeft + xRight) / 2f, yCenter, firstCallPaint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
canvas.drawText(label, (xLeft + xRight) / 2f, yCenter, labelPaint)
|
canvas.drawText(label, (xLeft + xRight) / 2f, yCenter, labelPaint)
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -153,7 +154,10 @@ fun MapDestination(
|
|||||||
mapFilterViewModel: MapFilterViewModel,
|
mapFilterViewModel: MapFilterViewModel,
|
||||||
// Invoked with the tapped grid when the QSO dialog's "Match" button is
|
// Invoked with the tapped grid when the QSO dialog's "Match" button is
|
||||||
// pressed: navigate to the match page pre-filled for that grid.
|
// pressed: navigate to the match page pre-filled for that grid.
|
||||||
onMatchGrid: (String) -> Unit = {}
|
onMatchGrid: (String) -> Unit = {},
|
||||||
|
// True while the map "Match" query is running (the page only navigates
|
||||||
|
// once the query finished, so the match page opens with results ready).
|
||||||
|
matchCalculating: Boolean = false
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val container = (context.applicationContext as IContainerProvider).getMainContainer()
|
val container = (context.applicationContext as IContainerProvider).getMainContainer()
|
||||||
@@ -190,7 +194,7 @@ fun MapDestination(
|
|||||||
viewModel.onAction(MapAction.SetVisible(false))
|
viewModel.onAction(MapAction.SetVisible(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MapScreen(uiState, viewModel::onAction, mapView, mapFilterViewModel, onMatchGrid)
|
MapScreen(uiState, viewModel::onAction, mapView, mapFilterViewModel, onMatchGrid, matchCalculating)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -199,7 +203,8 @@ private fun MapScreen(
|
|||||||
onAction: (MapAction) -> Unit,
|
onAction: (MapAction) -> Unit,
|
||||||
mapView: MapView,
|
mapView: MapView,
|
||||||
mapFilterViewModel: MapFilterViewModel,
|
mapFilterViewModel: MapFilterViewModel,
|
||||||
onMatchGrid: (String) -> Unit
|
onMatchGrid: (String) -> Unit,
|
||||||
|
matchCalculating: Boolean
|
||||||
) {
|
) {
|
||||||
val rotateMod = Modifier.rotate(180f)
|
val rotateMod = Modifier.rotate(180f)
|
||||||
val timeString = uiState.mapData?.aosTime ?: "00:00:00"
|
val timeString = uiState.mapData?.aosTime ?: "00:00:00"
|
||||||
@@ -357,7 +362,8 @@ private fun MapScreen(
|
|||||||
centerOnStation = shouldCenter,
|
centerOnStation = shouldCenter,
|
||||||
// 首通呼号标签只作用于 VUCC 视图(用户要求); "All"/其他奖状不过滤.
|
// 首通呼号标签只作用于 VUCC 视图(用户要求); "All"/其他奖状不过滤.
|
||||||
showFirstCallLabels = uiState.showFirstCallLabels && selectedAward == AwardType.VUCC,
|
showFirstCallLabels = uiState.showFirstCallLabels && selectedAward == AwardType.VUCC,
|
||||||
firstCallsByGrid = firstCallsByGrid
|
firstCallsByGrid = firstCallsByGrid,
|
||||||
|
markedGrids = uiState.markedGrids
|
||||||
)
|
)
|
||||||
if (!shouldCenter || uiState.stationPosition != null) {
|
if (!shouldCenter || uiState.stationPosition != null) {
|
||||||
prevGridMode = uiState.isGridMode
|
prevGridMode = uiState.isGridMode
|
||||||
@@ -417,14 +423,19 @@ private fun MapScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Centered dialog listing the tapped worked grid's confirmed satellite QSOs.
|
// Centered dialog listing the tapped worked grid's confirmed satellite QSOs.
|
||||||
// Dismissed by tapping outside (no explicit close button).
|
// Dismissed by tapping outside (no explicit close button). Unworked grids
|
||||||
|
// open the same dialog with an empty list plus a mark-a-station reminder.
|
||||||
selectedGrid?.let { grid ->
|
selectedGrid?.let { grid ->
|
||||||
WorkedGridQsoDialog(
|
WorkedGridQsoDialog(
|
||||||
grid = grid,
|
grid = grid,
|
||||||
qsos = uiState.workedGridQsos[grid].orEmpty().sortedBy { it.epochMs },
|
qsos = uiState.workedGridQsos[grid].orEmpty().sortedBy { it.epochMs },
|
||||||
|
marked = uiState.markedGrids[grid],
|
||||||
isUtc = uiState.isUtc,
|
isUtc = uiState.isUtc,
|
||||||
|
matchCalculating = matchCalculating,
|
||||||
onDismiss = { selectedGrid = null },
|
onDismiss = { selectedGrid = null },
|
||||||
onMatch = { onMatchGrid(grid) }
|
onMatch = { onMatchGrid(grid) },
|
||||||
|
onMark = { call -> onAction(MapAction.SetMarkedStation(grid, call)) },
|
||||||
|
onRemoveMark = { onAction(MapAction.RemoveMarkedStation(grid)) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,10 +446,16 @@ private fun MapScreen(
|
|||||||
private fun WorkedGridQsoDialog(
|
private fun WorkedGridQsoDialog(
|
||||||
grid: String,
|
grid: String,
|
||||||
qsos: List<com.rtbishop.look4sat.core.domain.model.GridQso>,
|
qsos: List<com.rtbishop.look4sat.core.domain.model.GridQso>,
|
||||||
|
marked: com.rtbishop.look4sat.core.domain.model.MarkedStation?,
|
||||||
isUtc: Boolean,
|
isUtc: Boolean,
|
||||||
|
matchCalculating: Boolean,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onMatch: () -> Unit
|
onMatch: () -> Unit,
|
||||||
|
onMark: (String) -> Unit,
|
||||||
|
onRemoveMark: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
var showMarkInput by remember { mutableStateOf(false) }
|
||||||
|
var callInput by remember { mutableStateOf("") }
|
||||||
androidx.compose.ui.window.Dialog(onDismissRequest = onDismiss) {
|
androidx.compose.ui.window.Dialog(onDismissRequest = onDismiss) {
|
||||||
// Centered card, ~85% width, internal scroll for long lists.
|
// Centered card, ~85% width, internal scroll for long lists.
|
||||||
Card(
|
Card(
|
||||||
@@ -467,41 +484,150 @@ private fun WorkedGridQsoDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
TextButton(
|
TextButton(
|
||||||
|
enabled = !matchCalculating,
|
||||||
onClick = {
|
onClick = {
|
||||||
onDismiss()
|
onDismiss()
|
||||||
onMatch()
|
onMatch()
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Icon(
|
if (matchCalculating) {
|
||||||
painter = painterResource(R.drawable.ic_radio_tower),
|
CircularProgressIndicator(
|
||||||
contentDescription = null,
|
modifier = Modifier.size(18.dp),
|
||||||
modifier = Modifier.size(18.dp)
|
strokeWidth = 2.dp
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(R.drawable.ic_radio_tower),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
Spacer(Modifier.width(4.dp))
|
Spacer(Modifier.width(4.dp))
|
||||||
Text(stringResource(R.string.grid_qso_match))
|
Text(stringResource(R.string.grid_qso_match))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
androidx.compose.material3.HorizontalDivider()
|
androidx.compose.material3.HorizontalDivider()
|
||||||
if (qsos.isNotEmpty()) {
|
Column(
|
||||||
// Group by callsign preserving first-contact order (list is
|
Modifier
|
||||||
// already sorted oldest-first); expandable rows.
|
.heightIn(max = 380.dp)
|
||||||
val grouped = remember(qsos) {
|
.verticalScroll(rememberScrollState())
|
||||||
qsos.groupBy { it.call }.entries.sortedBy { it.value.first().epochMs }
|
) {
|
||||||
|
// A marked station shows first as a red reminder row: red
|
||||||
|
// callsign, "标记" in the count column, the marking date in
|
||||||
|
// the date column, and a small delete icon to remove it.
|
||||||
|
if (marked != null) {
|
||||||
|
MarkedStationRow(marked = marked, isUtc = isUtc, onRemoveMark = onRemoveMark)
|
||||||
|
androidx.compose.material3.HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.3f))
|
||||||
}
|
}
|
||||||
Column(
|
if (qsos.isNotEmpty()) {
|
||||||
Modifier
|
// Group by callsign preserving first-contact order (list is
|
||||||
.heightIn(max = 380.dp)
|
// already sorted oldest-first); expandable rows.
|
||||||
.verticalScroll(rememberScrollState())
|
val grouped = remember(qsos) {
|
||||||
) {
|
qsos.groupBy { it.call }.entries.sortedBy { it.value.first().epochMs }
|
||||||
|
}
|
||||||
grouped.forEach { (call, callQsos) ->
|
grouped.forEach { (call, callQsos) ->
|
||||||
WorkedGridCallRow(call, callQsos = callQsos, isUtc = isUtc)
|
WorkedGridCallRow(call, callQsos = callQsos, isUtc = isUtc)
|
||||||
androidx.compose.material3.HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.3f))
|
androidx.compose.material3.HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.3f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Unworked grids: offer to mark a station the user wants to
|
||||||
|
// contact in this grid (a reminder, cleared when worked).
|
||||||
|
if (qsos.isEmpty()) {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
callInput = marked?.call.orEmpty()
|
||||||
|
showMarkInput = true
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(R.drawable.ic_add),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Text(stringResource(R.string.grid_mark_station))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Mark-a-station input dialog: enter a callsign as a reminder.
|
||||||
|
if (showMarkInput) {
|
||||||
|
androidx.compose.material3.AlertDialog(
|
||||||
|
onDismissRequest = { showMarkInput = false },
|
||||||
|
title = { Text(stringResource(R.string.grid_mark_station)) },
|
||||||
|
text = {
|
||||||
|
androidx.compose.material3.OutlinedTextField(
|
||||||
|
value = callInput,
|
||||||
|
onValueChange = { callInput = it.uppercase() },
|
||||||
|
label = { Text(stringResource(R.string.grid_mark_callsign)) },
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
enabled = callInput.isNotBlank(),
|
||||||
|
onClick = {
|
||||||
|
onMark(callInput)
|
||||||
|
showMarkInput = false
|
||||||
|
}
|
||||||
|
) { Text(stringResource(R.string.grid_mark_confirm)) }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { showMarkInput = false }) { Text(stringResource(R.string.btn_cancel)) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MarkedStationRow(
|
||||||
|
marked: com.rtbishop.look4sat.core.domain.model.MarkedStation,
|
||||||
|
isUtc: Boolean,
|
||||||
|
onRemoveMark: () -> Unit
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = marked.call,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||||
|
color = ComposeColor(0xFFFF3B30),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.grid_mark_label),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.End,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = formatDate(marked.epochMs, isUtc),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(R.drawable.ic_delete),
|
||||||
|
contentDescription = stringResource(R.string.grid_mark_delete),
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(18.dp)
|
||||||
|
.clickable(onClick = onRemoveMark)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -929,7 +1055,8 @@ private fun setGridMode(
|
|||||||
stationPosition: GeoPos?,
|
stationPosition: GeoPos?,
|
||||||
centerOnStation: Boolean = false,
|
centerOnStation: Boolean = false,
|
||||||
showFirstCallLabels: Boolean = false,
|
showFirstCallLabels: Boolean = false,
|
||||||
firstCallsByGrid: Map<String, String> = emptyMap()
|
firstCallsByGrid: Map<String, String> = emptyMap(),
|
||||||
|
markedGrids: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap()
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
val gridOverlay = mapView.overlays[OVERLAY_GRID]
|
val gridOverlay = mapView.overlays[OVERLAY_GRID]
|
||||||
@@ -940,6 +1067,7 @@ private fun setGridMode(
|
|||||||
// 首通呼号模式: 绿格标注第一个通联的呼号, 非绿格不显示标签.
|
// 首通呼号模式: 绿格标注第一个通联的呼号, 非绿格不显示标签.
|
||||||
gridOverlay.showFirstCallLabels = showFirstCallLabels
|
gridOverlay.showFirstCallLabels = showFirstCallLabels
|
||||||
gridOverlay.firstCallsByGrid = firstCallsByGrid
|
gridOverlay.firstCallsByGrid = firstCallsByGrid
|
||||||
|
gridOverlay.markedGrids = markedGrids
|
||||||
// ownGrid must be set on EVERY update — the position is available
|
// ownGrid must be set on EVERY update — the position is available
|
||||||
// regardless of whether this frame centers (centering happens only
|
// regardless of whether this frame centers (centering happens only
|
||||||
// on entry, but passing null here would wipe the bold outline).
|
// on entry, but passing null here would wipe the bold outline).
|
||||||
@@ -951,6 +1079,7 @@ private fun setGridMode(
|
|||||||
this.roamedGrids = roamedGrids
|
this.roamedGrids = roamedGrids
|
||||||
this.showFirstCallLabels = showFirstCallLabels
|
this.showFirstCallLabels = showFirstCallLabels
|
||||||
this.firstCallsByGrid = firstCallsByGrid
|
this.firstCallsByGrid = firstCallsByGrid
|
||||||
|
this.markedGrids = markedGrids
|
||||||
this.ownGrid = ownGridOf(stationPosition)
|
this.ownGrid = ownGridOf(stationPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ data class MapState(
|
|||||||
val workedGridQsos: Map<String, List<com.rtbishop.look4sat.core.domain.model.GridQso>> = emptyMap(),
|
val workedGridQsos: Map<String, List<com.rtbishop.look4sat.core.domain.model.GridQso>> = emptyMap(),
|
||||||
/** 4-char gridsquares the station operated from (LoTW MY_GRIDSQUARE) — blue stripes. */
|
/** 4-char gridsquares the station operated from (LoTW MY_GRIDSQUARE) — blue stripes. */
|
||||||
val roamedGrids: Set<String> = emptySet(),
|
val roamedGrids: Set<String> = emptySet(),
|
||||||
|
/** Stations the user marked in unworked gridsquares (grid -> mark) — red fill. */
|
||||||
|
val markedGrids: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap(),
|
||||||
val stationPosition: GeoPos? = null,
|
val stationPosition: GeoPos? = null,
|
||||||
val orbitalPass: OrbitalPass,
|
val orbitalPass: OrbitalPass,
|
||||||
val track: List<List<GeoPos>>? = null,
|
val track: List<List<GeoPos>>? = null,
|
||||||
@@ -52,6 +54,8 @@ sealed interface MapAction {
|
|||||||
data class SelectDefaultItem(val catnum: Int) : MapAction
|
data class SelectDefaultItem(val catnum: Int) : MapAction
|
||||||
data class ToggleGridMode(val value: Boolean) : MapAction
|
data class ToggleGridMode(val value: Boolean) : MapAction
|
||||||
data class ToggleFirstCallLabels(val value: Boolean) : MapAction
|
data class ToggleFirstCallLabels(val value: Boolean) : MapAction
|
||||||
|
data class SetMarkedStation(val grid: String, val call: String) : MapAction
|
||||||
|
data class RemoveMarkedStation(val grid: String) : MapAction
|
||||||
data class SetVisible(val isVisible: Boolean) : MapAction
|
data class SetVisible(val isVisible: Boolean) : MapAction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,11 +90,19 @@ class MapViewModel(
|
|||||||
}
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
settingsRepo.wavelogSettings.collectLatest { _ ->
|
settingsRepo.wavelogSettings.collectLatest { _ ->
|
||||||
|
val workedGrids = settingsRepo.getWorkedGrids()
|
||||||
|
val markedGrids = settingsRepo.getMarkedGridStations()
|
||||||
|
// Marked stations auto-clear once their grid becomes worked:
|
||||||
|
// the reminder has served its purpose (user req: 网格变绿后标记自动清除).
|
||||||
|
val stale = markedGrids.keys.filter { it in workedGrids }
|
||||||
|
val activeMarks = if (stale.isEmpty()) markedGrids else markedGrids - stale.toSet()
|
||||||
|
if (stale.isNotEmpty()) settingsRepo.setMarkedGridStations(activeMarks)
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
workedGrids = settingsRepo.getWorkedGrids(),
|
workedGrids = workedGrids,
|
||||||
workedGridQsos = settingsRepo.getWorkedGridQsos(),
|
workedGridQsos = settingsRepo.getWorkedGridQsos(),
|
||||||
roamedGrids = settingsRepo.getRoamedGrids()
|
roamedGrids = settingsRepo.getRoamedGrids(),
|
||||||
|
markedGrids = activeMarks
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +120,20 @@ class MapViewModel(
|
|||||||
is MapAction.SelectDefaultItem -> selectDefaultSatellite(action.catnum)
|
is MapAction.SelectDefaultItem -> selectDefaultSatellite(action.catnum)
|
||||||
is MapAction.ToggleGridMode -> settingsRepo.updateOtherSettings { it.copy(stateOfMapGrid = action.value) }
|
is MapAction.ToggleGridMode -> settingsRepo.updateOtherSettings { it.copy(stateOfMapGrid = action.value) }
|
||||||
is MapAction.ToggleFirstCallLabels -> settingsRepo.updateOtherSettings { it.copy(stateOfMapFirstCall = action.value) }
|
is MapAction.ToggleFirstCallLabels -> settingsRepo.updateOtherSettings { it.copy(stateOfMapFirstCall = action.value) }
|
||||||
|
is MapAction.SetMarkedStation -> {
|
||||||
|
val updated = settingsRepo.getMarkedGridStations() +
|
||||||
|
(action.grid to com.rtbishop.look4sat.core.domain.model.MarkedStation(
|
||||||
|
call = action.call.trim().uppercase(),
|
||||||
|
epochMs = System.currentTimeMillis()
|
||||||
|
))
|
||||||
|
settingsRepo.setMarkedGridStations(updated)
|
||||||
|
_uiState.update { it.copy(markedGrids = updated) }
|
||||||
|
}
|
||||||
|
is MapAction.RemoveMarkedStation -> {
|
||||||
|
val updated = settingsRepo.getMarkedGridStations() - action.grid
|
||||||
|
settingsRepo.setMarkedGridStations(updated)
|
||||||
|
_uiState.update { it.copy(markedGrids = updated) }
|
||||||
|
}
|
||||||
is MapAction.SetVisible -> isScreenVisible.value = action.isVisible
|
is MapAction.SetVisible -> isScreenVisible.value = action.isVisible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,20 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.rtbishop.look4sat.feature.mutual"
|
namespace = "com.rtbishop.look4sat.feature.mutual"
|
||||||
}
|
testOptions {
|
||||||
|
unitTests {
|
||||||
|
// Robolectric needs real Android resources for Compose UI tests.
|
||||||
|
isIncludeAndroidResources = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(libs.test.junit4)
|
||||||
|
testImplementation(libs.test.coroutines)
|
||||||
|
testImplementation(libs.robolectric)
|
||||||
|
testImplementation(libs.androidx.test.core)
|
||||||
|
testImplementation(libs.compose.ui.test.junit4)
|
||||||
|
testImplementation(libs.compose.navigation3)
|
||||||
|
debugImplementation(libs.compose.debug.manifest)
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rtbishop.look4sat.feature.mutual
|
package com.rtbishop.look4sat.feature.mutual
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.expandVertically
|
import androidx.compose.animation.expandVertically
|
||||||
import androidx.compose.animation.shrinkVertically
|
import androidx.compose.animation.shrinkVertically
|
||||||
@@ -54,11 +55,13 @@ import androidx.compose.runtime.LaunchedEffect
|
|||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableFloatStateOf
|
import androidx.compose.runtime.mutableFloatStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -77,6 +80,7 @@ import java.text.SimpleDateFormat
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.TimeZone
|
import java.util.TimeZone
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -157,7 +161,7 @@ fun MutualScreen(
|
|||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
state = state,
|
state = state,
|
||||||
isVertical = isVertical,
|
isVertical = isVertical,
|
||||||
onQuery = viewModel::queryMutualPasses,
|
onQuery = { viewModel.queryMutualPasses() },
|
||||||
onSelectPass = viewModel::onSelectPass,
|
onSelectPass = viewModel::onSelectPass,
|
||||||
onNavigateToRadar = navigateToRadar,
|
onNavigateToRadar = navigateToRadar,
|
||||||
onStationALat = viewModel::onStationALat,
|
onStationALat = viewModel::onStationALat,
|
||||||
@@ -220,8 +224,24 @@ private fun MutualContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set once the list has actually been laid out. The prefill scroll only
|
||||||
|
// fires after this, because on a real device the Mutual entry appears
|
||||||
|
// through the NavDisplay transition and LaunchedEffect alone can run
|
||||||
|
// before the list is measurable (the scroll then never lands and the
|
||||||
|
// page stays at the top). onGloballyPositioned fires on the first real
|
||||||
|
// layout, so the subsequent scrollToItem always has a measured list.
|
||||||
|
var listReady by remember { mutableStateOf(false) }
|
||||||
|
Log.d(TAG, "composed: scrollToTimeRange=${state.scrollToTimeRange} matchIndex=${if (state.errorMessage != null) 2 else 1} listReady=$listReady")
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.onGloballyPositioned {
|
||||||
|
if (!listReady) {
|
||||||
|
Log.d(TAG, "lazy list laid out, opening prefill scroll gate")
|
||||||
|
listReady = true
|
||||||
|
}
|
||||||
|
},
|
||||||
state = listState,
|
state = listState,
|
||||||
verticalArrangement = Arrangement.spacedBy(6.dp)
|
verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
@@ -369,8 +389,44 @@ private fun MutualContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefill from the map's grid-QSO dialog "Match" button: once the page is
|
||||||
|
// laid out, jump straight to the time-range card. Index accounts for the
|
||||||
|
// optional error card at the top (error = 0, station inputs = 1, time
|
||||||
|
// range = 2; else 1). scrollToItem is used instead of initializing the
|
||||||
|
// LazyListState at index 1: the constructor parameter is ignored by this
|
||||||
|
// Compose version (verified in tests), while scrollToItem lands correctly.
|
||||||
|
val matchSearchIndex = if (state.errorMessage != null) 2 else 1
|
||||||
|
LaunchedEffect(state.scrollToTimeRange, matchSearchIndex, listReady) {
|
||||||
|
Log.d(TAG, "scroll effect: scrollToTimeRange=${state.scrollToTimeRange} matchIndex=$matchSearchIndex listReady=$listReady")
|
||||||
|
if (state.scrollToTimeRange && listReady) {
|
||||||
|
// Keep trying until the scroll really lands: on a device the first
|
||||||
|
// frame only contains the station cards + time-range card, which
|
||||||
|
// can be shorter than the viewport (no scroll range), so a single
|
||||||
|
// scrollToItem does nothing. When the async query results arrive
|
||||||
|
// the list grows past one screen and the scroll becomes possible.
|
||||||
|
for (attempt in 0 until 20) {
|
||||||
|
Log.d(TAG, "attempting scrollToItem($matchSearchIndex) #$attempt")
|
||||||
|
try {
|
||||||
|
listState.scrollToItem(matchSearchIndex)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.e(TAG, "scrollToItem($matchSearchIndex) threw", t)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (listState.firstVisibleItemIndex == matchSearchIndex) {
|
||||||
|
Log.d(TAG, "scroll landed at $matchSearchIndex on attempt #$attempt")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
delay(100)
|
||||||
|
}
|
||||||
|
viewModel.consumeScrollToTimeRange()
|
||||||
|
Log.d(TAG, "scrollToTimeRange consumed")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val TAG = "Look4SatMutual"
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun MutualStatusChip(state: MutualUiState) {
|
private fun MutualStatusChip(state: MutualUiState) {
|
||||||
val colorScheme = MaterialTheme.colorScheme
|
val colorScheme = MaterialTheme.colorScheme
|
||||||
|
|||||||
+75
-19
@@ -40,6 +40,8 @@ import kotlinx.coroutines.withContext
|
|||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
private const val TAG = "Look4SatMutual"
|
||||||
|
|
||||||
data class MutualUiState(
|
data class MutualUiState(
|
||||||
val stationALat: String = "",
|
val stationALat: String = "",
|
||||||
val stationALon: String = "",
|
val stationALon: String = "",
|
||||||
@@ -50,12 +52,24 @@ data class MutualUiState(
|
|||||||
val stationBGrid: String = "",
|
val stationBGrid: String = "",
|
||||||
val stationBMinElev: Double = 10.0,
|
val stationBMinElev: Double = 10.0,
|
||||||
val hoursAhead: Int = 24,
|
val hoursAhead: Int = 24,
|
||||||
|
/** 历史过境回看窗口(小时), 跟随主页面 Passes 设置; 匹配查询从
|
||||||
|
* now-hoursBefore 开始, 使设置过历史回看时匹配页也包含历史过境. */
|
||||||
|
val hoursBefore: Int = 0,
|
||||||
val mutualPasses: List<MutualPass> = emptyList(),
|
val mutualPasses: List<MutualPass> = emptyList(),
|
||||||
val isCalculating: Boolean = false,
|
val isCalculating: Boolean = false,
|
||||||
val hasSearched: Boolean = false,
|
val hasSearched: Boolean = false,
|
||||||
val selectedPassIndex: Int = -1,
|
val selectedPassIndex: Int = -1,
|
||||||
val isUtc: Boolean = false,
|
val isUtc: Boolean = false,
|
||||||
val errorMessage: String? = null
|
val errorMessage: String? = null,
|
||||||
|
// One-shot flag set by prefillMatchFromGrid() (map grid → Match button):
|
||||||
|
// the page scrolls to the time-range card after the first layout, then
|
||||||
|
// consumeScrollToTimeRange() clears it.
|
||||||
|
val scrollToTimeRange: Boolean = false,
|
||||||
|
// One-shot flag set by prefillMatchFromGrid(): the map page waits for the
|
||||||
|
// pre-filled query to finish, then navigates to the match page so the very
|
||||||
|
// first frame already contains the results (time-range card + pass curves,
|
||||||
|
// no scroll flicker). consumePendingNavigation() clears it.
|
||||||
|
val pendingNavigation: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
class MutualViewModel(
|
class MutualViewModel(
|
||||||
@@ -97,6 +111,12 @@ class MutualViewModel(
|
|||||||
_uiState.update { it.copy(isUtc = settings.stateOfUtc) }
|
_uiState.update { it.copy(isUtc = settings.stateOfUtc) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 历史过境回看窗口跟随主页面 Passes 设置 (设置里改小时数, 匹配页同步生效)
|
||||||
|
viewModelScope.launch {
|
||||||
|
settingsRepo.passesSettings.collectLatest { settings ->
|
||||||
|
_uiState.update { it.copy(hoursBefore = settings.hoursBefore) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onStationALat(value: String) {
|
fun onStationALat(value: String) {
|
||||||
@@ -187,25 +207,46 @@ class MutualViewModel(
|
|||||||
* Pre-fill the match page for a target grid picked from the map's grid-QSO
|
* Pre-fill the match page for a target grid picked from the map's grid-QSO
|
||||||
* dialog ("Match" button): set the opposite-station grid (with its
|
* dialog ("Match" button): set the opposite-station grid (with its
|
||||||
* coordinates), reset the time range to 24h, start the query immediately
|
* coordinates), reset the time range to 24h, start the query immediately
|
||||||
* so results are ready when the page opens, and position the list at the
|
* so results are ready when the page opens, and flag the page to scroll
|
||||||
* time-range card (LazyColumn item 1, the card right below the station
|
* straight to the time-range card once it is laid out.
|
||||||
* inputs) so the page opens showing it at the top.
|
|
||||||
*/
|
*/
|
||||||
fun prefillMatchFromGrid(grid: String) {
|
fun prefillMatchFromGrid(grid: String) {
|
||||||
val g = grid.trim().uppercase()
|
val g = grid.trim().uppercase()
|
||||||
val pos = qthToPosition(g)
|
val pos = qthToPosition(g)
|
||||||
|
android.util.Log.d(TAG, "prefillMatchFromGrid('$g')")
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
stationBGrid = g,
|
stationBGrid = g,
|
||||||
stationBLat = pos?.let { p -> "%.4f".format(p.latitude) } ?: it.stationBLat,
|
stationBLat = pos?.let { p -> "%.4f".format(p.latitude) } ?: it.stationBLat,
|
||||||
stationBLon = pos?.let { p -> "%.4f".format(p.longitude) } ?: it.stationBLon,
|
stationBLon = pos?.let { p -> "%.4f".format(p.longitude) } ?: it.stationBLon,
|
||||||
hoursAhead = 24
|
hoursAhead = 24,
|
||||||
|
scrollToTimeRange = true,
|
||||||
|
pendingNavigation = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
queryMutualPasses(initialScrollIndex = 1)
|
queryMutualPasses()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun queryMutualPasses(initialScrollIndex: Int = 0) {
|
fun consumePendingNavigation() {
|
||||||
|
android.util.Log.d(TAG, "consumePendingNavigation")
|
||||||
|
_uiState.update { it.copy(pendingNavigation = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun consumeScrollToTimeRange() {
|
||||||
|
android.util.Log.d(TAG, "consumeScrollToTimeRange")
|
||||||
|
_uiState.update { it.copy(scrollToTimeRange = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a mutual-pass query. `initialScrollIndex` non-null forces the list
|
||||||
|
* to rebuild at that position (legacy callers); null keeps the current
|
||||||
|
* scroll position, so re-running a query from the match page does not
|
||||||
|
* jump back to the top. The previous results stay on screen while the
|
||||||
|
* query runs (the list keeps its height, so the scroll position is not
|
||||||
|
* clamped away); they are replaced — possibly with empty — when the new
|
||||||
|
* results arrive.
|
||||||
|
*/
|
||||||
|
fun queryMutualPasses(initialScrollIndex: Int? = null) {
|
||||||
val state = _uiState.value
|
val state = _uiState.value
|
||||||
|
|
||||||
// Resolve positions from lat/lon or grid
|
// Resolve positions from lat/lon or grid
|
||||||
@@ -228,26 +269,39 @@ class MutualViewModel(
|
|||||||
isCalculating = true,
|
isCalculating = true,
|
||||||
hasSearched = true,
|
hasSearched = true,
|
||||||
errorMessage = null,
|
errorMessage = null,
|
||||||
mutualPasses = emptyList(),
|
// Deliberately keep mutualPasses: clearing it would shrink the
|
||||||
|
// list below one screen and clamp the scroll position away.
|
||||||
|
// The stale results are replaced when the new ones arrive.
|
||||||
selectedPassIndex = -1
|
selectedPassIndex = -1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// The results list is about to be replaced, so the scroll position must
|
// Scroll position: an explicit initialScrollIndex overrides (legacy
|
||||||
// not leak from the previous query's list. A prefill from the map
|
// callers start at a fixed spot); null keeps the current position so
|
||||||
// (grid-QSO dialog "Match" button) instead starts at the time-range
|
// re-querying does not jump back to the top.
|
||||||
// card so the page opens with it at the top.
|
if (initialScrollIndex != null) {
|
||||||
listScrollIndex = initialScrollIndex
|
listScrollIndex = initialScrollIndex
|
||||||
listScrollOffset = 0
|
listScrollOffset = 0
|
||||||
|
}
|
||||||
queryGeneration += 1
|
queryGeneration += 1
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val time = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
|
// 历史回看: 查询窗口起点 = now - hoursBefore (跟随主页面 Passes 设置),
|
||||||
|
// 终点 = now + hoursAhead 不变.
|
||||||
|
val time = now - state.hoursBefore * 60L * 60L * 1000L
|
||||||
val minElevA = state.stationAMinElev
|
val minElevA = state.stationAMinElev
|
||||||
val minElevB = state.stationBMinElev
|
val minElevB = state.stationBMinElev
|
||||||
val hours = state.hoursAhead
|
val hours = state.hoursAhead
|
||||||
|
|
||||||
val results = withContext(computeDispatcher) {
|
val results = try {
|
||||||
findMutualPasses(satellites, posA, posB, minElevA, minElevB, time, hours)
|
withContext(computeDispatcher) {
|
||||||
|
findMutualPasses(satellites, posA, posB, minElevA, minElevB, time, hours, state.hoursBefore)
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
// Never leave the query stuck in "calculating" (which would also
|
||||||
|
// block the pending map→match navigation forever).
|
||||||
|
android.util.Log.e(TAG, "findMutualPasses threw", t)
|
||||||
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
val errorMsg = if (results.isEmpty()) {
|
val errorMsg = if (results.isEmpty()) {
|
||||||
@@ -286,9 +340,11 @@ class MutualViewModel(
|
|||||||
satellites: List<OrbitalObject>,
|
satellites: List<OrbitalObject>,
|
||||||
posA: GeoPos, posB: GeoPos,
|
posA: GeoPos, posB: GeoPos,
|
||||||
minElevADeg: Double, minElevBDeg: Double,
|
minElevADeg: Double, minElevBDeg: Double,
|
||||||
time: Long, hours: Int
|
time: Long, hours: Int, hoursBefore: Int
|
||||||
): List<MutualPass> {
|
): List<MutualPass> {
|
||||||
val endTime = time + hours * 60L * 60L * 1000L
|
// 终点始终是 now + hoursAhead; 起点已由调用方下移 hoursBefore 小时,
|
||||||
|
// 因此这里的 endTime 要在起点之上补回 hoursBefore, 保证窗口 = [now-hb, now+h].
|
||||||
|
val endTime = time + (hoursBefore + hours) * 60L * 60L * 1000L
|
||||||
val sampleInterval = 5_000L
|
val sampleInterval = 5_000L
|
||||||
|
|
||||||
// Use the main page's pass list for AOS/LOS times, then sample the curves
|
// Use the main page's pass list for AOS/LOS times, then sample the curves
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ class FakeSettingsRepo(initialPosition: GeoPos = GeoPos(23.13, 113.26)) : ISetti
|
|||||||
override fun setWorkedGridQsos(qsos: Map<String, List<GridQso>>) = TODO()
|
override fun setWorkedGridQsos(qsos: Map<String, List<GridQso>>) = TODO()
|
||||||
override fun getRoamedGrids(): Set<String> = TODO()
|
override fun getRoamedGrids(): Set<String> = TODO()
|
||||||
override fun setRoamedGrids(grids: Set<String>) = TODO()
|
override fun setRoamedGrids(grids: Set<String>) = TODO()
|
||||||
|
override fun getMarkedGridStations(): Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation> = emptyMap()
|
||||||
|
override fun setMarkedGridStations(stations: Map<String, com.rtbishop.look4sat.core.domain.model.MarkedStation>) = Unit
|
||||||
override fun updateLoTWSettings(settings: LoTWSettings) = TODO()
|
override fun updateLoTWSettings(settings: LoTWSettings) = TODO()
|
||||||
override fun getLastLotwSyncDate(): String = ""
|
override fun getLastLotwSyncDate(): String = ""
|
||||||
override fun setLastLotwSyncDate(date: String) = Unit
|
override fun setLastLotwSyncDate(date: String) = Unit
|
||||||
|
|||||||
+291
@@ -0,0 +1,291 @@
|
|||||||
|
package com.rtbishop.look4sat.feature.mutual
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.navigation3.runtime.NavBackStack
|
||||||
|
import androidx.navigation3.runtime.NavKey
|
||||||
|
import androidx.navigation3.runtime.entryProvider
|
||||||
|
import androidx.navigation3.runtime.rememberNavBackStack
|
||||||
|
import androidx.navigation3.ui.NavDisplay
|
||||||
|
import com.rtbishop.look4sat.core.presentation.Screen
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
import org.robolectric.annotation.GraphicsMode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the map grid-QSO dialog "Match" prefill: after
|
||||||
|
* [MutualViewModel.prefillMatchFromGrid] the page opens with the time-range
|
||||||
|
* card at the top and the 24h query auto-started.
|
||||||
|
*
|
||||||
|
* Note: `LazyListState(firstVisibleItemIndex = 1)` is deliberately NOT used to
|
||||||
|
* position the page. In this Compose version (BOM 2026.06.01 / ui 1.11.x) the
|
||||||
|
* constructor parameter is ignored — the list still starts at item 0 — while
|
||||||
|
* `listState.scrollToItem(1)` from a LaunchedEffect lands correctly. See
|
||||||
|
* [scrollToItemLandsAtTop] below, which guards the scrollToItem mechanism.
|
||||||
|
*
|
||||||
|
* Robolectric quirk: `assertIsNotDisplayed()` is unreliable here (a node
|
||||||
|
* scrolled fully out of the viewport can still report "displayed"), so the
|
||||||
|
* prefill test asserts the time-range card IS displayed (positive assertion)
|
||||||
|
* rather than that the station card is NOT.
|
||||||
|
*/
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||||
|
@Config(sdk = [34], qualifiers = "w411dp-h891dp-port")
|
||||||
|
class MutualMatchPrefillScrollTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeRule = createComposeRule()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun sanity_textRenders() {
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Text("sanity-check-text")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.onNodeWithText("sanity-check-text").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun scrollToItemLandsAtTop() {
|
||||||
|
// Guards the mechanism the prefill relies on: scrollToItem(1) from a
|
||||||
|
// LaunchedEffect moves item 1 to the top of the viewport.
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
val state = remember { LazyListState(firstVisibleItemIndex = 0) }
|
||||||
|
LaunchedEffect(Unit) { state.scrollToItem(1) }
|
||||||
|
LazyColumn(state = state) {
|
||||||
|
item { Text("min-item-0") }
|
||||||
|
item { Text("min-item-1") }
|
||||||
|
item { Text("min-item-2") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
composeRule.onNodeWithText("min-item-1").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun defaultOpen_showsStationInputsAtTop() {
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
MutualScreen(viewModel = vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Without a prefill the list starts at item 0 (station inputs).
|
||||||
|
composeRule.onNodeWithText("Your Station").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun prefillFromMap_opensAtTimeRangeCard() {
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
// Same call the map grid-QSO "Match" button makes.
|
||||||
|
vm.prefillMatchFromGrid("OL62")
|
||||||
|
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
MutualScreen(viewModel = vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
|
// The time-range card must be visible at the top of the page after the
|
||||||
|
// prefill scroll.
|
||||||
|
composeRule.onNodeWithText("Time range").assertIsDisplayed()
|
||||||
|
// The snapshotFlow write-back stores the scrolled position in the VM.
|
||||||
|
// It equals 1 only if scrollToItem(1) REALLY scrolled the station card
|
||||||
|
// out. If the list content is shorter than the viewport there is no
|
||||||
|
// scroll range, scrollToItem cannot move, and this stays 0 — that is
|
||||||
|
// exactly the device symptom ("page stays at the top").
|
||||||
|
org.junit.Assert.assertEquals(
|
||||||
|
"list must have actually scrolled to item 1 (content shorter than viewport?)",
|
||||||
|
1, vm.listScrollIndex
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun prefillAutoStartsQueryAndFillsState() {
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
vm.prefillMatchFromGrid("OL62")
|
||||||
|
val s = vm.uiState.value
|
||||||
|
// Query auto-started: with the empty-satellite fake the query reaches
|
||||||
|
// the "no satellite data" guard (rather than never being triggered),
|
||||||
|
// proving prefillMatchFromGrid kicks off queryMutualPasses.
|
||||||
|
assertTrue(
|
||||||
|
"auto-query should reach the satellite guard: gridA=${s.stationAGrid} " +
|
||||||
|
"gridB=${s.stationBGrid} err=${s.errorMessage}",
|
||||||
|
s.errorMessage?.contains("satellite", ignoreCase = true) == true
|
||||||
|
)
|
||||||
|
// ...and the target grid + 24h range pre-filled.
|
||||||
|
org.junit.Assert.assertEquals("OL62", s.stationBGrid)
|
||||||
|
org.junit.Assert.assertEquals(24, s.hoursAhead)
|
||||||
|
// ...and navigation to the match page is pending until the query done.
|
||||||
|
assertTrue("navigation should be pending", s.pendingNavigation)
|
||||||
|
// The early-return guard means the query finished immediately (no
|
||||||
|
// satellites): the map page must now be free to navigate.
|
||||||
|
org.junit.Assert.assertFalse("query finished -> not calculating", s.isCalculating)
|
||||||
|
vm.consumePendingNavigation()
|
||||||
|
org.junit.Assert.assertFalse("consume clears pending navigation", vm.uiState.value.pendingNavigation)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun navDisplayEntryAfterPrefill_scrollsToTimeRange() {
|
||||||
|
// The Mutual screen composed inside a NavDisplay entry (back stack
|
||||||
|
// [Mutual]) right after prefillMatchFromGrid.
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
vm.prefillMatchFromGrid("OL62")
|
||||||
|
composeRule.setContent {
|
||||||
|
val backStack = rememberNavBackStack(Screen.Mutual)
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
NavDisplay(
|
||||||
|
backStack = backStack,
|
||||||
|
onBack = { backStack.removeLastOrNull() },
|
||||||
|
entryProvider = entryProvider {
|
||||||
|
entry<Screen.Mutual> { MutualScreen(viewModel = vm) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
composeRule.onNodeWithText("Time range").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun navDisplay_switchToMutualEntry_scrollsToTimeRange() {
|
||||||
|
// Closest device path: start on the Map entry, then push the Mutual
|
||||||
|
// entry (what the map "Match" button does). NavDisplay runs a real
|
||||||
|
// fade transition while the Mutual screen composes.
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
vm.prefillMatchFromGrid("OL62")
|
||||||
|
val backStackRef = mutableStateOf<NavBackStack<NavKey>?>(null)
|
||||||
|
composeRule.setContent {
|
||||||
|
val backStack = rememberNavBackStack(Screen.Map)
|
||||||
|
backStackRef.value = backStack
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
NavDisplay(
|
||||||
|
backStack = backStack,
|
||||||
|
onBack = { backStack.removeLastOrNull() },
|
||||||
|
entryProvider = entryProvider {
|
||||||
|
entry<Screen.Map> { Text("MAP PAGE") }
|
||||||
|
entry<Screen.Mutual> { MutualScreen(viewModel = vm) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
// Push Mutual like onMatchGrid does, so the transition composes
|
||||||
|
// MutualScreen with scrollToTimeRange already set.
|
||||||
|
composeRule.runOnIdle { backStackRef.value?.add(Screen.Mutual) }
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
composeRule.onNodeWithText("Time range").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun scrollRetriesUntilContentGrows() {
|
||||||
|
// Reproduces the real-device mechanism: the first frame's content
|
||||||
|
// (item 0 short) is shorter than the viewport, so scrollToItem(1) has
|
||||||
|
// no range and cannot move. Then the content grows (async results)
|
||||||
|
// past one screen; the retry loop must land on item 1.
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
val tall = mutableStateOf(false)
|
||||||
|
LaunchedEffect(Unit) { delay(300); tall.value = true }
|
||||||
|
val state = remember { LazyListState() }
|
||||||
|
LaunchedEffect(state) {
|
||||||
|
// Same retry loop MutualScreen uses for the prefill.
|
||||||
|
for (attempt in 0 until 20) {
|
||||||
|
state.scrollToItem(1)
|
||||||
|
if (state.firstVisibleItemIndex == 1) return@LaunchedEffect
|
||||||
|
delay(100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LazyColumn(state = state) {
|
||||||
|
item {
|
||||||
|
if (tall.value) Spacer(modifier = Modifier.height(900.dp))
|
||||||
|
else Spacer(modifier = Modifier.height(40.dp))
|
||||||
|
}
|
||||||
|
item { Text("target-item") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
composeRule.onNodeWithText("target-item").assertIsDisplayed()
|
||||||
|
// Confirm the list really scrolled (station card equivalent is gone).
|
||||||
|
// We can't read listState from here, so use the VM-style probe: none —
|
||||||
|
// the target visible + viewport tall enough implies item 1 on top.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun keepPositionAcrossTabs_thenMapMatchPrefill_scrollsToTimeRange() {
|
||||||
|
// User hypothesis: the "keep scroll position across tab switches"
|
||||||
|
// machinery (listState remember(queryGeneration) + snapshotFlow
|
||||||
|
// write-back) interferes with the prefill auto-scroll. Reproduce the
|
||||||
|
// full journey: first visit -> scroll a bit -> leave -> return
|
||||||
|
// (position restored) -> leave -> enter via map Match button.
|
||||||
|
val vm = MutualViewModel(FakeSatelliteRepo(), FakeSettingsRepo())
|
||||||
|
val showMutual = mutableStateOf(true)
|
||||||
|
|
||||||
|
// First visit (e.g. bottom nav), user scrolls a little; the
|
||||||
|
// snapshotFlow write-back stored index/offset in the VM.
|
||||||
|
composeRule.setContent {
|
||||||
|
MaterialTheme {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
if (showMutual.value) MutualScreen(viewModel = vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
vm.listScrollIndex = 0
|
||||||
|
vm.listScrollOffset = 40
|
||||||
|
|
||||||
|
// Leave the page (tab switch destroys the composition).
|
||||||
|
showMutual.value = false
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
|
// Re-enter: keep-position restores the scroll offset.
|
||||||
|
showMutual.value = true
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
|
// Leave again, then enter via the map grid-QSO Match button.
|
||||||
|
showMutual.value = false
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
vm.prefillMatchFromGrid("OL62")
|
||||||
|
showMutual.value = true
|
||||||
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
|
composeRule.onNodeWithText("Time range").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -285,4 +285,39 @@ class MutualViewModelTest {
|
|||||||
|
|
||||||
assertNull(vm.uiState.value.errorMessage)
|
assertNull(vm.uiState.value.errorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `requery keeps scroll position and stale results while running`() = runTest(mainDispatcherRule.dispatcher.scheduler) {
|
||||||
|
val windows = TestOrbits.findPassWindows()
|
||||||
|
assertTrue("fixture must produce ISS windows", windows.isNotEmpty())
|
||||||
|
val vm = createVm(
|
||||||
|
satellites = listOf(TestOrbits.ISS),
|
||||||
|
passes = windows
|
||||||
|
)
|
||||||
|
vm.onStationBGrid("OL62")
|
||||||
|
queryAndSettle(vm)
|
||||||
|
assertTrue("fixture must yield passes", vm.uiState.value.mutualPasses.isNotEmpty())
|
||||||
|
|
||||||
|
// The user scrolled into the results; the snapshotFlow write-back has
|
||||||
|
// stored this position in the VM.
|
||||||
|
vm.listScrollIndex = 4
|
||||||
|
vm.listScrollOffset = 137
|
||||||
|
|
||||||
|
// Re-run the query from the match page ("query" button).
|
||||||
|
vm.queryMutualPasses()
|
||||||
|
|
||||||
|
// While the query runs, the old results stay on screen (the list keeps
|
||||||
|
// its height, so the scroll position is not clamped away)...
|
||||||
|
assertTrue("stale results kept while calculating", vm.uiState.value.mutualPasses.isNotEmpty())
|
||||||
|
// ...and the scroll position must not be reset to the top.
|
||||||
|
assertEquals(4, vm.listScrollIndex)
|
||||||
|
assertEquals(137, vm.listScrollOffset)
|
||||||
|
|
||||||
|
advanceUntilIdle()
|
||||||
|
assertFalse(vm.uiState.value.isCalculating)
|
||||||
|
assertTrue("fresh results replace the stale ones", vm.uiState.value.mutualPasses.isNotEmpty())
|
||||||
|
// Position intact after the query settled.
|
||||||
|
assertEquals(4, vm.listScrollIndex)
|
||||||
|
assertEquals(137, vm.listScrollOffset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
[versions]
|
[versions]
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
appVersionCode = "487"
|
appVersionCode = "495"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
appVersionName = "4.4.7-ba7opf.12.1"
|
appVersionName = "4.4.7-ba7opf.14.1"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
compileSdk = "37"
|
compileSdk = "37"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
@@ -33,6 +33,8 @@ other-okhttp = "5.4.0"
|
|||||||
other-osmdroid = "6.1.20"
|
other-osmdroid = "6.1.20"
|
||||||
|
|
||||||
test-junit4 = "4.13.2"
|
test-junit4 = "4.13.2"
|
||||||
|
robolectric = "4.16"
|
||||||
|
androidx-test-core = "1.7.0"
|
||||||
|
|
||||||
androidTest-junit = "1.3.0"
|
androidTest-junit = "1.3.0"
|
||||||
androidTest-espresso = "3.7.0"
|
androidTest-espresso = "3.7.0"
|
||||||
@@ -79,6 +81,9 @@ other-osmdroid = { module = "org.osmdroid:osmdroid-android", version.ref = "othe
|
|||||||
|
|
||||||
test-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlin-coroutines" }
|
test-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlin-coroutines" }
|
||||||
test-junit4 = { module = "junit:junit", version.ref = "test-junit4" }
|
test-junit4 = { module = "junit:junit", version.ref = "test-junit4" }
|
||||||
|
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
|
||||||
|
androidx-test-core = { module = "androidx.test:core-ktx", version.ref = "androidx-test-core" }
|
||||||
|
compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||||
# Real org.json for unit tests (android.jar stub throws "not mocked")
|
# Real org.json for unit tests (android.jar stub throws "not mocked")
|
||||||
test-json = { module = "org.json:json", version = "20240303" }
|
test-json = { module = "org.json:json", version = "20240303" }
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user