From 7956fe855b3112f21f44355de3ce7292b54db8c6 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Thu, 30 May 2019 17:14:57 -0400 Subject: [PATCH] Close notification guts after applying changes ChannelEditorDialogController now tells interested parties about the fact that it wants to dismiss. NotificationInfo also can close itself without saving changes Test: disable top channel in dialog, watch the guts close and notification disappear Bug: 133182818 Change-Id: I70adc7dc0d6b9a8a207cdff0b28b281fbd24e18a --- .../row/ChannelEditorDialogController.kt | 22 ++++++++++++++++++- .../notification/row/NotificationInfo.java | 10 +++++---- .../row/NotificationInfoTest.java | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt index b89b5cb34d7a4..46490cd878b59 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogController.kt @@ -43,6 +43,18 @@ import javax.inject.Singleton const val TAG = "ChannelDialogController" +/** + * ChannelEditorDialogController is the controller for the dialog half-shelf + * that allows users to quickly turn off channels. It is launched from the NotificationInfo + * guts view and displays controls for toggling app notifications as well as up to 4 channels + * from that app like so: + * + * APP TOGGLE + * - Channel from which we launched + * - + * - the next 3 channels sorted alphabetically for that app + * - + */ @Singleton class ChannelEditorDialogController @Inject constructor( c: Context, @@ -58,6 +70,9 @@ class ChannelEditorDialogController @Inject constructor( private var appName: String? = null private var onSettingsClickListener: NotificationInfo.OnSettingsClickListener? = null + // Caller should set this if they care about when we dismiss + var onFinishListener: OnChannelEditorDialogFinishedListener? = null + // Channels handed to us from NotificationInfo @VisibleForTesting internal val providedChannels = mutableListOf() @@ -144,6 +159,7 @@ class ChannelEditorDialogController @Inject constructor( private fun done() { resetState() dialog.dismiss() + onFinishListener?.onChannelEditorDialogFinished() } private fun resetState() { @@ -240,7 +256,7 @@ class ChannelEditorDialogController @Inject constructor( findViewById(R.id.see_more_button)?.setOnClickListener { onSettingsClickListener?.onClick(it, null, appUid!!) - dismiss() + done() } window?.apply { @@ -265,3 +281,7 @@ class ChannelEditorDialogController @Inject constructor( or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) } + +interface OnChannelEditorDialogFinishedListener { + fun onChannelEditorDialogFinished() +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java index 1dc96b82f4a58..626701c6cb349 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java @@ -159,13 +159,13 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G // used by standard ui private OnClickListener mOnDismissSettings = v -> { mPressedApply = true; - closeControls(v); + closeControls(v, true); }; // used by blocking helper private OnClickListener mOnKeepShowing = v -> { mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING; - closeControls(v); + closeControls(v, true); mMetricsLogger.write(getLogMaker().setCategory( MetricsEvent.NOTIFICATION_BLOCKING_HELPER) .setType(MetricsEvent.TYPE_ACTION) @@ -445,6 +445,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G if (mChannelEditorDialogController != null) { mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); + mChannelEditorDialogController.setOnFinishListener( + () -> closeControls(this, false)); mChannelEditorDialogController.show(); } }); @@ -725,7 +727,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G * {@link #swapContent(boolean, boolean)} for where undo is handled. */ @VisibleForTesting - void closeControls(View v) { + void closeControls(View v, boolean save) { int[] parentLoc = new int[2]; int[] targetLoc = new int[2]; mGutsContainer.getLocationOnScreen(parentLoc); @@ -734,7 +736,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G final int centerY = v.getHeight() / 2; final int x = targetLoc[0] - parentLoc[0] + centerX; final int y = targetLoc[1] - parentLoc[1] + centerY; - mGutsContainer.closeControls(x, y, true /* save */, false /* force */); + mGutsContainer.closeControls(x, y, save, false /* force */); } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java index 06acc73ac48ca..78970d9658e20 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java @@ -646,7 +646,7 @@ public class NotificationInfoTest extends SysuiTestCase { doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); mNotificationInfo.setGutsParent(guts); - mNotificationInfo.closeControls(mNotificationInfo); + mNotificationInfo.closeControls(mNotificationInfo, true); verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); }