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

Commit d25d79f9 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Status Bar Refactor] 3/3: Remove HeadsUpAppearanceController#destroy and

migrate the controller to a ViewController model instead.

This allows us to not have to keep track of old HUACs anymore!

Test: atest SystemUITests
Test: manual (verified via logging that #onDetach is called at the same
points that #destroy would have been called)
Bug: 205609837

Change-Id: I32b5df3306616a75ffe009c81b8966689fd11dda
parent 098e210a
Loading
Loading
Loading
Loading
+31 −25
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll
import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentScope;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.util.ViewController;

import java.util.function.BiConsumer;
import java.util.function.Consumer;
@@ -49,14 +50,15 @@ import javax.inject.Inject;
 * Controls the appearance of heads up notifications in the icon area and the header itself.
 */
@StatusBarFragmentScope
public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        DarkIconDispatcher.DarkReceiver, NotificationWakeUpCoordinator.WakeUpListener {
public class HeadsUpAppearanceController extends ViewController<HeadsUpStatusBarView>
        implements OnHeadsUpChangedListener,
        DarkIconDispatcher.DarkReceiver,
        NotificationWakeUpCoordinator.WakeUpListener {
    public static final int CONTENT_FADE_DURATION = 110;
    public static final int CONTENT_FADE_DELAY = 100;
    private final NotificationIconAreaController mNotificationIconAreaController;
    private final HeadsUpManagerPhone mHeadsUpManager;
    private final NotificationStackScrollLayoutController mStackScrollerController;
    private final HeadsUpStatusBarView mHeadsUpStatusBarView;
    private final View mCenteredIconView;
    private final View mClockView;
    private final View mOperatorNameView;
@@ -125,13 +127,10 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
            View clockView,
            View operatorNameView,
            View centeredIconView) {
        super(headsUpStatusBarView);
        mNotificationIconAreaController = notificationIconAreaController;
        mHeadsUpManager = headsUpManager;
        mHeadsUpManager.addListener(this);
        mHeadsUpStatusBarView = headsUpStatusBarView;
        mCenteredIconView = centeredIconView;
        headsUpStatusBarView.setOnDrawingRectChangedListener(
                () -> updateIsolatedIconLocation(true /* requireUpdate */));

        // We may be mid-HUN-expansion when this controller is re-created (for example, if the user
        // has started pulling down the notification shade from the HUN and then the font size
@@ -143,16 +142,12 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,

        mStackScrollerController = stackScrollerController;
        mNotificationPanelViewController = notificationPanelViewController;
        notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
        notificationPanelViewController.setHeadsUpAppearanceController(this);
        mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight);
        mStackScrollerController.setHeadsUpAppearanceController(this);
        mClockView = clockView;
        mOperatorNameView = operatorNameView;
        mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class);
        mDarkIconDispatcher.addDarkReceiver(this);

        mHeadsUpStatusBarView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        mView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
                    int oldLeft, int oldTop, int oldRight, int oldBottom) {
@@ -162,21 +157,32 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
                    // trigger scroller to notify the latest panel translation
                    mStackScrollerController.requestLayout();
                }
                mHeadsUpStatusBarView.removeOnLayoutChangeListener(this);
                mView.removeOnLayoutChangeListener(this);
            }
        });
        mBypassController = bypassController;
        mStatusBarStateController = stateController;
        mWakeUpCoordinator = wakeUpCoordinator;
        wakeUpCoordinator.addListener(this);
        mCommandQueue = commandQueue;
        mKeyguardStateController = keyguardStateController;
    }

    @Override
    protected void onViewAttached() {
        mHeadsUpManager.addListener(this);
        mView.setOnDrawingRectChangedListener(
                () -> updateIsolatedIconLocation(true /* requireUpdate */));
        mWakeUpCoordinator.addListener(this);
        mNotificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp);
        mNotificationPanelViewController.setHeadsUpAppearanceController(this);
        mStackScrollerController.addOnExpandedHeightChangedListener(mSetExpandedHeight);
        mDarkIconDispatcher.addDarkReceiver(this);
    }

    public void destroy() {
    @Override
    protected void onViewDetached() {
        mHeadsUpManager.removeListener(this);
        mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null);
        mView.setOnDrawingRectChangedListener(null);
        mWakeUpCoordinator.removeListener(this);
        mNotificationPanelViewController.removeTrackingHeadsUpListener(mSetTrackingHeadsUp);
        mNotificationPanelViewController.setHeadsUpAppearanceController(null);
@@ -186,7 +192,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,

    private void updateIsolatedIconLocation(boolean requireStateUpdate) {
        mNotificationIconAreaController.setIsolatedIconLocation(
                mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate);
                mView.getIconDrawingRect(), requireStateUpdate);
    }

    @Override
