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

Commit fb72b56b authored by Andreas Miko's avatar Andreas Miko
Browse files

Fix bundled groups not expanding on long press

This bug only existed when there is exactly one child in the bundle.
This made the condition trigger that makes sure that when we swipe and
there is only 1 child we swipe the entire group away rather than just
the child.

The problem here is that we can't just modify the condition in
getChildAtPosition as I'm not aware how we could make this judgment
without also knowing which MotionEvent we are dealing with. For a
swipe the dismiss action should still target the parent when conditions
are met but for a longpress we want to target the child. This requires
us to introduce this new method getSwipeTarget() that can implement
specific behavior for ACTION_MOVE.

Bug: b/419100765
Test: Refactor only verified manually
Flag: com.android.systemui.notification_bundle_ui
Change-Id: Iff6370093a25c64a345eec0fe35fa965dc707ce4
parent 6ac2cc9d
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -373,6 +373,10 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
                            : mPagingTouchSlop;
                    if (Math.abs(delta) > pagingTouchSlop
                            && Math.abs(delta) > Math.abs(deltaPerpendicular)) {
                        if (NotificationBundleUi.isEnabled()
                                && mTouchedView instanceof ExpandableNotificationRow row) {
                            mTouchedView = mCallback.getSwipeTarget(row);
                        }
                        if (mCallback.canChildBeDragged(mTouchedView)) {
                            mIsSwiping = true;
                            mCallback.setMagneticAndRoundableTargets(mTouchedView);
@@ -691,10 +695,11 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!mIsSwiping && !mMenuRowIntercepting && !mLongPressSent) {
            if (mCallback.getChildAtPosition(ev) != null) {
            View childAtPosition = mCallback.getChildAtPosition(ev);
            if (childAtPosition != null) {
                // We are dragging directly over a card, make sure that we also catch the gesture
                // even if nobody else wants the touch event.
                mTouchedView = mCallback.getChildAtPosition(ev);
                mTouchedView = childAtPosition;
                onInterceptTouchEvent(ev);
                return true;
            } else {
@@ -1031,6 +1036,13 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
         */
        void onLongPressSent(View v);

        /**
         * Get the swipe target based on the currently touched row. The swipe target may be the
         * parent of the touched row.
         * @return the ENR that should actually handle the swipe event
         */
        ExpandableNotificationRow getSwipeTarget(ExpandableNotificationRow row);

        /**
         * The snap back animation on a view overshoots for the first time.
         */
+27 −1
Original line number Diff line number Diff line
@@ -649,7 +649,8 @@ public class NotificationStackScrollLayoutController implements Dumpable {
                                && (parent.areGutsExposed()
                                || mSwipeHelper.getExposedMenuView() == parent
                                || (parent.getAttachedChildren().size() == 1
                                && mDismissibilityProvider.isDismissable(parent.getKey())))) {
                                && mDismissibilityProvider.isDismissable(parent.getKey())
                                && !NotificationBundleUi.isEnabled()))) {
                            // In this case the group is expanded and showing the menu for the
                            // group, further interaction should apply to the group, not any
                            // child notifications so we use the parent of the child. We also do the
@@ -660,6 +661,31 @@ public class NotificationStackScrollLayoutController implements Dumpable {
                    return child;
                }

                /**
                 * While {@code getChildAtPosition} already contains logic to change the touch
                 * interaction target to the parent based on some conditions, this method
                 * does the same but narrowed down to swipe interactions. This provides the
                 * opportunity to control the target based on the specific touch event.
                 * <p>
                 * For example: A long press may target the directly touched view but a swipe may
                 * target the containing group or bundle when it is dismissable and only has one
                 * child.
                 *
                 * @param row the ENR that has been touched
                 * @return the ENR that should actually handle the swipe event
                 */
                public ExpandableNotificationRow getSwipeTarget(ExpandableNotificationRow row) {
                    ExpandableNotificationRow parent = row.getNotificationParent();
                    if (parent != null && parent.areChildrenExpanded()
                            && parent.getAttachedChildren().size() == 1
                            && mDismissibilityProvider.isDismissable(parent.getKey())) {
                        // We run this recursively to get the parents parent for the case where
                        // you swipe a lonely child in a lonely group within a bundle
                        return getSwipeTarget(parent);
                    }
                    return row;
                }

                @Override
                public void onLongPressSent(View v) {
                    mLongPressedView = v;