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

Commit 19b2c86d authored by Steve Elliott's avatar Steve Elliott
Browse files

Add new "incoming" header for HUNing notifications

Bug: 155494605
Test: manual, visual
Change-Id: I4838d235bb18204fe929c935b230c041eb12f4f1
parent bf8d4b44
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1253,6 +1253,9 @@
    <!-- The text for the notification history link. [CHAR LIMIT=40] -->
    <string name="manage_notifications_history_text">History</string>

    <!-- Section title for notifications that have recently appeared. [CHAR LIMIT=40] -->
    <string name="notification_section_header_incoming">Incoming</string>

    <!-- Section title for notifications that do not vibrate or make noise. [CHAR LIMIT=40] -->
    <string name="notification_section_header_gentle">Silent notifications</string>

+26 −26
Original line number Diff line number Diff line
@@ -27,20 +27,17 @@ import com.android.systemui.statusbar.notification.NotificationFilter
import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_IMPORTANT_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT

import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.PriorityBucket
import com.android.systemui.statusbar.phone.NotificationGroupManager
import com.android.systemui.statusbar.policy.HeadsUpManager
import dagger.Lazy
import java.util.Objects;
import java.util.Objects
import javax.inject.Inject
import kotlin.Comparator

private const val TAG = "NotifRankingManager"

@@ -140,33 +137,36 @@ open class NotificationRankingManager @Inject constructor(
                .filterNot(notifFilter::shouldFilterOut)
                .sortedWith(rankingComparator)
                .toList()
        for (entry in filtered) {
            assignBucketForEntry(entry)
        }
        assignBuckets(filtered)
        return filtered
    }

    private fun assignBucketForEntry(entry: NotificationEntry) {
    private fun assignBuckets(entries: List<NotificationEntry>) {
        entries.forEach { it.bucket = getBucketForEntry(it) }
        if (!usePeopleFiltering) {
            // If we don't have a Conversation section, just assign buckets normally based on the
            // content.
            return
        }
        // If HUNs are not continuous with the top section, break out into a new Incoming section.
        entries.asReversed().asSequence().zipWithNext().forEach { (next, entry) ->
            if (entry.isRowHeadsUp && entry.bucket > next.bucket) {
                entry.bucket = BUCKET_HEADS_UP
            }
        }
    }

    @PriorityBucket
    private fun getBucketForEntry(entry: NotificationEntry): Int {
        val isHeadsUp = entry.isRowHeadsUp
        val isMedia = isImportantMedia(entry)
        val isSystemMax = entry.isSystemMax()
        setBucket(entry, isHeadsUp, isMedia, isSystemMax)
    }

    private fun setBucket(
        entry: NotificationEntry,
        isHeadsUp: Boolean,
        isMedia: Boolean,
        isSystemMax: Boolean
    ) {
        if (usePeopleFiltering && isHeadsUp) {
            entry.bucket = BUCKET_HEADS_UP
        } else if (usePeopleFiltering && entry.getPeopleNotificationType() != TYPE_NON_PERSON) {
            entry.bucket = BUCKET_PEOPLE
        } else if (isHeadsUp || isMedia || isSystemMax || entry.isHighPriority()) {
            entry.bucket = BUCKET_ALERTING
        } else {
            entry.bucket = BUCKET_SILENT
        return when {
            usePeopleFiltering && entry.getPeopleNotificationType() != TYPE_NON_PERSON ->
                BUCKET_PEOPLE
            isHeadsUp || isMedia || isSystemMax || entry.isHighPriority() ->
                BUCKET_ALERTING
            else -> BUCKET_SILENT
        }
    }

+37 −2
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
    @Nullable private View.OnClickListener mOnClearGentleNotifsClickListener;

    private SectionHeaderView mAlertingHeader;
    private SectionHeaderView mIncomingHeader;

    private PeopleHubView mPeopleHubView;
    private boolean mPeopleHubVisible = false;
@@ -199,6 +200,11 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
            mPeopleHubSubscription = mPeopleHubViewAdapter.bindView(mPeopleHubViewBoundary);
        }

        mIncomingHeader = reinflateView(
                mIncomingHeader, layoutInflater, R.layout.status_bar_notification_section_header);
        mIncomingHeader.setHeaderText(R.string.notification_section_header_incoming);
        mIncomingHeader.setOnHeaderClickListener(this::onGentleHeaderClick);

        if (mMediaControlsView != null) {
            mKeyguardMediaPlayer.unbindView();
        }
@@ -218,6 +224,7 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
                || view == mMediaControlsView
                || view == mPeopleHubView
                || view == mAlertingHeader
                || view == mIncomingHeader
                || !Objects.equals(getBucket(view), getBucket(previous));
    }

@@ -229,6 +236,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
    private Integer getBucket(View view) {
        if (view == mGentleHeader) {
            return BUCKET_SILENT;
        } else if (view == mIncomingHeader) {
            return BUCKET_HEADS_UP;
        } else if (view == mMediaControlsView) {
            return BUCKET_MEDIA_CONTROLS;
        } else if (view == mPeopleHubView) {
@@ -267,6 +276,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
        // Currently, just putting media controls in the front and incrementing the position based
        // on the number of heads-up notifs.
        int mediaControlsTarget = isKeyguard && usingMediaControls ? 0 : -1;
        int currentIncomingHeaderIdx = -1;
        int incomingHeaderTarget = -1;
        int currentPeopleHeaderIdx = -1;
        int peopleHeaderTarget = -1;
        int currentAlertingHeaderIdx = -1;
@@ -281,6 +292,10 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
            View child = mParent.getChildAt(i);

            // Track the existing positions of the headers
            if (child == mIncomingHeader) {
                currentIncomingHeaderIdx = i;
                continue;
            }
            if (child == mMediaControlsView) {
                currentMediaControlsIdx = i;
                continue;
@@ -306,6 +321,26 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
            // Once we enter a new section, calculate the target position for the header.
            switch (row.getEntry().getBucket()) {
                case BUCKET_HEADS_UP:
                    if (showHeaders && incomingHeaderTarget == -1) {
                        incomingHeaderTarget = i;
                        // Offset the target if there are other headers before this that will be
                        // moved.
                        if (currentIncomingHeaderIdx != -1) {
                            incomingHeaderTarget--;
                        }
                        if (currentMediaControlsIdx != -1) {
                            incomingHeaderTarget--;
                        }
                        if (currentPeopleHeaderIdx != -1) {
                            incomingHeaderTarget--;
                        }
                        if (currentAlertingHeaderIdx != -1) {
                            incomingHeaderTarget--;
                        }
                        if (currentGentleHeaderIdx != -1) {
                            incomingHeaderTarget--;
                        }
                    }
                    if (mediaControlsTarget != -1) {
                        mediaControlsTarget++;
                    }
@@ -378,8 +413,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
                alertingHeaderTarget, mAlertingHeader, currentAlertingHeaderIdx);
        adjustHeaderVisibilityAndPosition(
                peopleHeaderTarget, mPeopleHubView, currentPeopleHeaderIdx);
        adjustViewPosition(
                mediaControlsTarget, mMediaControlsView, currentMediaControlsIdx);
        adjustViewPosition(mediaControlsTarget, mMediaControlsView, currentMediaControlsIdx);
        adjustViewPosition(incomingHeaderTarget, mIncomingHeader, currentIncomingHeaderIdx);

        // Update headers to reflect state of section contents
        mGentleHeader.setAreThereDismissableGentleNotifs(