Skip to content

Commit dbce7be

Browse files
committed
fix: keep radar section selection stable
1 parent e9cc12e commit dbce7be

3 files changed

Lines changed: 13 additions & 45 deletions

File tree

feature/radar/src/main/java/io/blueeye/feature/radar/presentation/RadarScreen.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fun RadarScreen(
6363
val showClearDialog = remember { mutableStateOf(false) }
6464
val showFilterDialog = remember { mutableStateOf(false) }
6565
val showActiveCollectionDialog = remember { mutableStateOf(false) }
66-
var selectedSectionView by rememberSaveable { mutableStateOf<RadarSectionViewType?>(null) }
66+
var selectedSectionView by rememberSaveable { mutableStateOf(RadarSectionViewType.ALL) }
6767

6868
if (showClearDialog.value) {
6969
AlertDialog(
@@ -235,9 +235,6 @@ fun RadarScreen(
235235
onClick = { onDeviceClick(item.fingerprint) },
236236
onWatchlistClick = { device ->
237237
viewModel.toggleWatchlist(device)
238-
if (!device.isInWatchlist) {
239-
selectedSectionView = RadarSectionViewType.WATCHLIST
240-
}
241238
},
242239
onCalibrationClick = { device, label ->
243240
viewModel.updateCalibrationLabel(device, label)
@@ -450,15 +447,13 @@ private fun scannerEmptyText(scannerState: ScannerRuntimeState): String {
450447
}
451448

452449
private fun resolveRadarSectionView(
453-
selectedSectionView: RadarSectionViewType?,
450+
selectedSectionView: RadarSectionViewType,
454451
options: List<RadarSectionViewOption>,
455452
): RadarSectionViewType =
456-
selectedSectionView?.let { requestedView ->
457-
RadarSectionViewMapper.resolveSelectedView(
458-
requested = requestedView,
459-
options = options,
460-
)
461-
} ?: RadarSectionViewMapper.defaultView(options)
453+
RadarSectionViewMapper.resolveSelectedView(
454+
requested = selectedSectionView,
455+
options = options,
456+
)
462457

463458
private object RadarSectionHeaderDefaults {
464459
const val STATUS_CONTAINER_ALPHA = 0.12f

feature/radar/src/main/java/io/blueeye/feature/radar/presentation/RadarSectionViewMapper.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ object RadarSectionViewMapper {
3535
}
3636
}
3737

38-
fun defaultView(options: List<RadarSectionViewOption>): RadarSectionViewType =
39-
DEFAULT_VIEW_PRIORITY.firstOrNull { view ->
40-
options.any { option -> option.type == view && option.count > 0 }
41-
} ?: RadarSectionViewType.ALL
42-
4338
fun resolveSelectedView(
4439
requested: RadarSectionViewType,
4540
options: List<RadarSectionViewOption>,
@@ -85,13 +80,4 @@ object RadarSectionViewMapper {
8580
RadarSectionViewType.NEARBY,
8681
RadarSectionViewType.UNKNOWN_NOISE,
8782
)
88-
89-
private val DEFAULT_VIEW_PRIORITY =
90-
listOf(
91-
RadarSectionViewType.WATCHLIST,
92-
RadarSectionViewType.SUSPICIOUS,
93-
RadarSectionViewType.PUBLIC_SAFETY,
94-
RadarSectionViewType.NEARBY,
95-
RadarSectionViewType.UNKNOWN_NOISE,
96-
)
9783
}

feature/radar/src/test/java/io/blueeye/feature/radar/presentation/RadarSectionViewMapperTest.kt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,23 @@ class RadarSectionViewMapperTest {
7676
}
7777

7878
@Test
79-
fun `default view opens watchlist before suspicious attention section`() {
79+
fun `all view remains selected when attention sections are present`() {
8080
val options =
8181
RadarSectionViewMapper.options(
8282
listOf(
83-
section(RadarUiSectionType.WATCHLIST, count = 1),
8483
section(RadarUiSectionType.SUSPICIOUS, count = 2),
85-
section(RadarUiSectionType.PUBLIC_SAFETY, count = 1),
86-
section(RadarUiSectionType.UNKNOWN_NOISE, count = 8),
87-
),
88-
)
89-
90-
assertEquals(RadarSectionViewType.WATCHLIST, RadarSectionViewMapper.defaultView(options))
91-
}
92-
93-
@Test
94-
fun `default view falls back to nearby before noise`() {
95-
val options =
96-
RadarSectionViewMapper.options(
97-
listOf(
9884
section(RadarUiSectionType.NEARBY, count = 4),
9985
section(RadarUiSectionType.UNKNOWN_NOISE, count = 9),
10086
),
10187
)
10288

103-
assertEquals(RadarSectionViewType.NEARBY, RadarSectionViewMapper.defaultView(options))
104-
}
89+
val selected =
90+
RadarSectionViewMapper.resolveSelectedView(
91+
requested = RadarSectionViewType.ALL,
92+
options = options,
93+
)
10594

106-
@Test
107-
fun `default view is all when options are empty`() {
108-
assertEquals(RadarSectionViewType.ALL, RadarSectionViewMapper.defaultView(emptyList()))
95+
assertEquals(RadarSectionViewType.ALL, selected)
10996
}
11097

11198
@Test

0 commit comments

Comments
 (0)