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

Commit 7956fe85 authored by Evan Laird's avatar Evan Laird
Browse files

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
parent 782e511f
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -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                                                 <on/off>
 *   - Channel from which we launched                           <on/off>
 *   -                                                          <on/off>
 *   - the next 3 channels sorted alphabetically for that app   <on/off>
 *   -                                                          <on/off>
 */
@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<NotificationChannel>()
@@ -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<TextView>(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()
}
+6 −4
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }