diff options
3 files changed, 86 insertions, 11 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelperTest.kt index 51de9d5d7514..87cd728d106f 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelperTest.kt @@ -14,6 +14,7 @@ import junit.framework.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.kotlin.whenever /** Tests for {@link NotificationTargetsHelper}. */ @SmallTest @@ -21,7 +22,7 @@ import org.junit.runner.RunWith @RunWithLooper class NotificationTargetsHelperTest : SysuiTestCase() { private val featureFlags = FakeFeatureFlagsClassic() - lateinit var notificationTestHelper: NotificationTestHelper + private lateinit var notificationTestHelper: NotificationTestHelper private val sectionsManager: NotificationSectionsManager = mock() private val stackScrollLayout: NotificationStackScrollLayout = mock() @@ -107,7 +108,12 @@ class NotificationTargetsHelperTest : SysuiTestCase() { // THEN all the views that surround it become targets with the swiped view at the middle val actual = notificationTargetsHelper() - .findMagneticTargets(viewSwiped = swiped, stackScrollLayout = stackScrollLayout, 5) + .findMagneticTargets( + viewSwiped = swiped, + stackScrollLayout = stackScrollLayout, + sectionsManager, + totalMagneticTargets = 5, + ) assertMagneticTargetsForChildren(actual, children.attachedChildren) } @@ -123,7 +129,12 @@ class NotificationTargetsHelperTest : SysuiTestCase() { // to the left val actual = notificationTargetsHelper() - .findMagneticTargets(viewSwiped = swiped, stackScrollLayout = stackScrollLayout, 5) + .findMagneticTargets( + viewSwiped = swiped, + stackScrollLayout = stackScrollLayout, + sectionsManager, + totalMagneticTargets = 5, + ) val expectedRows = listOf(null, null, swiped, children.attachedChildren[1], children.attachedChildren[2]) assertMagneticTargetsForChildren(actual, expectedRows) @@ -141,7 +152,12 @@ class NotificationTargetsHelperTest : SysuiTestCase() { // to the right val actual = notificationTargetsHelper() - .findMagneticTargets(viewSwiped = swiped, stackScrollLayout = stackScrollLayout, 5) + .findMagneticTargets( + viewSwiped = swiped, + stackScrollLayout = stackScrollLayout, + sectionsManager, + totalMagneticTargets = 5, + ) val expectedRows = listOf( children.attachedChildren[childrenNumber - 3], @@ -153,6 +169,54 @@ class NotificationTargetsHelperTest : SysuiTestCase() { assertMagneticTargetsForChildren(actual, expectedRows) } + @Test + fun findMagneticTargets_doesNotCrossSectionAtTop() { + val childrenNumber = 5 + val children = notificationTestHelper.createGroup(childrenNumber).childrenContainer + + // WHEN the second child is swiped and the first one begins a new section + val swiped = children.attachedChildren[1] + whenever(sectionsManager.beginsSection(swiped, children.attachedChildren[0])).then { true } + + // THEN the neighboring views become targets, with the swiped view at the middle and nulls + // to the left since the top view relative to swiped begins a new section + val actual = + notificationTargetsHelper() + .findMagneticTargets( + viewSwiped = swiped, + stackScrollLayout = stackScrollLayout, + sectionsManager, + totalMagneticTargets = 5, + ) + val expectedRows = + listOf(null, null, swiped, children.attachedChildren[2], children.attachedChildren[3]) + assertMagneticTargetsForChildren(actual, expectedRows) + } + + @Test + fun findMagneticTargets_doesNotCrossSectionAtBottom() { + val childrenNumber = 5 + val children = notificationTestHelper.createGroup(childrenNumber).childrenContainer + + // WHEN the fourth child is swiped and the last one begins a new section + val swiped = children.attachedChildren[3] + whenever(sectionsManager.beginsSection(children.attachedChildren[4], swiped)).then { true } + + // THEN the neighboring views become targets, with the swiped view at the middle and nulls + // to the right since the bottom view relative to swiped begins a new section + val actual = + notificationTargetsHelper() + .findMagneticTargets( + viewSwiped = swiped, + stackScrollLayout = stackScrollLayout, + sectionsManager, + totalMagneticTargets = 5, + ) + val expectedRows = + listOf(children.attachedChildren[1], children.attachedChildren[2], swiped, null, null) + assertMagneticTargetsForChildren(actual, expectedRows) + } + private fun assertMagneticTargetsForChildren( targets: List<MagneticRowListener?>, children: List<ExpandableNotificationRow?>, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/MagneticNotificationRowManagerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/MagneticNotificationRowManagerImpl.kt index a507c4ceecd2..31e78c51b5aa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/MagneticNotificationRowManagerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/MagneticNotificationRowManagerImpl.kt @@ -95,12 +95,15 @@ constructor( notificationTargetsHelper.findMagneticTargets( expandableNotificationRow, stackScrollLayout, + sectionsManager, MAGNETIC_TRANSLATION_MULTIPLIERS.size, ) - currentMagneticListeners.swipedListener()?.cancelTranslationAnimations() newListeners.forEach { if (currentMagneticListeners.contains(it)) { it?.cancelMagneticAnimations() + if (it == currentMagneticListeners.swipedListener()) { + it?.cancelTranslationAnimations() + } } } currentMagneticListeners = newListeners diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelper.kt index b69b936ea9f0..8d7b2209ac43 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationTargetsHelper.kt @@ -5,7 +5,6 @@ import androidx.core.view.isVisible import com.android.systemui.dagger.SysUISingleton import com.android.systemui.statusbar.NotificationShelf import com.android.systemui.statusbar.notification.Roundable -import com.android.systemui.statusbar.notification.footer.ui.view.FooterView import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableView import javax.inject.Inject @@ -88,6 +87,7 @@ class NotificationTargetsHelper @Inject constructor() { * * @param[viewSwiped] The [ExpandableNotificationRow] that is swiped. * @param[stackScrollLayout] [NotificationStackScrollLayout] container. + * @param[sectionsManager] The [NotificationSectionsManager] * @param[totalMagneticTargets] The total number of magnetic listeners in the resulting list. * This includes the listener of the view swiped. * @return The list of [MagneticRowListener]s above and below the swiped @@ -96,6 +96,7 @@ class NotificationTargetsHelper @Inject constructor() { fun findMagneticTargets( viewSwiped: ExpandableNotificationRow, stackScrollLayout: NotificationStackScrollLayout, + sectionsManager: NotificationSectionsManager, totalMagneticTargets: Int, ): List<MagneticRowListener?> { val notificationParent = viewSwiped.notificationParent @@ -126,26 +127,34 @@ class NotificationTargetsHelper @Inject constructor() { var canMoveRight = true for (distance in 1..totalMagneticTargets / 2) { if (canMoveLeft) { - val leftElement = container.getOrNull(index = centerIndex - distance) + val leftElement = + container.getOrNull(index = centerIndex - distance)?.takeIf { + it.isValidMagneticBoundary() || + !sectionsManager.beginsSection(view = viewSwiped, previous = it) + } if (leftElement is ExpandableNotificationRow) { magneticTargets[leftIndex] = leftElement.magneticRowListener leftIndex-- } else { if (leftElement.isValidMagneticBoundary()) { - // Add the boundary and then stop the iterating + // Add the boundary and then stop iterating magneticTargets[leftIndex] = leftElement?.magneticRowListener } canMoveLeft = false } } if (canMoveRight) { - val rightElement = container.getOrNull(index = centerIndex + distance) + val rightElement = + container.getOrNull(index = centerIndex + distance)?.takeIf { + it.isValidMagneticBoundary() || + !sectionsManager.beginsSection(view = it, previous = viewSwiped) + } if (rightElement is ExpandableNotificationRow) { magneticTargets[rightIndex] = rightElement.magneticRowListener rightIndex++ } else { if (rightElement.isValidMagneticBoundary()) { - // Add the boundary and then stop the iterating + // Add the boundary and then stop iterating magneticTargets[rightIndex] = rightElement?.magneticRowListener } canMoveRight = false @@ -157,7 +166,6 @@ class NotificationTargetsHelper @Inject constructor() { private fun ExpandableView?.isValidMagneticBoundary(): Boolean = when (this) { - is FooterView, is NotificationShelf, is SectionHeaderView -> true else -> false |