diff options
| author | 2024-05-08 14:16:44 -0400 | |
|---|---|---|
| committer | 2024-05-08 15:58:34 -0400 | |
| commit | 61565bb2fdb7327b84a166b237aaecd6494dc7b3 (patch) | |
| tree | daa8f43b6088eb6a4e9befb05c70eb315a0cf22c | |
| parent | 5044cdfd8c328c68a65653c943c24226fb8aec03 (diff) | |
Rename boolean flow operators to match collections
Flag: NA
Test: make
Change-Id: Ie4ecaa874f14fb5cd84c1b348804401f491474bf
10 files changed, 81 insertions, 40 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/kotlin/BooleanFlowOperatorsTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/kotlin/BooleanFlowOperatorsTest.kt index 03a39f8f07d8..2d8cd930d8fa 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/kotlin/BooleanFlowOperatorsTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/kotlin/BooleanFlowOperatorsTest.kt @@ -23,9 +23,9 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos -import com.android.systemui.util.kotlin.BooleanFlowOperators.and +import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.BooleanFlowOperators.not -import com.android.systemui.util.kotlin.BooleanFlowOperators.or import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -45,21 +45,21 @@ class BooleanFlowOperatorsTest : SysuiTestCase() { @Test fun and_allTrue_returnsTrue() = testScope.runTest { - val result by collectLastValue(and(TRUE, TRUE)) + val result by collectLastValue(allOf(TRUE, TRUE)) assertThat(result).isTrue() } @Test fun and_anyFalse_returnsFalse() = testScope.runTest { - val result by collectLastValue(and(TRUE, FALSE, TRUE)) + val result by collectLastValue(allOf(TRUE, FALSE, TRUE)) assertThat(result).isFalse() } @Test fun and_allFalse_returnsFalse() = testScope.runTest { - val result by collectLastValue(and(FALSE, FALSE, FALSE)) + val result by collectLastValue(allOf(FALSE, FALSE, FALSE)) assertThat(result).isFalse() } @@ -68,7 +68,7 @@ class BooleanFlowOperatorsTest : SysuiTestCase() { testScope.runTest { val flow1 = MutableStateFlow(false) val flow2 = MutableStateFlow(false) - val values by collectValues(and(flow1, flow2)) + val values by collectValues(allOf(flow1, flow2)) assertThat(values).containsExactly(false) flow1.value = true @@ -81,21 +81,21 @@ class BooleanFlowOperatorsTest : SysuiTestCase() { @Test fun or_allTrue_returnsTrue() = testScope.runTest { - val result by collectLastValue(or(TRUE, TRUE)) + val result by collectLastValue(anyOf(TRUE, TRUE)) assertThat(result).isTrue() } @Test fun or_anyTrue_returnsTrue() = testScope.runTest { - val result by collectLastValue(or(FALSE, TRUE, FALSE)) + val result by collectLastValue(anyOf(FALSE, TRUE, FALSE)) assertThat(result).isTrue() } @Test fun or_allFalse_returnsFalse() = testScope.runTest { - val result by collectLastValue(or(FALSE, FALSE, FALSE)) + val result by collectLastValue(anyOf(FALSE, FALSE, FALSE)) assertThat(result).isFalse() } @@ -104,7 +104,7 @@ class BooleanFlowOperatorsTest : SysuiTestCase() { testScope.runTest { val flow1 = MutableStateFlow(false) val flow2 = MutableStateFlow(false) - val values by collectValues(or(flow1, flow2)) + val values by collectValues(anyOf(flow1, flow2)) assertThat(values).containsExactly(false) flow1.value = true diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/AlternateBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/AlternateBouncerInteractor.kt index fa19bf478453..e0334a060ee2 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/AlternateBouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/AlternateBouncerInteractor.kt @@ -29,7 +29,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInterac import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.policy.KeyguardStateController -import com.android.systemui.util.kotlin.BooleanFlowOperators.or +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.time.SystemClock import dagger.Lazy import javax.inject.Inject @@ -78,7 +78,7 @@ constructor( bouncerRepository.alternateBouncerUIAvailable } private val isDozingOrAod: Flow<Boolean> = - or( + anyOf( keyguardTransitionInteractor.get().transitionValue(KeyguardState.DOZING).map { it > 0f }, diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java index beaa170943fd..001e4edf6fa8 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java @@ -206,7 +206,7 @@ class FalsingCollectorImpl implements FalsingCollector { ); final CommunalInteractor communalInteractor = mCommunalInteractorLazy.get(); mJavaAdapter.alwaysCollectFlow( - BooleanFlowOperators.INSTANCE.and( + BooleanFlowOperators.INSTANCE.allOf( communalInteractor.isCommunalEnabled(), communalInteractor.isCommunalShowing()), this::onShowingCommunalHubChanged diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt index 0042915d0cd9..5091a99b2a64 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt @@ -60,9 +60,9 @@ import com.android.systemui.scene.shared.flag.SceneContainerFlag import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.settings.UserTracker import com.android.systemui.smartspace.data.repository.SmartspaceRepository -import com.android.systemui.util.kotlin.BooleanFlowOperators.and +import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.BooleanFlowOperators.not -import com.android.systemui.util.kotlin.BooleanFlowOperators.or import com.android.systemui.util.kotlin.emitOnStart import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher @@ -127,10 +127,10 @@ constructor( /** Whether communal features are enabled and available. */ val isCommunalAvailable: Flow<Boolean> = - and( + allOf( communalSettingsInteractor.isCommunalEnabled, not(keyguardInteractor.isEncryptedOrLockdown), - or(keyguardInteractor.isKeyguardShowing, keyguardInteractor.isDreaming) + anyOf(keyguardInteractor.isKeyguardShowing, keyguardInteractor.isDreaming) ) .distinctUntilChanged() .onEach { available -> diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt index 8390d62b23db..2ccab072d57f 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt @@ -23,7 +23,7 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.settings.UserTracker -import com.android.systemui.util.kotlin.BooleanFlowOperators.or +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.pairwise import com.android.systemui.util.kotlin.sample import javax.inject.Inject @@ -46,7 +46,7 @@ constructor( ) : CoreStartable { override fun start() { - or(communalInteractor.isCommunalAvailable, communalInteractor.editModeOpen) + anyOf(communalInteractor.isCommunalAvailable, communalInteractor.editModeOpen) // Only trigger updates on state changes, ignoring the initial false value. .pairwise(false) .filter { (previous, new) -> previous != new } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGlanceableHubTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGlanceableHubTransitionInteractor.kt index 54d9a78620e5..faab033441c1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGlanceableHubTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromGlanceableHubTransitionInteractor.kt @@ -28,7 +28,7 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled import com.android.systemui.power.domain.interactor.PowerInteractor -import com.android.systemui.util.kotlin.BooleanFlowOperators.and +import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf import com.android.systemui.util.kotlin.BooleanFlowOperators.not import javax.inject.Inject import kotlin.time.Duration.Companion.seconds @@ -148,7 +148,7 @@ constructor( } } else { scope.launch { - and(keyguardInteractor.isKeyguardOccluded, not(keyguardInteractor.isDreaming)) + allOf(keyguardInteractor.isKeyguardOccluded, not(keyguardInteractor.isDreaming)) .filterRelevantKeyguardStateAnd { isOccludedAndNotDreaming -> isOccludedAndNotDreaming } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt index 24a7c512a6a9..bbcea56799ea 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt @@ -42,7 +42,7 @@ import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.statusbar.notification.domain.interactor.NotificationsKeyguardInteractor import com.android.systemui.statusbar.phone.DozeParameters import com.android.systemui.statusbar.phone.ScreenOffAnimationController -import com.android.systemui.util.kotlin.BooleanFlowOperators.or +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.pairwise import com.android.systemui.util.kotlin.sample import com.android.systemui.util.ui.AnimatableEvent @@ -64,7 +64,6 @@ import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart -import kotlinx.coroutines.launch @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton @@ -134,7 +133,7 @@ constructor( private val isOnLockscreen: Flow<Boolean> = combine( keyguardTransitionInteractor.isFinishedInState(LOCKSCREEN).onStart { emit(false) }, - or( + anyOf( keyguardTransitionInteractor.isInTransitionToState(LOCKSCREEN), keyguardTransitionInteractor.isInTransitionFromState(LOCKSCREEN), ), diff --git a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt index 851bfca56359..21825934c851 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt @@ -50,9 +50,9 @@ import com.android.systemui.res.R import com.android.systemui.scene.shared.model.SceneDataSourceDelegator import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.statusbar.phone.SystemUIDialogFactory -import com.android.systemui.util.kotlin.BooleanFlowOperators.and +import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.BooleanFlowOperators.not -import com.android.systemui.util.kotlin.BooleanFlowOperators.or import com.android.systemui.util.kotlin.collectFlow import javax.inject.Inject import kotlinx.coroutines.flow.Flow @@ -148,7 +148,7 @@ constructor( /** Returns a flow that tracks whether communal hub is available. */ fun communalAvailable(): Flow<Boolean> = - or(communalInteractor.isCommunalAvailable, communalInteractor.editModeOpen) + anyOf(communalInteractor.isCommunalAvailable, communalInteractor.editModeOpen) /** * Creates the container view containing the glanceable hub UI. @@ -250,7 +250,7 @@ constructor( // transition to the bouncer would be incorrectly intercepted by the hub. collectFlow( containerView, - or( + anyOf( keyguardInteractor.primaryBouncerShowing, keyguardInteractor.alternateBouncerShowing ), @@ -269,7 +269,7 @@ constructor( ) collectFlow( containerView, - and(shadeInteractor.isAnyFullyExpanded, not(shadeInteractor.isUserInteracting)), + allOf(shadeInteractor.isAnyFullyExpanded, not(shadeInteractor.isUserInteracting)), { shadeShowing = it updateTouchHandlingState() diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt index ac4bd09b1687..f6c1a98d6424 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt @@ -68,8 +68,8 @@ import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.statusbar.notification.stack.domain.interactor.NotificationStackAppearanceInteractor import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor import com.android.systemui.unfold.domain.interactor.UnfoldTransitionInteractor -import com.android.systemui.util.kotlin.BooleanFlowOperators.and -import com.android.systemui.util.kotlin.BooleanFlowOperators.or +import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf +import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import com.android.systemui.util.kotlin.FlowDumperImpl import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine import javax.inject.Inject @@ -246,7 +246,7 @@ constructor( keyguardTransitionInteractor.finishedKeyguardState.map { state -> state == GLANCEABLE_HUB }, - or( + anyOf( keyguardTransitionInteractor.isInTransitionToState(GLANCEABLE_HUB), keyguardTransitionInteractor.isInTransitionFromState(GLANCEABLE_HUB), ), @@ -424,14 +424,14 @@ constructor( while (currentCoroutineContext().isActive) { emit(false) // Ensure states are inactive to start - and( + allOf( *toFlowArray(statesForHiddenKeyguard) { state -> keyguardTransitionInteractor.transitionValue(state).map { it == 0f } } ) .first { it } // Wait for a qualifying transition to begin - or( + anyOf( *toFlowArray(statesForHiddenKeyguard) { state -> keyguardTransitionInteractor .transitionStepsToState(state) @@ -446,7 +446,7 @@ constructor( // it is considered safe to reset alpha to 1f for HUNs. combine( keyguardInteractor.statusBarState, - and( + allOf( *toFlowArray(statesForHiddenKeyguard) { state -> keyguardTransitionInteractor.transitionValue(state).map { it == 0f diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/BooleanFlowOperators.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/BooleanFlowOperators.kt index b3008856d370..a2759c6bf470 100644 --- a/packages/SystemUI/src/com/android/systemui/util/kotlin/BooleanFlowOperators.kt +++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/BooleanFlowOperators.kt @@ -28,11 +28,23 @@ object BooleanFlowOperators { * * Usage: * ``` - * val result = and(flow1, flow2) + * val result = allOf(flow1, flow2) * ``` */ - fun and(vararg flows: Flow<Boolean>): Flow<Boolean> = - combine(flows.asIterable()) { values -> values.all { it } }.distinctUntilChanged() + fun allOf(vararg flows: Flow<Boolean>): Flow<Boolean> = flows.asIterable().all() + + /** + * Logical AND operator for boolean flows. Will collect all flows and [combine] them to + * determine the result. + */ + fun Array<Flow<Boolean>>.all(): Flow<Boolean> = allOf(*this) + + /** + * Logical AND operator for boolean flows. Will collect all flows and [combine] them to + * determine the result. + */ + fun Iterable<Flow<Boolean>>.all(): Flow<Boolean> = + combine(this) { values -> values.all { it } }.distinctUntilChanged() /** * Logical NOT operator for a boolean flow. @@ -48,6 +60,36 @@ object BooleanFlowOperators { * Logical OR operator for a boolean flow. Will collect all flows and [combine] them to * determine the result. */ - fun or(vararg flows: Flow<Boolean>): Flow<Boolean> = - combine(flows.asIterable()) { values -> values.any { it } }.distinctUntilChanged() + fun anyOf(vararg flows: Flow<Boolean>): Flow<Boolean> = flows.asIterable().any() + + /** + * Logical OR operator for a boolean flow. Will collect all flows and [combine] them to + * determine the result. + */ + fun Array<Flow<Boolean>>.any(): Flow<Boolean> = anyOf(*this) + + /** + * Logical OR operator for a boolean flow. Will collect all flows and [combine] them to + * determine the result. + */ + fun Iterable<Flow<Boolean>>.any(): Flow<Boolean> = + combine(this) { values -> values.any { it } }.distinctUntilChanged() + + /** + * Returns a Flow that produces `true` when all input flows are producing `false`, otherwise + * produces `false`. + */ + fun noneOf(vararg flows: Flow<Boolean>): Flow<Boolean> = not(anyOf(*flows)) + + /** + * Returns a Flow that produces `true` when all input flows are producing `false`, otherwise + * produces `false`. + */ + fun Array<Flow<Boolean>>.none(): Flow<Boolean> = noneOf(*this) + + /** + * Returns a Flow that produces `true` when all input flows are producing `false`, otherwise + * produces `false`. + */ + fun Iterable<Flow<Boolean>>.none(): Flow<Boolean> = not(any()) } |