diff options
author | 2020-05-06 22:34:15 +0000 | |
---|---|---|
committer | 2020-05-06 22:34:15 +0000 | |
commit | 0b17a06762fa2f3c68dc147dfc65737f703357b1 (patch) | |
tree | 7cb2fcb48f14d1b310983c6ba2c963056025d4d1 | |
parent | e8be4f8cb6dcbffa4a8e60668a5a31a9d6853d50 (diff) | |
parent | 19b2c86d8a233d71cee6f3bf260bda2962d6a06c (diff) |
Merge "Add new "incoming" header for HUNing notifications" into rvc-dev
3 files changed, 66 insertions, 28 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 96843f187f72..ee97e7374148 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -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> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt index 9738bcc69279..c78370ec4643 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt @@ -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 } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.java index d02037cf61fd..6eec1ca33e14 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.java @@ -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( |