diff options
author | 2024-02-16 13:38:30 -0500 | |
---|---|---|
committer | 2024-02-16 13:38:30 -0500 | |
commit | eb2c6935518e781ca0651bca69ddb2e306daa05a (patch) | |
tree | 6ed021ba42bad49604bb7674d4cb34ef4ecb0f12 /java/src | |
parent | cfb60519c7cd3de3e4a0041f73a7c344627eb389 (diff) |
Change UserInteractor availability interface
This does the following:
1) Keeps availability information per-Profile, and not per-Type because
there isn't a requirement to enforce a single instance per type at
this layer, and this requirement may come along in the future.
2) changes `fun isAvailable(Profile.Type: Flow<Boolean>` to
`val availability: Flow<Map<Profile, Boolean>>` which is easier to
consume downstream as a StateFlow without additional bookeeping of
maintaining individual flows. Changes can be easily processed by
using a runningFold and taking the difference in the two maps.
Test: atest UserInteractorTest
Bug: n/a
Flag: n/a (code is not yet live)
Change-Id: I8605c42bead70b4bf41fdf89c195311b85938b1b
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt b/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt index c8df9684..72b604c2 100644 --- a/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt +++ b/java/src/com/android/intentresolver/v2/domain/interactor/UserInteractor.kt @@ -26,9 +26,7 @@ import com.android.intentresolver.v2.shared.model.User.Role import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.mapNotNull /** The high level User interface. */ class UserInteractor @@ -67,20 +65,16 @@ constructor( it.primary.id == launchedAs.identifier || it.clone?.id == launchedAs.identifier } } - /** - * Provides a flow to report on the availability of the profile. An unavailable profile may be + * Provides a flow to report on the availability of profile. An unavailable profile may be * hidden or appear disabled within the app. */ - fun isAvailable(type: Type): Flow<Boolean> { - val profileFlow = profiles.map { list -> list.firstOrNull { it.type == type } } - return combine(profileFlow, userRepository.availability) { profile, availability -> - when (profile) { - null -> false - else -> availability.getOrDefault(profile.primary, false) + val availability: Flow<Map<Profile, Boolean>> = + combine(profiles, userRepository.availability) { profiles, availability -> + profiles.associateWith { + availability.getOrDefault(it.primary, false) } } - } /** * Request the profile state be updated. In the case of enabling, the operation could take |