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

Commit 114489a6 authored by Steve Elliott's avatar Steve Elliott
Browse files

cleanup BooleanFlowOperators java interop

Flag: EXEMPT no functional change
Test: make
Change-Id: I37d3d5dcc68f2e21d17b92aefec9c021d57fcd23
parent a19e75b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ class FalsingCollectorImpl implements FalsingCollector {
        final CommunalInteractor communalInteractor = mCommunalInteractorLazy.get();
        final CommunalSceneInteractor communalSceneInteractor = mCommunalSceneInteractorLazy.get();
        mJavaAdapter.alwaysCollectFlow(
                BooleanFlowOperators.INSTANCE.allOf(
                BooleanFlowOperators.allOf(
                        communalInteractor.isCommunalEnabled(),
                        communalSceneInteractor.isIdleOnCommunal()),
                this::onShowingCommunalHubChanged
+1 −1
Original line number Diff line number Diff line
@@ -476,7 +476,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            mFlows.add(collectFlow(getLifecycle(), sceneInteractor.getCurrentOverlays(),
                    mCurrentOverlaysConsumer));
        } else {
            mFlows.add(collectFlow(getLifecycle(), BooleanFlowOperators.INSTANCE.anyOf(
            mFlows.add(collectFlow(getLifecycle(), BooleanFlowOperators.anyOf(
                    keyguardInteractor.primaryBouncerShowing,
                    keyguardInteractor.getAlternateBouncerShowing()),
                    mBouncerShowingConsumer));
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class CommunalTouchHandler implements TouchHandler {

        mFlows.add(collectFlow(
                mLifecycle,
                BooleanFlowOperators.INSTANCE.allOf(
                BooleanFlowOperators.allOf(
                        mCommunalInteractor.isCommunalAvailable(),
                        keyguardInteractor.isKeyguardShowing()
                ),
+2 −2
Original line number Diff line number Diff line
@@ -166,9 +166,9 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
        mJavaAdapter.alwaysCollectFlow(mShadeAnimationInteractor.isLaunchingActivity(),
                this::onLaunchingActivityChanged);
        mJavaAdapter.alwaysCollectFlow(
                BooleanFlowOperators.INSTANCE.allOf(
                BooleanFlowOperators.allOf(
                        mCommunalSceneInteractor.isIdleOnCommunal(),
                        BooleanFlowOperators.INSTANCE.not(mShadeInteractor.isAnyFullyExpanded())
                        BooleanFlowOperators.not(mShadeInteractor.isAnyFullyExpanded())
                ),
                this::onCommunalShowingChanged);

+13 −5
Original line number Diff line number Diff line
@@ -31,18 +31,21 @@ object BooleanFlowOperators {
     * val result = allOf(flow1, flow2)
     * ```
     */
    @JvmStatic
    @SafeVarargs
    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)
    @JvmStatic 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.
     */
    @JvmStatic
    fun Iterable<Flow<Boolean>>.all(): Flow<Boolean> =
        combine(this) { values -> values.all { it } }.distinctUntilChanged()

@@ -54,24 +57,27 @@ object BooleanFlowOperators {
     * val negatedFlow = not(flow)
     * ```
     */
    fun not(flow: Flow<Boolean>) = flow.map { !it }
    @JvmStatic fun not(flow: Flow<Boolean>) = flow.map { !it }

    /**
     * Logical OR operator for a boolean flow. Will collect all flows and [combine] them to
     * determine the result.
     */
    @JvmStatic
    @SafeVarargs
    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)
    @JvmStatic 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.
     */
    @JvmStatic
    fun Iterable<Flow<Boolean>>.any(): Flow<Boolean> =
        combine(this) { values -> values.any { it } }.distinctUntilChanged()

@@ -79,17 +85,19 @@ object BooleanFlowOperators {
     * Returns a Flow that produces `true` when all input flows are producing `false`, otherwise
     * produces `false`.
     */
    @JvmStatic
    @SafeVarargs
    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)
    @JvmStatic 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())
    @JvmStatic fun Iterable<Flow<Boolean>>.none(): Flow<Boolean> = not(any())
}