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

Commit 7f125e22 authored by Luca Zuccarini's avatar Luca Zuccarini
Browse files

Extract chip creation outside of the main chip flow.

This is in preparation of a new version of the chip flow that fully
leverages the new `isHidden` field and enables return animations.

Bug: 202516970
Flag: EXEMPT moving code only
Test: atest CallChipViewModelTest
Change-Id: Ia09a2b34ffce0b0c82ae8faefb84f14c7ce7c66d
parent d88f8f54
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
@@ -71,7 +72,7 @@ class CallChipViewModelTest : SysuiTestCase() {
    private val mockExpandable: Expandable =
        mock<Expandable>().apply { whenever(dialogTransitionController(any())).thenReturn(mock()) }

    private val underTest by lazy { kosmos.callChipViewModel }
    private val Kosmos.underTest by Kosmos.Fixture { callChipViewModel }

    @Test
    fun chip_noCall_isHidden() =
+56 −58
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.chips.call.ui.viewmodel

import android.app.PendingIntent
import android.content.Context
import android.view.View
import com.android.internal.jank.Cuj
@@ -65,7 +66,16 @@ constructor(
                when (state) {
                    is OngoingCallModel.NoCall,
                    is OngoingCallModel.InCallWithVisibleApp -> OngoingActivityChipModel.Inactive()
                    is OngoingCallModel.InCall -> {
                    is OngoingCallModel.InCall -> prepareChip(state, systemClock)
                }
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), OngoingActivityChipModel.Inactive())

    /** Builds an [OngoingActivityChipModel.Active] from all the relevant information. */
    private fun prepareChip(
        state: OngoingCallModel.InCall,
        systemClock: SystemClock,
    ): OngoingActivityChipModel.Active {
        val key = state.notificationKey
        val contentDescription = getContentDescription(state.appName)
        val icon =
@@ -88,38 +98,31 @@ constructor(

        // This block mimics OngoingCallController#updateChip.
        if (state.startTimeMs <= 0L) {
                            // If the start time is invalid, don't show a timer and show just an
                            // icon. See b/192379214.
                            OngoingActivityChipModel.Active.IconOnly(
            // If the start time is invalid, don't show a timer and show just an icon.
            // See b/192379214.
            return OngoingActivityChipModel.Active.IconOnly(
                key = key,
                icon = icon,
                colors = colors,
                                onClickListenerLegacy = getOnClickListener(state),
                                clickBehavior = getClickBehavior(state),
                onClickListenerLegacy = getOnClickListener(state.intent),
                clickBehavior = getClickBehavior(state.intent),
            )
        } else {
            val startTimeInElapsedRealtime =
                                state.startTimeMs - systemClock.currentTimeMillis() +
                                    systemClock.elapsedRealtime()
                            OngoingActivityChipModel.Active.Timer(
                state.startTimeMs - systemClock.currentTimeMillis() + systemClock.elapsedRealtime()
            return OngoingActivityChipModel.Active.Timer(
                key = key,
                icon = icon,
                colors = colors,
                startTimeMs = startTimeInElapsedRealtime,
                                onClickListenerLegacy = getOnClickListener(state),
                                clickBehavior = getClickBehavior(state),
                onClickListenerLegacy = getOnClickListener(state.intent),
                clickBehavior = getClickBehavior(state.intent),
            )
        }
    }
                }
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), OngoingActivityChipModel.Inactive())

    private fun getOnClickListener(state: OngoingCallModel.InCall): View.OnClickListener? {
        if (state.intent == null) {
            return null
        }

    private fun getOnClickListener(intent: PendingIntent?): View.OnClickListener? {
        if (intent == null) return null
        return View.OnClickListener { view ->
            StatusBarChipsModernization.assertInLegacyMode()
            logger.log(TAG, LogLevel.INFO, {}, { "Chip clicked" })
@@ -127,7 +130,7 @@ constructor(
                view.requireViewById<ChipBackgroundContainer>(R.id.ongoing_activity_chip_background)
            // This mimics OngoingCallController#updateChipClickListener.
            activityStarter.postStartActivityDismissingKeyguard(
                state.intent,
                intent,
                ActivityTransitionAnimator.Controller.fromView(
                    backgroundView,
                    Cuj.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP,
@@ -136,10 +139,8 @@ constructor(
        }
    }

    private fun getClickBehavior(
        state: OngoingCallModel.InCall
    ): OngoingActivityChipModel.ClickBehavior =
        if (state.intent == null) {
    private fun getClickBehavior(intent: PendingIntent?): OngoingActivityChipModel.ClickBehavior =
        if (intent == null) {
            OngoingActivityChipModel.ClickBehavior.None
        } else {
            OngoingActivityChipModel.ClickBehavior.ExpandAction(
@@ -149,10 +150,7 @@ constructor(
                        expandable.activityTransitionController(
                            Cuj.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP
                        )
                    activityStarter.postStartActivityDismissingKeyguard(
                        state.intent,
                        animationController,
                    )
                    activityStarter.postStartActivityDismissingKeyguard(intent, animationController)
                }
            )
        }