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

Commit 81ebe383 authored by Tony Wickham's avatar Tony Wickham
Browse files

Small cleanup for notifications

- Add null check when collapsing footer, as container could be null
  if the app is opened
- Remove redundant method that always passed mNotificationItemView
- Set mNotificationItemView to null when it is removed

Change-Id: Ia329815224b213fc688733eaaf6f29ee6888caaf
parent a431fbb8
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -198,6 +198,7 @@ public class NotificationFooterLayout extends FrameLayout {
            // There are no more icons in the footer, so hide it.
            // There are no more icons in the footer, so hide it.
            PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(
            PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(
                    Launcher.getLauncher(getContext()));
                    Launcher.getLauncher(getContext()));
            if (popup != null) {
                Animator collapseFooter = popup.reduceNotificationViewHeight(getHeight(),
                Animator collapseFooter = popup.reduceNotificationViewHeight(getHeight(),
                        getResources().getInteger(R.integer.config_removeNotificationViewDuration));
                        getResources().getInteger(R.integer.config_removeNotificationViewDuration));
                collapseFooter.addListener(new AnimatorListenerAdapter() {
                collapseFooter.addListener(new AnimatorListenerAdapter() {
@@ -209,6 +210,7 @@ public class NotificationFooterLayout extends FrameLayout {
                collapseFooter.start();
                collapseFooter.start();
            }
            }
        }
        }
    }


    public void trimNotifications(List<String> notifications) {
    public void trimNotifications(List<String> notifications) {
        if (!isAttachedToWindow() || mIconRow.getChildCount() == 0) {
        if (!isAttachedToWindow() || mIconRow.getChildCount() == 0) {
+0 −3
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.FrameLayout;


import com.android.launcher3.ItemInfo;
import com.android.launcher3.ItemInfo;
@@ -85,8 +84,6 @@ public class NotificationItemView extends PopupItemView implements LogContainerP
                            MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY));
                            MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY));
                    initializeBackgroundClipping(true /* force */);
                    initializeBackgroundClipping(true /* force */);
                    invalidate();
                    invalidate();
                } else {
                    ((ViewGroup) getParent()).removeView(NotificationItemView.this);
                }
                }
            }
            }
        });
        });
+6 −9
Original line number Original line Diff line number Diff line
@@ -568,7 +568,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
                    R.integer.config_removeNotificationViewDuration);
                    R.integer.config_removeNotificationViewDuration);
            final int spacing = getResources().getDimensionPixelSize(R.dimen.popup_items_spacing);
            final int spacing = getResources().getDimensionPixelSize(R.dimen.popup_items_spacing);
            removeNotification.play(reduceNotificationViewHeight(
            removeNotification.play(reduceNotificationViewHeight(
                    mNotificationItemView.getHeight() + spacing, duration, mNotificationItemView));
                    mNotificationItemView.getHeight() + spacing, duration));
            final View removeMarginView = mIsAboveIcon ? getItemViewAt(getItemCount() - 2)
            final View removeMarginView = mIsAboveIcon ? getItemViewAt(getItemCount() - 2)
                    : mNotificationItemView;
                    : mNotificationItemView;
            if (removeMarginView != null) {
            if (removeMarginView != null) {
@@ -588,6 +588,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
                @Override
                @Override
                public void onAnimationEnd(Animator animation) {
                public void onAnimationEnd(Animator animation) {
                    removeView(mNotificationItemView);
                    removeView(mNotificationItemView);
                    mNotificationItemView = null;
                    if (getItemCount() == 0) {
                    if (getItemCount() == 0) {
                        close(false);
                        close(false);
                        return;
                        return;
@@ -612,19 +613,19 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
        return LauncherAnimUtils.ofPropertyValuesHolder(
        return LauncherAnimUtils.ofPropertyValuesHolder(
                mArrow, new PropertyListBuilder().scale(scale).build());
                mArrow, new PropertyListBuilder().scale(scale).build());
    }
    }

    /**
    /**
     * Animates the height of the notification item and the translationY of other items accordingly.
     * Animates the height of the notification item and the translationY of other items accordingly.
     */
     */
    public Animator reduceNotificationViewHeight(int heightToRemove, int duration,
    public Animator reduceNotificationViewHeight(int heightToRemove, int duration) {
            NotificationItemView notificationItem) {
        final int translateYBy = mIsAboveIcon ? heightToRemove : -heightToRemove;
        final int translateYBy = mIsAboveIcon ? heightToRemove : -heightToRemove;
        AnimatorSet animatorSet = LauncherAnimUtils.createAnimatorSet();
        AnimatorSet animatorSet = LauncherAnimUtils.createAnimatorSet();
        animatorSet.play(notificationItem.animateHeightRemoval(heightToRemove));
        animatorSet.play(mNotificationItemView.animateHeightRemoval(heightToRemove));
        PropertyResetListener<View, Float> resetTranslationYListener
        PropertyResetListener<View, Float> resetTranslationYListener
                = new PropertyResetListener<>(TRANSLATION_Y, 0f);
                = new PropertyResetListener<>(TRANSLATION_Y, 0f);
        for (int i = 0; i < getItemCount(); i++) {
        for (int i = 0; i < getItemCount(); i++) {
            final PopupItemView itemView = getItemViewAt(i);
            final PopupItemView itemView = getItemViewAt(i);
            if (!mIsAboveIcon && itemView == notificationItem) {
            if (!mIsAboveIcon && itemView == mNotificationItemView) {
                // The notification view is already in the right place when container is below icon.
                // The notification view is already in the right place when container is below icon.
                continue;
                continue;
            }
            }
@@ -647,10 +648,6 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
        return animatorSet;
        return animatorSet;
    }
    }


    public Animator reduceNotificationViewHeight(int heightToRemove, int duration) {
        return reduceNotificationViewHeight(heightToRemove, duration, mNotificationItemView);
    }

    @Override
    @Override
    public boolean supportsAppInfoDropTarget() {
    public boolean supportsAppInfoDropTarget() {
        return true;
        return true;