Skip to content

Commit

Permalink
fix(android): set picker results to null instead of removing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
autoreleasefool committed Sep 14, 2024
1 parent e8f231a commit 5c2c858
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AvatarFormResultViewModel @Inject constructor(
fun getAvatar() = savedStateHandle
.getStateFlow<String?>(AVATAR_FORM_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(AVATAR_FORM_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(AVATAR_FORM_RESULT_KEY, null) }
.map { Avatar.fromString(it) }

fun setResult(result: Avatar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GamesSettingsResultViewModel @Inject constructor(
fun getResult() = savedStateHandle
.getStateFlow<String?>(GAMES_SETTINGS_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(GAMES_SETTINGS_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(GAMES_SETTINGS_RESULT_KEY, null) }
.map {
val (seriesIds, gameId) = it.split(":")
Pair(seriesIds.split(",").map { id -> SeriesID.fromString(id) }, GameID.fromString(gameId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LaneFormResultViewModel @Inject constructor(private val savedStateHandle:
fun getLanes() = savedStateHandle
.getStateFlow<String?>(LANE_FORM_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(LANE_FORM_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(LANE_FORM_RESULT_KEY, null) }
.map { it.split(",").map { id -> LaneID.fromString(id) } }

fun setResult(result: List<LaneID>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResourcePickerResultViewModel @Inject constructor(
.getStateFlow<Set<UUID>?>(key.value, null)
.filterNotNull()
.map {
savedStateHandle.remove<Set<UUID>>(key.value)
savedStateHandle.set<Set<UUID>>(key.value, null)
it.map { id -> parse(id) }.toSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ScoreEditorResultViewModel @Inject constructor(
fun getScore() = savedStateHandle
.getStateFlow<String?>(SCORE_EDITOR_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(SCORE_EDITOR_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(SCORE_EDITOR_RESULT_KEY, null) }
.map {
val (method, score) = it.split(":")
GameScoringMethod.valueOf(method) to score.toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SeriesFormResultViewModel @Inject constructor(
fun getSeriesID() = savedStateHandle
.getStateFlow<String?>(SERIES_FORM_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(SERIES_FORM_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(SERIES_FORM_RESULT_KEY, null) }
.map { SeriesID.fromString(it) }

fun setResult(result: SeriesID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StatisticPickerResultViewModel @Inject constructor(
fun getStatisticID() = savedStateHandle
.getStateFlow<String?>(STATISTIC_PICKER_RESULT_KEY, null)
.filterNotNull()
.onEach { savedStateHandle.remove<String?>(STATISTIC_PICKER_RESULT_KEY) }
.onEach { savedStateHandle.set<String?>(STATISTIC_PICKER_RESULT_KEY, null) }
.map { StatisticID.valueOf(it) }

fun setResult(result: StatisticID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class QuickPlayViewModel @Inject constructor(

private fun updateBowlerLeague(leagueId: LeagueID?) {
val bowlerId = selectingLeagueForBowler ?: return
selectingLeagueForBowler = null

if (leagueId == null) {
if (isTeamQuickPlay) {
Expand Down

0 comments on commit 5c2c858

Please sign in to comment.