mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-06 04:27:29 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8138c948b | ||
|
|
0e28231c4a | ||
|
|
d6bdf5ecb6 | ||
|
|
6962a4bfa1 | ||
|
|
94a1a4f7b7 | ||
|
|
dbf2229774 | ||
|
|
f2fc1b7b28 | ||
|
|
d600836e19 | ||
|
|
94bffe80b0 | ||
|
|
4260fbb096 |
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)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -423,6 +428,7 @@ private fun MapScreen(
|
|||||||
grid = grid,
|
grid = grid,
|
||||||
qsos = uiState.workedGridQsos[grid].orEmpty().sortedBy { it.epochMs },
|
qsos = uiState.workedGridQsos[grid].orEmpty().sortedBy { it.epochMs },
|
||||||
isUtc = uiState.isUtc,
|
isUtc = uiState.isUtc,
|
||||||
|
matchCalculating = matchCalculating,
|
||||||
onDismiss = { selectedGrid = null },
|
onDismiss = { selectedGrid = null },
|
||||||
onMatch = { onMatchGrid(grid) }
|
onMatch = { onMatchGrid(grid) }
|
||||||
)
|
)
|
||||||
@@ -436,6 +442,7 @@ 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>,
|
||||||
isUtc: Boolean,
|
isUtc: Boolean,
|
||||||
|
matchCalculating: Boolean,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onMatch: () -> Unit
|
onMatch: () -> Unit
|
||||||
) {
|
) {
|
||||||
@@ -467,16 +474,24 @@ 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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ dependencies {
|
|||||||
testImplementation(libs.robolectric)
|
testImplementation(libs.robolectric)
|
||||||
testImplementation(libs.androidx.test.core)
|
testImplementation(libs.androidx.test.core)
|
||||||
testImplementation(libs.compose.ui.test.junit4)
|
testImplementation(libs.compose.ui.test.junit4)
|
||||||
|
testImplementation(libs.compose.navigation3)
|
||||||
debugImplementation(libs.compose.debug.manifest)
|
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)
|
||||||
) {
|
) {
|
||||||
@@ -377,14 +397,36 @@ private fun MutualContent(
|
|||||||
// LazyListState at index 1: the constructor parameter is ignored by this
|
// LazyListState at index 1: the constructor parameter is ignored by this
|
||||||
// Compose version (verified in tests), while scrollToItem lands correctly.
|
// Compose version (verified in tests), while scrollToItem lands correctly.
|
||||||
val matchSearchIndex = if (state.errorMessage != null) 2 else 1
|
val matchSearchIndex = if (state.errorMessage != null) 2 else 1
|
||||||
LaunchedEffect(state.scrollToTimeRange, matchSearchIndex) {
|
LaunchedEffect(state.scrollToTimeRange, matchSearchIndex, listReady) {
|
||||||
if (state.scrollToTimeRange) {
|
Log.d(TAG, "scroll effect: scrollToTimeRange=${state.scrollToTimeRange} matchIndex=$matchSearchIndex listReady=$listReady")
|
||||||
listState.scrollToItem(matchSearchIndex)
|
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()
|
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
|
||||||
|
|||||||
+46
-12
@@ -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 = "",
|
||||||
@@ -59,7 +61,12 @@ data class MutualUiState(
|
|||||||
// One-shot flag set by prefillMatchFromGrid() (map grid → Match button):
|
// One-shot flag set by prefillMatchFromGrid() (map grid → Match button):
|
||||||
// the page scrolls to the time-range card after the first layout, then
|
// the page scrolls to the time-range card after the first layout, then
|
||||||
// consumeScrollToTimeRange() clears it.
|
// consumeScrollToTimeRange() clears it.
|
||||||
val scrollToTimeRange: Boolean = false
|
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(
|
||||||
@@ -197,23 +204,40 @@ class MutualViewModel(
|
|||||||
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
|
scrollToTimeRange = true,
|
||||||
|
pendingNavigation = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
queryMutualPasses()
|
queryMutualPasses()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun consumePendingNavigation() {
|
||||||
|
android.util.Log.d(TAG, "consumePendingNavigation")
|
||||||
|
_uiState.update { it.copy(pendingNavigation = false) }
|
||||||
|
}
|
||||||
|
|
||||||
fun consumeScrollToTimeRange() {
|
fun consumeScrollToTimeRange() {
|
||||||
|
android.util.Log.d(TAG, "consumeScrollToTimeRange")
|
||||||
_uiState.update { it.copy(scrollToTimeRange = false) }
|
_uiState.update { it.copy(scrollToTimeRange = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun queryMutualPasses(initialScrollIndex: Int = 0) {
|
/**
|
||||||
|
* 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
|
||||||
@@ -236,16 +260,19 @@ 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 {
|
||||||
@@ -254,8 +281,15 @@ class MutualViewModel(
|
|||||||
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)
|
||||||
|
}
|
||||||
|
} 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()) {
|
||||||
|
|||||||
+162
-1
@@ -1,6 +1,8 @@
|
|||||||
package com.rtbishop.look4sat.feature.mutual
|
package com.rtbishop.look4sat.feature.mutual
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -8,10 +10,19 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.test.assertIsDisplayed
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.test.junit4.createComposeRule
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
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.Assert.assertTrue
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -38,7 +49,7 @@ import org.robolectric.annotation.GraphicsMode
|
|||||||
*/
|
*/
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||||
@Config(sdk = [34])
|
@Config(sdk = [34], qualifiers = "w411dp-h891dp-port")
|
||||||
class MutualMatchPrefillScrollTest {
|
class MutualMatchPrefillScrollTest {
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
@@ -108,6 +119,15 @@ class MutualMatchPrefillScrollTest {
|
|||||||
// The time-range card must be visible at the top of the page after the
|
// The time-range card must be visible at the top of the page after the
|
||||||
// prefill scroll.
|
// prefill scroll.
|
||||||
composeRule.onNodeWithText("Time range").assertIsDisplayed()
|
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
|
@Test
|
||||||
@@ -126,5 +146,146 @@ class MutualMatchPrefillScrollTest {
|
|||||||
// ...and the target grid + 24h range pre-filled.
|
// ...and the target grid + 24h range pre-filled.
|
||||||
org.junit.Assert.assertEquals("OL62", s.stationBGrid)
|
org.junit.Assert.assertEquals("OL62", s.stationBGrid)
|
||||||
org.junit.Assert.assertEquals(24, s.hoursAhead)
|
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 = "488"
|
appVersionCode = "493"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
appVersionName = "4.4.7-ba7opf.12.2"
|
appVersionName = "4.4.7-ba7opf.13"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
compileSdk = "37"
|
compileSdk = "37"
|
||||||
#noinspection UnusedVersionCatalogEntry
|
#noinspection UnusedVersionCatalogEntry
|
||||||
|
|||||||
Reference in new issue
Block a user