SettingsManager: use Flows instead of LiveData #714
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uses Flow instead of LiveData to provide observable settings.
callbackFlow
is used with theSettingsManager.addOnChangeListener
.collectAsStateWithLifecycle
is used to collect the flow lifecycle-aware: if the Activity is paused, the flow will be stopped; if it's resumed, it will be started again..asLiveData()
is used so that existing code that uses settings LiveData doesn't have to be rewritten in this PR.In the
AccountDetailsPage
, there was a problem with the initial value ofgroupMethod
:forcedGroupMethod
may benull
at the first composition and then be updated. Now updated values offorcedGroupMethod
are forced into thegroupMethod
. In this context, we're also usingFlow.map
.In
TaskUtils.currentProviderFlow
, I have usedstateIn
to make theSELECTED_TASK_PROVIDER
setting flow hot and stateful: the initial value and then incoming updates will be collected to a current state (StateFlow) so that the result always has a correctvalue
.@ArnyminerZ @sunkup I think this is how we could use Flows in the future (as discussed yesterday). Please test / have a look and tell me your thoughts.