From 5c2c8581bf6858642d2139284da3dea3c0c2233b Mon Sep 17 00:00:00 2001 From: Joseph Roque Date: Sat, 14 Sep 2024 12:13:07 -0700 Subject: [PATCH] fix(android): set picker results to null instead of removing Prevents an issue where removing the key actually removes all of the listeners. Setting to null will keep the listeners, and each listener filtersNotNull already --- .../core/navigation/AvatarFormResultViewModel.kt | 2 +- .../core/navigation/GamesSettingsResultViewModel.kt | 2 +- .../bowlingcompanion/core/navigation/LaneFormResultViewModel.kt | 2 +- .../core/navigation/ResourcePickerResultViewModel.kt | 2 +- .../core/navigation/ScoreEditorResultViewModel.kt | 2 +- .../core/navigation/SeriesFormResultViewModel.kt | 2 +- .../core/navigation/StatisticPickerResultViewModel.kt | 2 +- .../bowlingcompanion/feature/quickplay/QuickPlayViewModel.kt | 1 + 8 files changed, 8 insertions(+), 7 deletions(-) diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/AvatarFormResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/AvatarFormResultViewModel.kt index de74b7386..6c54b3462 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/AvatarFormResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/AvatarFormResultViewModel.kt @@ -19,7 +19,7 @@ class AvatarFormResultViewModel @Inject constructor( fun getAvatar() = savedStateHandle .getStateFlow(AVATAR_FORM_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(AVATAR_FORM_RESULT_KEY) } + .onEach { savedStateHandle.set(AVATAR_FORM_RESULT_KEY, null) } .map { Avatar.fromString(it) } fun setResult(result: Avatar) { diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/GamesSettingsResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/GamesSettingsResultViewModel.kt index 3c09fe4c2..4e8e36c4a 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/GamesSettingsResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/GamesSettingsResultViewModel.kt @@ -20,7 +20,7 @@ class GamesSettingsResultViewModel @Inject constructor( fun getResult() = savedStateHandle .getStateFlow(GAMES_SETTINGS_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(GAMES_SETTINGS_RESULT_KEY) } + .onEach { savedStateHandle.set(GAMES_SETTINGS_RESULT_KEY, null) } .map { val (seriesIds, gameId) = it.split(":") Pair(seriesIds.split(",").map { id -> SeriesID.fromString(id) }, GameID.fromString(gameId)) diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/LaneFormResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/LaneFormResultViewModel.kt index 837db983e..84a896461 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/LaneFormResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/LaneFormResultViewModel.kt @@ -18,7 +18,7 @@ class LaneFormResultViewModel @Inject constructor(private val savedStateHandle: fun getLanes() = savedStateHandle .getStateFlow(LANE_FORM_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(LANE_FORM_RESULT_KEY) } + .onEach { savedStateHandle.set(LANE_FORM_RESULT_KEY, null) } .map { it.split(",").map { id -> LaneID.fromString(id) } } fun setResult(result: List) { diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ResourcePickerResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ResourcePickerResultViewModel.kt index e227c4a8a..36d7cd042 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ResourcePickerResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ResourcePickerResultViewModel.kt @@ -25,7 +25,7 @@ class ResourcePickerResultViewModel @Inject constructor( .getStateFlow?>(key.value, null) .filterNotNull() .map { - savedStateHandle.remove>(key.value) + savedStateHandle.set>(key.value, null) it.map { id -> parse(id) }.toSet() } diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ScoreEditorResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ScoreEditorResultViewModel.kt index 2f2fbe9f1..2677010ae 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ScoreEditorResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/ScoreEditorResultViewModel.kt @@ -19,7 +19,7 @@ class ScoreEditorResultViewModel @Inject constructor( fun getScore() = savedStateHandle .getStateFlow(SCORE_EDITOR_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(SCORE_EDITOR_RESULT_KEY) } + .onEach { savedStateHandle.set(SCORE_EDITOR_RESULT_KEY, null) } .map { val (method, score) = it.split(":") GameScoringMethod.valueOf(method) to score.toInt() diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/SeriesFormResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/SeriesFormResultViewModel.kt index f02005a80..76dab8f40 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/SeriesFormResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/SeriesFormResultViewModel.kt @@ -19,7 +19,7 @@ class SeriesFormResultViewModel @Inject constructor( fun getSeriesID() = savedStateHandle .getStateFlow(SERIES_FORM_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(SERIES_FORM_RESULT_KEY) } + .onEach { savedStateHandle.set(SERIES_FORM_RESULT_KEY, null) } .map { SeriesID.fromString(it) } fun setResult(result: SeriesID) { diff --git a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/StatisticPickerResultViewModel.kt b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/StatisticPickerResultViewModel.kt index 06cdaaf41..474adfc38 100644 --- a/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/StatisticPickerResultViewModel.kt +++ b/android/core/navigation/src/main/java/ca/josephroque/bowlingcompanion/core/navigation/StatisticPickerResultViewModel.kt @@ -19,7 +19,7 @@ class StatisticPickerResultViewModel @Inject constructor( fun getStatisticID() = savedStateHandle .getStateFlow(STATISTIC_PICKER_RESULT_KEY, null) .filterNotNull() - .onEach { savedStateHandle.remove(STATISTIC_PICKER_RESULT_KEY) } + .onEach { savedStateHandle.set(STATISTIC_PICKER_RESULT_KEY, null) } .map { StatisticID.valueOf(it) } fun setResult(result: StatisticID) { diff --git a/android/feature/quickplay/src/main/java/ca/josephroque/bowlingcompanion/feature/quickplay/QuickPlayViewModel.kt b/android/feature/quickplay/src/main/java/ca/josephroque/bowlingcompanion/feature/quickplay/QuickPlayViewModel.kt index 8cc9c2205..1db2f02c7 100644 --- a/android/feature/quickplay/src/main/java/ca/josephroque/bowlingcompanion/feature/quickplay/QuickPlayViewModel.kt +++ b/android/feature/quickplay/src/main/java/ca/josephroque/bowlingcompanion/feature/quickplay/QuickPlayViewModel.kt @@ -196,6 +196,7 @@ class QuickPlayViewModel @Inject constructor( private fun updateBowlerLeague(leagueId: LeagueID?) { val bowlerId = selectingLeagueForBowler ?: return + selectingLeagueForBowler = null if (leagueId == null) { if (isTeamQuickPlay) {