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

Commit 18bd6e67 authored by Evan Laird's avatar Evan Laird
Browse files

Only use "apply" when there are changes

ChannelEditorDialog now only uses the word "apply" when there are edits
to be made by pressing the button. Otherwise use "done"

Also removed ChannelEditorDialog from Dependency to allow for better
testing / initialization of the class

Test: atest ChannelEditorDialogControllerTest
Fixes: 138957374
Change-Id: Idc111ccb0bee50df65f4037d3e552b498e135660
parent 65225acf
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -76,7 +76,6 @@ import com.android.systemui.statusbar.notification.NotificationEntryManager.Keyg
import com.android.systemui.statusbar.notification.NotificationFilter;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.ChannelEditorDialogController;
import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.phone.AutoHideController;
@@ -308,7 +307,6 @@ public class Dependency {
    @Inject Lazy<PackageManagerWrapper> mPackageManagerWrapper;
    @Inject Lazy<SensorPrivacyController> mSensorPrivacyController;
    @Inject Lazy<DockManager> mDockManager;
    @Inject Lazy<ChannelEditorDialogController> mChannelEditorDialogController;
    @Inject Lazy<INotificationManager> mINotificationManager;
    @Inject Lazy<SysUiState> mSysUiStateFlagsContainer;
    @Inject Lazy<AlarmManager> mAlarmManager;
@@ -498,7 +496,6 @@ public class Dependency {
        mProviders.put(PackageManagerWrapper.class, mPackageManagerWrapper::get);
        mProviders.put(SensorPrivacyController.class, mSensorPrivacyController::get);
        mProviders.put(DockManager.class, mDockManager::get);
        mProviders.put(ChannelEditorDialogController.class, mChannelEditorDialogController::get);
        mProviders.put(INotificationManager.class, mINotificationManager::get);
        mProviders.put(SysUiState.class, mSysUiStateFlagsContainer::get);
        mProviders.put(AlarmManager.class, mAlarmManager::get);
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.systemui.statusbar.notification.interruption.NotificationInte
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLogger;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLoggerImpl;
import com.android.systemui.statusbar.notification.row.ChannelEditorDialogController;
import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.PriorityOnboardingDialogController;
@@ -111,6 +112,7 @@ public interface NotificationsModule {
            INotificationManager notificationManager,
            LauncherApps launcherApps,
            ShortcutManager shortcutManager,
            ChannelEditorDialogController channelEditorDialogController,
            CurrentUserContextTracker contextTracker,
            Provider<PriorityOnboardingDialogController.Builder> builderProvider) {
        return new NotificationGutsManager(
@@ -123,6 +125,7 @@ public interface NotificationsModule {
                notificationManager,
                launcherApps,
                shortcutManager,
                channelEditorDialogController,
                contextTracker,
                builderProvider);
    }
+62 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.NotificationChannel
import android.app.NotificationChannel.DEFAULT_CHANNEL_ID
import android.app.NotificationChannelGroup
import android.app.NotificationManager.IMPORTANCE_NONE
import android.app.NotificationManager.Importance
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
@@ -37,8 +38,10 @@ import android.view.Window
import android.view.WindowInsets.Type.statusBars
import android.view.WindowManager
import android.widget.TextView

import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.R

import javax.inject.Inject
import javax.inject.Singleton

@@ -59,11 +62,13 @@ private const val TAG = "ChannelDialogController"
@Singleton
class ChannelEditorDialogController @Inject constructor(
    c: Context,
    private val noMan: INotificationManager
    private val noMan: INotificationManager,
    private val dialogBuilder: ChannelEditorDialog.Builder
) {
    val context: Context = c.applicationContext

    lateinit var dialog: Dialog
    private var prepared = false
    private lateinit var dialog: ChannelEditorDialog

    private var appIcon: Drawable? = null
    private var appUid: Int? = null
@@ -80,7 +85,9 @@ class ChannelEditorDialogController @Inject constructor(

    // Map from NotificationChannel to importance
    private val edits = mutableMapOf<NotificationChannel, Int>()
    var appNotificationsEnabled = true
    private var appNotificationsEnabled = true
    // System settings for app notifications
    private var appNotificationsCurrentlyEnabled: Boolean? = null

    // Keep a mapping of NotificationChannel.getGroup() to the actual group name for display
    @VisibleForTesting
@@ -106,10 +113,16 @@ class ChannelEditorDialogController @Inject constructor(
        this.appNotificationsEnabled = checkAreAppNotificationsOn()
        this.onSettingsClickListener = onSettingsClickListener

        // These will always start out the same
        appNotificationsCurrentlyEnabled = appNotificationsEnabled

        channelGroupList.clear()
        channelGroupList.addAll(fetchNotificationChannelGroups())
        buildGroupNameLookup()
        padToFourChannels(channels)
        initDialog()

        prepared = true
    }

    private fun buildGroupNameLookup() {
@@ -157,7 +170,9 @@ class ChannelEditorDialogController @Inject constructor(
    }

    fun show() {
        initDialog()
        if (!prepared) {
            throw IllegalStateException("Must call prepareDialogForApp() before calling show()")
        }
        dialog.show()
    }

@@ -178,6 +193,7 @@ class ChannelEditorDialogController @Inject constructor(
        appUid = null
        packageName = null
        appName = null
        appNotificationsCurrentlyEnabled = null

        edits.clear()
        providedChannels.clear()
@@ -188,12 +204,27 @@ class ChannelEditorDialogController @Inject constructor(
        return groupNameLookup[groupId] ?: ""
    }

    fun proposeEditForChannel(channel: NotificationChannel, edit: Int) {
    fun proposeEditForChannel(channel: NotificationChannel, @Importance edit: Int) {
        if (channel.importance == edit) {
            edits.remove(channel)
        } else {
            edits[channel] = edit
        }

        dialog.updateDoneButtonText(hasChanges())
    }

    fun proposeSetAppNotificationsEnabled(enabled: Boolean) {
        appNotificationsEnabled = enabled
        dialog.updateDoneButtonText(hasChanges())
    }

    fun areAppNotificationsEnabled(): Boolean {
        return appNotificationsEnabled
    }

    private fun hasChanges(): Boolean {
        return edits.isNotEmpty() || (appNotificationsEnabled != appNotificationsCurrentlyEnabled)
    }

    @Suppress("unchecked_cast")
@@ -241,7 +272,7 @@ class ChannelEditorDialogController @Inject constructor(
            }
        }

        if (appNotificationsEnabled != checkAreAppNotificationsOn()) {
        if (appNotificationsEnabled != appNotificationsCurrentlyEnabled) {
            applyAppNotificationsOn(appNotificationsEnabled)
        }
    }
@@ -252,7 +283,8 @@ class ChannelEditorDialogController @Inject constructor(
    }

    private fun initDialog() {
        dialog = Dialog(context)
        dialogBuilder.setContext(context)
        dialog = dialogBuilder.build()

        dialog.window?.requestFeature(Window.FEATURE_NO_TITLE)
        // Prevent a11y readers from reading the first element in the dialog twice
@@ -265,7 +297,7 @@ class ChannelEditorDialogController @Inject constructor(
                    onFinishListener?.onChannelEditorDialogFinished()
                }
            })
            findViewById<ChannelEditorListView>(R.id.half_shelf_container).apply {
            findViewById<ChannelEditorListView>(R.id.half_shelf_container)?.apply {
                controller = this@ChannelEditorDialogController
                appIcon = this@ChannelEditorDialogController.appIcon
                appName = this@ChannelEditorDialogController.appName
@@ -306,6 +338,28 @@ class ChannelEditorDialogController @Inject constructor(
            or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
}

class ChannelEditorDialog(context: Context) : Dialog(context) {
    fun updateDoneButtonText(hasChanges: Boolean) {
        findViewById<TextView>(R.id.done_button)?.setText(
                if (hasChanges)
                    R.string.inline_ok_button
                else
                    R.string.inline_done_button)
    }

    class Builder @Inject constructor() {
        private lateinit var context: Context
        fun setContext(context: Context): Builder {
            this.context = context
            return this
        }

        fun build(): ChannelEditorDialog {
            return ChannelEditorDialog(context)
        }
    }
}

interface OnChannelEditorDialogFinishedListener {
    fun onChannelEditorDialogFinished()
}
+3 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a
    }

    private fun updateRows() {
        val enabled = controller.appNotificationsEnabled
        val enabled = controller.areAppNotificationsEnabled()

        val transition = AutoTransition()
        transition.duration = 200
@@ -114,7 +114,7 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a
                .getString(R.string.notification_channel_dialog_title, appName)
        appControlRow.switch.isChecked = enabled
        appControlRow.switch.setOnCheckedChangeListener { _, b ->
            controller.appNotificationsEnabled = b
            controller.proposeSetAppNotificationsEnabled(b)
            updateRows()
        }
    }
@@ -150,6 +150,7 @@ class ChannelRow(c: Context, attrs: AttributeSet) : LinearLayout(c, attrs) {
        }

    override fun onFinishInflate() {
        super.onFinishInflate()
        channelName = findViewById(R.id.channel_name)
        channelDescription = findViewById(R.id.channel_description)
        switch = findViewById(R.id.toggle)
+5 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
    private final VisualStabilityManager mVisualStabilityManager;
    private final AccessibilityManager mAccessibilityManager;
    private final HighPriorityProvider mHighPriorityProvider;
    private final ChannelEditorDialogController mChannelEditorDialogController;

    // Dependencies:
    private final NotificationLockscreenUserManager mLockscreenUserManager =
@@ -127,6 +128,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
            INotificationManager notificationManager,
            LauncherApps launcherApps,
            ShortcutManager shortcutManager,
            ChannelEditorDialogController channelEditorDialogController,
            CurrentUserContextTracker contextTracker,
            Provider<PriorityOnboardingDialogController.Builder> builderProvider) {
        mContext = context;
@@ -140,6 +142,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
        mShortcutManager = shortcutManager;
        mContextTracker = contextTracker;
        mBuilderProvider = builderProvider;
        mChannelEditorDialogController = channelEditorDialogController;
    }

    public void setUpWithPresenter(NotificationPresenter presenter,
@@ -348,6 +351,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
                pmUser,
                mNotificationManager,
                mVisualStabilityManager,
                mChannelEditorDialogController,
                packageName,
                row.getEntry().getChannel(),
                row.getUniqueChannels(),
@@ -390,6 +394,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
        notificationInfoView.bindNotification(
                pmUser,
                mNotificationManager,
                mChannelEditorDialogController,
                packageName,
                row.getEntry().getChannel(),
                row.getUniqueChannels(),
Loading