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

Commit a13b6f18 authored by Ned Burns's avatar Ned Burns
Browse files

Centralize reorder-on-priority-change logic

The visual stability manager has a special exception that allows notifs
to be reordered if their priority changes. Previously, this was tracked
by various members and method spread across a lot of classes: it
was set in one place, read in another, and cleared out in a third. This
CL attemps to centralize this logic as much as possible to be just
contained in the VisualStabilityManager.

Test: atest, manual
Change-Id: I19e047711ef1f8bcb083bdd62f45f2fe68109cc4
parent ebfc162d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -47,7 +47,11 @@ public interface NotificationEntryListener {
    }

    /**
     * Called when a notification is updated, before any filtering of notifications have occurred.
     * Called when a notification is about to be updated. Notification- and ranking-derived fields
     * on the entry have already been updated but the following have not yet occurred:
     * (a) View binding (i.e. the associated view has not yet been updated / inflation has not yet
     *      been kicked off.
     * (b) Notification filtering
     */
    default void onPreEntryUpdated(NotificationEntry entry) {
    }
+2 −4
Original line number Diff line number Diff line
@@ -230,7 +230,6 @@ public class NotificationEntryManager implements
                }
            }
        }
        entry.setLowPriorityStateUpdated(false);
    }

    @Override
@@ -384,13 +383,12 @@ public class NotificationEntryManager implements

        mNotificationData.update(entry, ranking, notification);

        getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification),
                mNotificationData.get(entry.key) != null);

        for (NotificationEntryListener listener : mNotificationEntryListeners) {
            listener.onPreEntryUpdated(entry);
        }

        getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification),
                mNotificationData.get(entry.key) != null);
        updateNotifications();

        if (DEBUG) {
+1 −4
Original line number Diff line number Diff line
@@ -226,10 +226,7 @@ public class NotificationRowBinder {
            StatusBarNotification sbn,
            ExpandableNotificationRow row,
            boolean isUpdate) {
        boolean isLowPriority = entry.ambient;
        boolean wasLowPriority = row.isLowPriority();
        row.setIsLowPriority(isLowPriority);
        row.setLowPriorityStateUpdated(isUpdate && (wasLowPriority != isLowPriority));
        row.setIsLowPriority(entry.ambient);
        // bind the click event to the content area
        checkNotNull(mNotificationClicker).register(row, sbn);

+15 −12
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class VisualStabilityManager implements OnHeadsUpChangedListener {
    private boolean mReorderingAllowed;
    private VisibilityLocationProvider mVisibilityLocationProvider;
    private ArraySet<View> mAllowedReorderViews = new ArraySet<>();
    private ArraySet<View> mLowPriorityReorderingViews = new ArraySet<>();
    private ArraySet<NotificationEntry> mLowPriorityReorderingViews = new ArraySet<>();
    private ArraySet<View> mAddedChildren = new ArraySet<>();
    private boolean mPulsing;

@@ -53,13 +53,20 @@ public class VisualStabilityManager implements OnHeadsUpChangedListener {
    public VisualStabilityManager(NotificationEntryManager notificationEntryManager) {
        notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
            @Override
            public void onEntryReinflated(NotificationEntry entry) {
                if (entry.hasLowPriorityStateUpdated()) {
                    onLowPriorityUpdated(entry);
                    if (mPresenter != null) {
                        mPresenter.updateNotificationViews();
            public void onPreEntryUpdated(NotificationEntry entry) {
                final boolean mAmbientStateHasChanged =
                        entry.ambient != entry.getRow().isLowPriority();
                if (mAmbientStateHasChanged) {
                    mLowPriorityReorderingViews.add(entry);
                }
            }

            @Override
            public void onPostEntryUpdated(NotificationEntry entry) {
                // This line is technically not required as we'll get called as the hierarchy
                // manager will call onReorderingFinished() immediately before this.
                // TODO: Find a way to make this relationship more explicit
                mLowPriorityReorderingViews.remove(entry);
            }
        });
    }
@@ -142,7 +149,7 @@ public class VisualStabilityManager implements OnHeadsUpChangedListener {
        if (mAddedChildren.contains(row)) {
            return true;
        }
        if (mLowPriorityReorderingViews.contains(row)) {
        if (mLowPriorityReorderingViews.contains(row.getEntry())) {
            return true;
        }
        if (mAllowedReorderViews.contains(row)
@@ -172,10 +179,6 @@ public class VisualStabilityManager implements OnHeadsUpChangedListener {
        }
    }

    private void onLowPriorityUpdated(NotificationEntry entry) {
        mLowPriorityReorderingViews.add(entry.getRow());
    }

    /**
     * Notify the visual stability manager that a new view was added and should be allowed to
     * reorder next time.
+0 −8
Original line number Diff line number Diff line
@@ -622,10 +622,6 @@ public final class NotificationEntry {
        return null;
    }

    public boolean hasLowPriorityStateUpdated() {
        return row != null && row.hasLowPriorityStateUpdated();
    }

    public void removeRow() {
        if (row != null) row.setRemoved();
    }
@@ -650,10 +646,6 @@ public final class NotificationEntry {
        return parent == null;
    }

    public void setLowPriorityStateUpdated(boolean updated) {
        if (row != null) row.setLowPriorityStateUpdated(updated);
    }

    /**
     * @return Can the underlying notification be cleared? This can be different from whether the
     *         notification can be dismissed in case notifications are sensitive on the lockscreen.
Loading