Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9171119 authored by Steve Elliott's avatar Steve Elliott Committed by Android (Google) Code Review
Browse files

Merge "Rename boolean flow operators to match collections" into main

parents a1756dd7 61565bb2
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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
                },
+1 −1
Original line number Diff line number Diff line
@@ -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
+4 −4
Original line number Diff line number Diff line
@@ -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 ->
+2 −2
Original line number Diff line number Diff line
@@ -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 }
Loading