Allow turning off currently active modes
Even if they don't allow manual invocation. The button will disappear afterwards -- maybe not perfect but good enough. Fixes: 355613076 Test: atest ZenModeButtonPreferenceControllerTest Flag: android.app.modes_ui Change-Id: I36cc96f7da78266be1a03e947304fc8e600899de
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
@@ -36,8 +38,8 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
|
||||
private static final String TAG = "ZenModeButtonPrefController";
|
||||
|
||||
private Button mZenButton;
|
||||
private Fragment mParent;
|
||||
private ManualDurationHelper mDurationHelper;
|
||||
private final Fragment mParent;
|
||||
private final ManualDurationHelper mDurationHelper;
|
||||
|
||||
ZenModeButtonPreferenceController(Context context, String key, Fragment parent,
|
||||
ZenModesBackend backend) {
|
||||
@@ -48,7 +50,8 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(ZenMode zenMode) {
|
||||
return zenMode.getRule().isManualInvocationAllowed() && zenMode.getRule().isEnabled();
|
||||
return zenMode.isEnabled()
|
||||
&& (zenMode.isActive() || zenMode.getRule().isManualInvocationAllowed());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +60,7 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
|
||||
mZenButton = ((LayoutPreference) preference).findViewById(R.id.activate_mode);
|
||||
}
|
||||
mZenButton.setOnClickListener(v -> {
|
||||
checkNotNull(mBackend, "Backend not available!");
|
||||
if (zenMode.isActive()) {
|
||||
mBackend.deactivateMode(zenMode);
|
||||
} else {
|
||||
|
@@ -89,6 +89,16 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_ifModeActiveEvenIfAppOptsOut() {
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(false)
|
||||
.setActive(true)
|
||||
.build();
|
||||
mController.setZenMode(zenMode);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notIfModeDisabled() {
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
@@ -119,7 +129,6 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setActive(true)
|
||||
.build();
|
||||
|
||||
@@ -151,7 +160,6 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setActive(true)
|
||||
.build();
|
||||
|
||||
|
Reference in New Issue
Block a user