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

Commit 8e42f093 authored by Steve Elliott's avatar Steve Elliott
Browse files

Cache resources for unseen footer treatment

These resources are frequently re-queried even if there is no change.
Caching them will increase performance and reduce potential jank.

Fixes: 266116638
Test: atest FooterViewTest
Change-Id: If8f00a56c68dc57c99cd9b755b55a7e3c274a6da
parent 0948e76a
Loading
Loading
Loading
Loading
+15 −29
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.systemui.statusbar.notification.row;

import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.StringRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
@@ -50,8 +48,8 @@ public class FooterView extends StackScrollerDecorView {

    // Footer label
    private TextView mSeenNotifsFooterTextView;
    private @StringRes int mSeenNotifsFilteredText;
    private int mUnlockIconSize;
    private String mSeenNotifsFilteredText;
    private Drawable mSeenNotifsFilteredIcon;

    public FooterView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -87,30 +85,12 @@ public class FooterView extends StackScrollerDecorView {
        mManageButton = findViewById(R.id.manage_text);
        mSeenNotifsFooterTextView = findViewById(R.id.unlock_prompt_footer);
        updateResources();
        updateText();
        updateContent();
        updateColors();
    }

    public void setFooterLabelTextAndIcon(@StringRes int text, @DrawableRes int icon) {
        mSeenNotifsFilteredText = text;
        if (mSeenNotifsFilteredText != 0) {
            mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText);
        } else {
            mSeenNotifsFooterTextView.setText(null);
        }
        Drawable drawable;
        if (icon == 0) {
            drawable = null;
        } else {
            drawable = getResources().getDrawable(icon);
            drawable.setBounds(0, 0, mUnlockIconSize, mUnlockIconSize);
        }
        mSeenNotifsFooterTextView.setCompoundDrawablesRelative(drawable, null, null, null);
        updateFooterVisibilityMode();
    }

    private void updateFooterVisibilityMode() {
        if (mSeenNotifsFilteredText != 0) {
    public void setFooterLabelVisible(boolean isVisible) {
        if (isVisible) {
            mManageButton.setVisibility(View.GONE);
            mClearAllButton.setVisibility(View.GONE);
            mSeenNotifsFooterTextView.setVisibility(View.VISIBLE);
@@ -141,10 +121,10 @@ public class FooterView extends StackScrollerDecorView {
            return;
        }
        mShowHistory = showHistory;
        updateText();
        updateContent();
    }

    private void updateText() {
    private void updateContent() {
        if (mShowHistory) {
            mManageButton.setText(mManageNotificationHistoryText);
            mManageButton.setContentDescription(mManageNotificationHistoryText);
@@ -152,6 +132,9 @@ public class FooterView extends StackScrollerDecorView {
            mManageButton.setText(mManageNotificationText);
            mManageButton.setContentDescription(mManageNotificationText);
        }
        mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText);
        mSeenNotifsFooterTextView
                .setCompoundDrawablesRelative(mSeenNotifsFilteredIcon, null, null, null);
    }

    public boolean isHistoryShown() {
@@ -166,7 +149,7 @@ public class FooterView extends StackScrollerDecorView {
        mClearAllButton.setContentDescription(
                mContext.getString(R.string.accessibility_clear_all));
        updateResources();
        updateText();
        updateContent();
    }

    /**
@@ -190,8 +173,11 @@ public class FooterView extends StackScrollerDecorView {
        mManageNotificationText = getContext().getString(R.string.manage_notifications_text);
        mManageNotificationHistoryText = getContext()
                .getString(R.string.manage_notifications_history_text);
        mUnlockIconSize = getResources()
        int unlockIconSize = getResources()
                .getDimensionPixelSize(R.dimen.notifications_unseen_footer_icon_size);
        mSeenNotifsFilteredText = getContext().getString(R.string.unlock_to_see_notif_text);
        mSeenNotifsFilteredIcon = getContext().getDrawable(R.drawable.ic_friction_lock_closed);
        mSeenNotifsFilteredIcon.setBounds(0, 0, unlockIconSize, unlockIconSize);
    }

    @Override
+1 −7
Original line number Diff line number Diff line
@@ -4741,13 +4741,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        mFooterView.setVisible(visible, animate);
        mFooterView.setSecondaryVisible(showDismissView, animate);
        mFooterView.showHistory(showHistory);
        if (mHasFilteredOutSeenNotifications) {
            mFooterView.setFooterLabelTextAndIcon(
                    R.string.unlock_to_see_notif_text,
                    R.drawable.ic_friction_lock_closed);
        } else {
            mFooterView.setFooterLabelTextAndIcon(0, 0);
        }
        mFooterView.setFooterLabelVisible(mHasFilteredOutSeenNotifications);
    }

    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
+13 −6
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@ import static junit.framework.Assert.assertTrue;

import static org.mockito.Mockito.mock;

import android.testing.AndroidTestingRunner;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
@@ -39,7 +39,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidTestingRunner.class)
public class FooterViewTest extends SysuiTestCase {

    FooterView mView;
@@ -102,14 +102,21 @@ public class FooterViewTest extends SysuiTestCase {
    }

    @Test
    public void testSetFooterLabelTextAndIcon() {
        mView.setFooterLabelTextAndIcon(
                R.string.unlock_to_see_notif_text,
                R.drawable.ic_friction_lock_closed);
    public void testSetFooterLabelVisible() {
        mView.setFooterLabelVisible(true);
        assertThat(mView.findViewById(R.id.manage_text).getVisibility()).isEqualTo(View.GONE);
        assertThat(mView.findSecondaryView().getVisibility()).isEqualTo(View.GONE);
        assertThat(mView.findViewById(R.id.unlock_prompt_footer).getVisibility())
                .isEqualTo(View.VISIBLE);
    }

    @Test
    public void testSetFooterLabelInvisible() {
        mView.setFooterLabelVisible(false);
        assertThat(mView.findViewById(R.id.manage_text).getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mView.findSecondaryView().getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mView.findViewById(R.id.unlock_prompt_footer).getVisibility())
                .isEqualTo(View.GONE);
    }
}