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

Commit 8d6c519f authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Handle the clear all button in the refactored stack.

Test: atest FooterViewTest ActiveNotificationsInteractorTest FooterViewModelTest
Bug: 293167744
Flag: ACONFIG com.android.systemui.notifications_footer_view_refactor DEVELOPMENT

Change-Id: I7bd06b36c1774c56fb404d68bcd3db28a0d8dc5b
parent 99d06463
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ public class EmptyShadeView extends StackScrollerDecorView {

    public void setFooterVisibility(@Visibility int visibility) {
        mFooterVisibility = visibility;
        setSecondaryVisible(visibility == View.VISIBLE, false);
        setSecondaryVisible(/* visible = */ visibility == View.VISIBLE,
                /* animate = */false,
                /* onAnimationEnded = */ null);
    }

    public void setFooterText(@StringRes int text) {
+9 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.statusbar.notification.collection.coordinator.dagger
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManagerImpl
import com.android.systemui.statusbar.notification.collection.render.NotifStackController
import com.android.systemui.statusbar.notification.collection.render.NotifStats
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.domain.interactor.RenderNotificationListInteractor
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
import com.android.systemui.statusbar.notification.shared.NotificationIconContainerRefactor
@@ -41,6 +42,7 @@ internal constructor(
    private val groupExpansionManagerImpl: GroupExpansionManagerImpl,
    private val notificationIconAreaController: NotificationIconAreaController,
    private val renderListInteractor: RenderNotificationListInteractor,
    private val activeNotificationsInteractor: ActiveNotificationsInteractor,
) : Coordinator {

    override fun attach(pipeline: NotifPipeline) {
@@ -50,7 +52,13 @@ internal constructor(

    fun onAfterRenderList(entries: List<ListEntry>, controller: NotifStackController) =
        traceSection("StackCoordinator.onAfterRenderList") {
            controller.setNotifStats(calculateNotifStats(entries))
            val notifStats = calculateNotifStats(entries)
            if (FooterViewRefactor.isEnabled) {
                activeNotificationsInteractor.setNotifStats(notifStats)
            }
            // TODO(b/293167744): This shouldn't be done if the footer flag is on, once the footer
            //  visibility is handled in the new stack.
            controller.setNotifStats(notifStats)
            if (NotificationIconContainerRefactor.isEnabled || FooterViewRefactor.isEnabled) {
                renderListInteractor.setRenderedList(entries)
            } else {
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.notification.data.repository

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.notification.collection.render.NotifStats
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore.Key
import com.android.systemui.statusbar.notification.shared.ActiveNotificationEntryModel
import com.android.systemui.statusbar.notification.shared.ActiveNotificationGroupModel
@@ -37,6 +38,9 @@ class ActiveNotificationListRepository @Inject constructor() {

    /** Are any already-seen notifications currently filtered out of the active list? */
    val hasFilteredOutSeenNotifications = MutableStateFlow(false)

    /** Stats about the list of notifications attached to the shade */
    val notifStats = MutableStateFlow(NotifStats.empty)
}

/** Represents the notification list, comprised of groups and individual notifications. */
+11 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@

package com.android.systemui.statusbar.notification.domain.interactor

import com.android.systemui.statusbar.notification.collection.render.NotifStats
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationListRepository
import com.android.systemui.statusbar.notification.shared.ActiveNotificationGroupModel
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
@@ -52,4 +53,14 @@ constructor(
     */
    val areAnyNotificationsPresentValue: Boolean
        get() = repository.activeNotifications.value.renderList.isNotEmpty()

    /** Are there are any notifications that can be cleared by the "Clear all" button? */
    val hasClearableNotifications: Flow<Boolean> =
        repository.notifStats
            .map { it.hasClearableAlertingNotifs || it.hasClearableSilentNotifs }
            .distinctUntilChanged()

    fun setNotifStats(notifStats: NotifStats) {
        repository.notifStats.value = notifStats
    }
}
+75 −11
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.systemui.statusbar.notification.stack.ViewState;
import com.android.systemui.util.DumpUtilsKt;

import java.io.PrintWriter;
import java.util.function.Consumer;

public class FooterView extends StackScrollerDecorView {
    private static final String TAG = "FooterView";
@@ -63,9 +64,13 @@ public class FooterView extends StackScrollerDecorView {
    private String mSeenNotifsFilteredText;
    private Drawable mSeenNotifsFilteredIcon;

    private @StringRes int mClearAllButtonTextId;
    private @StringRes int mClearAllButtonDescriptionId;
    private @StringRes int mMessageStringId;
    private @DrawableRes int mMessageIconId;

    private OnClickListener mClearAllButtonClickListener;

    public FooterView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
@@ -84,12 +89,18 @@ public class FooterView extends StackScrollerDecorView {
        return isSecondaryVisible();
    }

    /** See {@link this#setClearAllButtonVisible(boolean, boolean, Consumer)}. */
    public void setClearAllButtonVisible(boolean visible, boolean animate) {
        setClearAllButtonVisible(visible, animate, /* onAnimationEnded = */ null);
    }

    /**
     * Set the visibility of the "Clear all" button to {@code visible}. Animate the change if
     * {@code animate} is true.
     */
    public void setClearAllButtonVisible(boolean visible, boolean animate) {
        setSecondaryVisible(visible, animate);
    public void setClearAllButtonVisible(boolean visible, boolean animate,
            Consumer<Boolean> onAnimationEnded) {
        setSecondaryVisible(visible, animate, onAnimationEnded);
    }

    @Override
@@ -106,6 +117,42 @@ public class FooterView extends StackScrollerDecorView {
        });
    }

    /** Set the text label for the "Clear all" button. */
    public void setClearAllButtonText(@StringRes int textId) {
        if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) return;
        if (mClearAllButtonTextId == textId) {
            return; // nothing changed
        }
        mClearAllButtonTextId = textId;
        updateClearAllButtonText();
    }

    private void updateClearAllButtonText() {
        if (mClearAllButtonTextId == 0) {
            return; // not initialized yet
        }
        mClearAllButton.setText(getContext().getString(mClearAllButtonTextId));
    }

    /** Set the accessibility content description for the "Clear all" button. */
    public void setClearAllButtonDescription(@StringRes int contentDescriptionId) {
        if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) {
            return;
        }
        if (mClearAllButtonDescriptionId == contentDescriptionId) {
            return; // nothing changed
        }
        mClearAllButtonDescriptionId = contentDescriptionId;
        updateClearAllButtonDescription();
    }

    private void updateClearAllButtonDescription() {
        if (mClearAllButtonDescriptionId == 0) {
            return; // not initialized yet
        }
        mClearAllButton.setContentDescription(getContext().getString(mClearAllButtonDescriptionId));
    }

    /** Set the string for a message to be shown instead of the buttons. */
    public void setMessageString(@StringRes int messageId) {
        if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) return;
@@ -181,6 +228,10 @@ public class FooterView extends StackScrollerDecorView {

    /** Set onClickListener for the clear all (end) button. */
    public void setClearAllButtonClickListener(OnClickListener listener) {
        if (FooterViewRefactor.isEnabled()) {
            if (mClearAllButtonClickListener == listener) return;
            mClearAllButtonClickListener = listener;
        }
        mClearAllButton.setOnClickListener(listener);
    }

@@ -214,7 +265,28 @@ public class FooterView extends StackScrollerDecorView {
            mManageButton.setText(mManageNotificationText);
            mManageButton.setContentDescription(mManageNotificationText);
        }
        if (!FooterViewRefactor.isEnabled()) {
        if (FooterViewRefactor.isEnabled()) {
            updateClearAllButtonText();
            updateClearAllButtonDescription();

            updateMessageString();
            updateMessageIcon();
        } else {
            // NOTE: Prior to the refactor, `updateResources` set the class properties to the right
            // string values. It was always being called together with `updateContent`, which
            // deals with actually associating those string values with the correct views
            // (buttons or text).
            // In the new code, the resource IDs are being set in the view binder (through
            // setMessageString and similar setters). The setters themselves now deal with
            // updating both the resource IDs and the views where appropriate (as in, calling
            // `updateMessageString` when the resource ID changes). This eliminates the need for
            // `updateResources`, which will eventually be removed. There are, however, still
            // situations in which we want to update the views even if the resource IDs didn't
            // change, such as configuration changes.
            mClearAllButton.setText(R.string.clear_all_notifications_text);
            mClearAllButton.setContentDescription(
                    mContext.getString(R.string.accessibility_clear_all));

            mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText);
            mSeenNotifsFooterTextView
                    .setCompoundDrawablesRelative(mSeenNotifsFilteredIcon, null, null, null);
@@ -230,16 +302,8 @@ public class FooterView extends StackScrollerDecorView {
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        updateColors();
        mClearAllButton.setText(R.string.clear_all_notifications_text);
        mClearAllButton.setContentDescription(
                mContext.getString(R.string.accessibility_clear_all));
        updateResources();
        updateContent();

        if (FooterViewRefactor.isEnabled()) {
            updateMessageString();
            updateMessageIcon();
        }
    }

    /**
Loading