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

Commit 5182c9f5 authored by Kevin Han's avatar Kevin Han
Browse files

Move a bunch of row setters into an init method.

We have a bunch of setters for stuff that is only initialized once on a
row. So let's just go ahead and move these into an initialize method so
it's more readable and harder to mis-use.

There are a few others that are used in tests that should probably be
moved into this method or just moved out of ExpandableNotificationRow
entirely.

Test: builds
Test: atest SystemUITests
Change-Id: Ifa55ca19fa2fd1f2030caa0676e6aa3e1713f134
parent 0f98a6d1
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -166,20 +166,6 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
    private void bindRow(NotificationEntry entry, PackageManager pmUser,
            StatusBarNotification sbn, ExpandableNotificationRow row,
            Runnable onDismissRunnable) {
        row.setExpansionLogger(mExpansionLogger, entry.getSbn().getKey());
        row.setBypassController(mKeyguardBypassController);
        row.setStatusBarStateController(mStatusBarStateController);
        row.setGroupManager(mGroupManager);
        row.setHeadsUpManager(mHeadsUpManager);
        row.setOnExpandClickListener(mPresenter);
        row.setContentBinder(mRowContentBinder);
        row.setInflationCallback(mInflationCallback);
        if (mAllowLongPress) {
            row.setLongPressListener(mGutsManager::openGuts);
        }
        mListContainer.bindRow(row);
        mNotificationRemoteInputManager.bindRow(row);

        // Get the app name.
        // Note that Notification.Builder#bindHeaderAppName has similar logic
        // but since this field is used in the guts, it must be accurate.
@@ -197,15 +183,33 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
        } catch (PackageManager.NameNotFoundException e) {
            // Do nothing
        }
        row.setAppName(appname);

        row.initialize(
                appname,
                sbn.getKey(),
                mExpansionLogger,
                mKeyguardBypassController,
                mGroupManager,
                mHeadsUpManager,
                mRowContentBinder,
                mPresenter);

        // TODO: Either move these into ExpandableNotificationRow#initialize or out of row entirely
        row.setStatusBarStateController(mStatusBarStateController);
        row.setInflationCallback(mInflationCallback);
        row.setAppOpsOnClickListener(mOnAppOpsClickListener);
        if (mAllowLongPress) {
            row.setLongPressListener(mGutsManager::openGuts);
        }
        mListContainer.bindRow(row);
        mNotificationRemoteInputManager.bindRow(row);

        row.setOnDismissRunnable(onDismissRunnable);
        row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        if (ENABLE_REMOTE_INPUT) {
            row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        }

        row.setAppOpsOnClickListener(mOnAppOpsClickListener);

        mBindRowCallback.onBindRow(entry, pmUser, sbn, row);
    }

+23 −36
Original line number Diff line number Diff line
@@ -741,23 +741,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mIsHeadsUp || mHeadsupDisappearRunning;
    }


    public void setGroupManager(NotificationGroupManager groupManager) {
        mGroupManager = groupManager;
        mPrivateLayout.setGroupManager(groupManager);
    }

    public void setRemoteInputController(RemoteInputController r) {
        mPrivateLayout.setRemoteInputController(r);
    }

    public void setAppName(String appName) {
        mAppName = appName;
        if (mMenuRow != null && mMenuRow.getMenuView() != null) {
            mMenuRow.setAppName(mAppName);
        }
    }

    public void addChildNotification(ExpandableNotificationRow row) {
        addChildNotification(row, -1);
    }
@@ -1104,10 +1091,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mPrivateLayout.getContractedNotificationHeader();
    }

    public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
        mOnExpandClickListener = onExpandClickListener;
    }

    public void setLongPressListener(LongPressListener longPressListener) {
        mLongPressListener = longPressListener;
    }
@@ -1130,10 +1113,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    public void setHeadsUpManager(HeadsUpManager headsUpManager) {
        mHeadsUpManager = headsUpManager;
    }

    public HeadsUpManager getHeadsUpManager() {
        return mHeadsUpManager;
    }
@@ -1656,15 +1635,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    /**
     * Set the binder implementation for notification content views.
     *
     * @param contentBinder content binder
     */
    public void setContentBinder(NotificationRowContentBinder contentBinder) {
        mNotificationContentBinder = contentBinder;
    }

    public interface ExpansionLogger {
        void logNotificationExpansion(String key, boolean userAction, boolean expanded);
    }
@@ -1678,8 +1648,30 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        initDimens();
    }

    public void setBypassController(KeyguardBypassController bypassController) {
    /**
     * Initialize row.
     */
    public void initialize(
            String appName,
            String notificationKey,
            ExpansionLogger logger,
            KeyguardBypassController bypassController,
            NotificationGroupManager groupManager,
            HeadsUpManager headsUpManager,
            NotificationRowContentBinder rowContentBinder,
            OnExpandClickListener onExpandClickListener) {
        mAppName = appName;
        if (mMenuRow != null && mMenuRow.getMenuView() != null) {
            mMenuRow.setAppName(mAppName);
        }
        mLogger = logger;
        mLoggingKey = notificationKey;
        mBypassController = bypassController;
        mGroupManager = groupManager;
        mPrivateLayout.setGroupManager(groupManager);
        mHeadsUpManager = headsUpManager;
        mNotificationContentBinder = rowContentBinder;
        mOnExpandClickListener = onExpandClickListener;
    }

    public void setStatusBarStateController(StatusBarStateController statusBarStateController) {
@@ -2918,11 +2910,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return 0;
    }

    public void setExpansionLogger(ExpansionLogger logger, String key) {
        mLogger = logger;
        mLoggingKey = key;
    }

    public void onExpandedByGesture(boolean userExpanded) {
        int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
        if (mGroupManager.isSummaryOfGroup(mEntry.getSbn())) {
+16 −4
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.ExpansionLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.OnExpandClickListener;
import com.android.systemui.statusbar.notification.row.NotifRemoteViewCache;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
@@ -73,6 +75,7 @@ public class NotificationTestHelper {
    public static final UserHandle USER_HANDLE = UserHandle.of(ActivityManager.getCurrentUser());

    private static final String GROUP_KEY = "gruKey";
    private static final String APP_NAME = "appName";

    private final Context mContext;
    private int mId;
@@ -304,9 +307,6 @@ public class NotificationTestHelper {
                null /* root */,
                false /* attachToRoot */);
        ExpandableNotificationRow row = mRow;
        row.setGroupManager(mGroupManager);
        row.setHeadsUpManager(mHeadsUpManager);
        row.setAboveShelfChangedListener(aboveShelf -> {});

        final NotificationChannel channel =
                new NotificationChannel(
@@ -330,11 +330,23 @@ public class NotificationTestHelper {
        entry.setRow(row);
        entry.createIcons(mContext, entry.getSbn());
        row.setEntry(entry);

        NotificationContentInflater contentBinder = new NotificationContentInflater(
                mock(NotifRemoteViewCache.class),
                mock(NotificationRemoteInputManager.class));
        contentBinder.setInflateSynchronously(true);
        row.setContentBinder(contentBinder);

        row.initialize(
                APP_NAME,
                entry.getKey(),
                mock(ExpansionLogger.class),
                mock(KeyguardBypassController.class),
                mGroupManager,
                mHeadsUpManager,
                contentBinder,
                mock(OnExpandClickListener.class));
        row.setAboveShelfChangedListener(aboveShelf -> { });

        row.setInflationFlags(extraInflationFlags);
        inflateAndWait(row);