From eb2c6935518e781ca0651bca69ddb2e306daa05a Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Fri, 16 Feb 2024 13:38:30 -0500 Subject: 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` to `val availability: Flow>` 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 --- .../v2/domain/interactor/UserInteractor.kt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'java/src') 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 { - 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> = + 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 -- cgit v1.2.3-59-g8ed1b