@@ -200,8 +206,8 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
        if (shouldBeVisible()) {
            newEntry = mHeadsUpManager.getTopEntry();
        }
        NotificationEntry previousEntry = mHeadsUpStatusBarView.getShowingEntry();
        mHeadsUpStatusBarView.setEntry(newEntry);
        NotificationEntry previousEntry = mView.getShowingEntry();
        mView.setEntry(newEntry);
        if (newEntry != previousEntry) {
            boolean animateIsolation = false;
            if (newEntry == null) {
@@ -226,8 +232,8 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
            mShown = isShown;
            if (isShown) {
                updateParentClipping(false /* shouldClip */);
                mHeadsUpStatusBarView.setVisibility(View.VISIBLE);
                show(mHeadsUpStatusBarView);
                mView.setVisibility(View.VISIBLE);
                show(mView);
                hide(mClockView, View.INVISIBLE);
                if (mCenteredIconView.getVisibility() != View.GONE) {
                    hide(mCenteredIconView, View.INVISIBLE);
@@ -243,21 +249,21 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,
                if (mOperatorNameView != null) {
                    show(mOperatorNameView);
                }
                hide(mHeadsUpStatusBarView, View.GONE, () -> {
                hide(mView, View.GONE, () -> {
                    updateParentClipping(true /* shouldClip */);
                });
            }
            // Show the status bar icons when the view gets shown / hidden
            if (mStatusBarStateController.getState() != StatusBarState.SHADE) {
                mCommandQueue.recomputeDisableFlags(
                        mHeadsUpStatusBarView.getContext().getDisplayId(), false);
                        mView.getContext().getDisplayId(), false);
            }
        }
    }

    private void updateParentClipping(boolean shouldClip) {
        ViewClippingUtil.setClippingDeactivated(
                mHeadsUpStatusBarView, !shouldClip, mParentClippingParams);
                mView, !shouldClip, mParentClippingParams);
    }

    /**
@@ -396,7 +402,7 @@ public class HeadsUpAppearanceController implements OnHeadsUpChangedListener,

    @Override
    public void onDarkChanged(Rect area, float darkIntensity, int tint) {
        mHeadsUpStatusBarView.onDarkChanged(area, darkIntensity, tint);
        mView.onDarkChanged(area, darkIntensity, tint);
    }

    public void onStateChanged() {
+0 −12
Original line number Diff line number Diff line
@@ -664,7 +664,6 @@ public class StatusBar extends SystemUI implements
    private boolean mNoAnimationOnNextBarModeChange;
    private final SysuiStatusBarStateController mStatusBarStateController;

    private HeadsUpAppearanceController mHeadsUpAppearanceController;
    private final ActivityLaunchAnimator mActivityLaunchAnimator;
    private NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider;
    protected StatusBarNotificationPresenter mPresenter;
@@ -1164,17 +1163,6 @@ public class StatusBar extends SystemUI implements
                    mNotificationPanelViewController.updatePanelExpansionAndVisibility();
                    setBouncerShowingForStatusBarComponents(mBouncerShowing);

                    if (mHeadsUpAppearanceController != null) {
                        // This view is being recreated, let's destroy the old one
                        // TODO(b/205609837): Automatically destroy the old controller so that this
                        //  class doesn't need to hold a reference to the old one.
                        mHeadsUpAppearanceController.destroy();
                    }
                    // TODO (b/136993073) Separate notification shade and status bar
                    // TODO(b/205609837): Migrate this to StatusBarFragmentComponent.
                    mHeadsUpAppearanceController =
                            statusBarFragmentComponent.getHeadsUpAppearanceController();

                    mLightsOutNotifController.setLightsOutNotifView(
                            mStatusBarView.findViewById(R.id.notification_lights_out));
                    mNotificationShadeWindowViewController.setStatusBarView(mStatusBarView);
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public interface StatusBarFragmentComponent {
        // No one accesses this controller, so we need to make sure we reference it here so it does
        // get initialized.
        getBatteryMeterViewController().init();
        getHeadsUpAppearanceController().init();
    }

    /** */
+3 −1
Original line number Diff line number Diff line
@@ -193,7 +193,9 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
        reset(mDarkIconDispatcher);
        reset(mPanelView);
        reset(mStackScrollerController);
        mHeadsUpAppearanceController.destroy();

        mHeadsUpAppearanceController.onViewDetached();

        verify(mHeadsUpManager).removeListener(any());
        verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
        verify(mPanelView).removeTrackingHeadsUpListener(any());