Merge "Increase defensiveness of Incoming Header placement" into rvc-dev

This commit is contained in:
Steve Elliott
2020-06-05 14:44:05 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 19 deletions

View File

@@ -287,21 +287,17 @@ class NotificationSectionsManager @Inject internal constructor(
// Is there a section discontinuity? This usually occurs due to HUNs // Is there a section discontinuity? This usually occurs due to HUNs
if (prev?.entry?.bucket?.let { it > child.entry.bucket } == true) { if (prev?.entry?.bucket?.let { it > child.entry.bucket } == true) {
// Remove existing headers, and move the Incoming header if necessary // Remove existing headers, and move the Incoming header if necessary
if (alertingHeaderTarget != -1) { incomingHeaderTarget = when {
if (showHeaders && incomingHeaderTarget != -1) { !showHeaders -> -1
incomingHeaderTarget = alertingHeaderTarget incomingHeaderTarget != -1 -> incomingHeaderTarget
} peopleHeaderTarget != -1 -> peopleHeaderTarget
alertingHeaderTarget = -1 alertingHeaderTarget != -1 -> alertingHeaderTarget
} gentleHeaderTarget != -1 -> gentleHeaderTarget
if (peopleHeaderTarget != -1) { else -> 0
if (showHeaders && incomingHeaderTarget != -1) {
incomingHeaderTarget = peopleHeaderTarget
}
peopleHeaderTarget = -1
}
if (showHeaders && incomingHeaderTarget == -1) {
incomingHeaderTarget = 0
} }
peopleHeaderTarget = -1
alertingHeaderTarget = -1
gentleHeaderTarget = -1
// Walk backwards changing all previous notifications to the Incoming // Walk backwards changing all previous notifications to the Incoming
// section // section
for (j in i - 1 downTo lastIncomingIndex + 1) { for (j in i - 1 downTo lastIncomingIndex + 1) {
@@ -323,6 +319,9 @@ class NotificationSectionsManager @Inject internal constructor(
peopleHeaderTarget = i peopleHeaderTarget = i
// Offset the target if there are other headers before this that // Offset the target if there are other headers before this that
// will be moved. // will be moved.
if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) {
peopleHeaderTarget--
}
if (currentPeopleHeaderIdx != -1) { if (currentPeopleHeaderIdx != -1) {
peopleHeaderTarget-- peopleHeaderTarget--
} }
@@ -340,6 +339,13 @@ class NotificationSectionsManager @Inject internal constructor(
alertingHeaderTarget = i alertingHeaderTarget = i
// Offset the target if there are other headers before this that // Offset the target if there are other headers before this that
// will be moved. // will be moved.
if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) {
alertingHeaderTarget--
}
if (currentPeopleHeaderIdx != -1 && peopleHeaderTarget == -1) {
// People header will be removed
alertingHeaderTarget--
}
if (currentAlertingHeaderIdx != -1) { if (currentAlertingHeaderIdx != -1) {
alertingHeaderTarget-- alertingHeaderTarget--
} }
@@ -354,6 +360,17 @@ class NotificationSectionsManager @Inject internal constructor(
gentleHeaderTarget = i gentleHeaderTarget = i
// Offset the target if there are other headers before this that // Offset the target if there are other headers before this that
// will be moved. // will be moved.
if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) {
gentleHeaderTarget--
}
if (currentPeopleHeaderIdx != -1 && peopleHeaderTarget == -1) {
// People header will be removed
gentleHeaderTarget--
}
if (currentAlertingHeaderIdx != -1 && alertingHeaderTarget == -1) {
// Alerting header will be removed
gentleHeaderTarget--
}
if (currentGentleHeaderIdx != -1) { if (currentGentleHeaderIdx != -1) {
gentleHeaderTarget-- gentleHeaderTarget--
} }

View File

@@ -403,11 +403,11 @@ public class NotificationSectionsManagerTest extends SysuiTestCase {
enablePeopleFiltering(); enablePeopleFiltering();
setupMockStack( setupMockStack(
PERSON.headsUp(), PERSON.headsUp(), // personHeaderTarget = 0
INCOMING_HEADER, INCOMING_HEADER, // currentIncomingHeaderIdx = 1
ALERTING.headsUp(), ALERTING.headsUp(), // alertingHeaderTarget = 1
PEOPLE_HEADER, PEOPLE_HEADER, // currentPeopleHeaderIdx = 3
PERSON PERSON //
); );
mSectionsManager.updateSectionBoundaries(); mSectionsManager.updateSectionBoundaries();