diff --git a/res/layout/zen_mode_senders_overlay_image.xml b/res/layout/zen_mode_senders_overlay_image.xml
deleted file mode 100644
index eba98dad5b0..00000000000
--- a/res/layout/zen_mode_senders_overlay_image.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 57e47f2ec91..2f3d875ba36 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -51,9 +51,6 @@
32dp
24dp
- 24dp
- 32dp
- 50dp
7dp
17dp
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0da23718f09..aa6304b9519 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8179,8 +8179,6 @@
Conversations
-
- Conversations that can interrupt
All conversations
Priority conversations
diff --git a/res/xml/zen_mode_conversations_settings.xml b/res/xml/zen_mode_conversations_settings.xml
deleted file mode 100644
index e72d03ccb6a..00000000000
--- a/res/xml/zen_mode_conversations_settings.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/com/android/settings/notification/zen/ZenModeBackend.java b/src/com/android/settings/notification/zen/ZenModeBackend.java
index 85f9aeea5fe..10798652e68 100644
--- a/src/com/android/settings/notification/zen/ZenModeBackend.java
+++ b/src/com/android/settings/notification/zen/ZenModeBackend.java
@@ -312,21 +312,6 @@ public class ZenModeBackend {
return R.string.zen_mode_from_no_conversations;
}
- protected int getConversationSummary() {
- int conversationType = getPriorityConversationSenders();
-
- switch (conversationType) {
- case NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE:
- return R.string.zen_mode_from_all_conversations;
- case NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT:
- return R.string.zen_mode_from_important_conversations;
- case NotificationManager.Policy.CONVERSATION_SENDERS_NONE:
- return R.string.zen_mode_from_no_conversations;
- default:
- return R.string.zen_mode_from_no_conversations;
- }
- }
-
protected int getContactsCallsSummary(ZenPolicy policy) {
int peopleType = policy.getPriorityCallSenders();
switch (peopleType) {
diff --git a/src/com/android/settings/notification/zen/ZenModeConversationsImagePreferenceController.java b/src/com/android/settings/notification/zen/ZenModeConversationsImagePreferenceController.java
deleted file mode 100644
index 78c81341865..00000000000
--- a/src/com/android/settings/notification/zen/ZenModeConversationsImagePreferenceController.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification.zen;
-
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
-
-import android.content.Context;
-import android.content.pm.ParceledListSlice;
-import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
-import android.service.notification.ConversationChannelWrapper;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.widget.LayoutPreference;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Updates the DND Settings conversations image resource based on the conversations channels.
- */
-public class ZenModeConversationsImagePreferenceController
- extends AbstractZenModePreferenceController {
- private static final int MAX_CONVERSATIONS_SHOWN = 5;
- private final int mIconSizePx;
- private final int mIconOffsetPx;
- private final ArrayList mConversationDrawables = new ArrayList<>();
- private final NotificationBackend mNotificationBackend;
-
- private ViewGroup mViewGroup;
- private LayoutPreference mPreference;
-
- public ZenModeConversationsImagePreferenceController(Context context, String key,
- Lifecycle lifecycle, NotificationBackend notificationBackend) {
- super(context, key, lifecycle);
- mNotificationBackend = notificationBackend;
- mIconSizePx =
- mContext.getResources().getDimensionPixelSize(R.dimen.zen_conversations_icon_size);
- mIconOffsetPx = mContext.getResources()
- .getDimensionPixelSize(R.dimen.zen_conversations_icon_offset);
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = (LayoutPreference) screen.findPreference(KEY);
- mViewGroup =
- (ViewGroup) mPreference.findViewById(R.id.zen_mode_settings_senders_overlay_view);
- loadConversations();
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY;
- }
-
- @Override
- public void updateState(Preference preference) {
- loadConversations();
-
- mViewGroup.removeAllViews();
- final int conversationSenders = mBackend.getPriorityConversationSenders();
- if (conversationSenders == CONVERSATION_SENDERS_ANYONE) {
- mViewGroup.setContentDescription(
- mContext.getResources().getString(R.string.zen_mode_from_all_conversations));
- } else if (conversationSenders == CONVERSATION_SENDERS_IMPORTANT) {
- mViewGroup.setContentDescription(
- mContext.getResources().getString(
- R.string.zen_mode_from_important_conversations));
- } else {
- mViewGroup.setContentDescription(null);
- mViewGroup.setVisibility(View.GONE);
- return;
- }
-
- final int numDrawablesToShow = Math.min(MAX_CONVERSATIONS_SHOWN,
- mConversationDrawables.size());
- for (int i = 0; i < numDrawablesToShow; i++) {
- ImageView iv = new ImageView(mContext);
- iv.setImageDrawable(mConversationDrawables.get(i));
- iv.setLayoutParams(new ViewGroup.LayoutParams(mIconSizePx, mIconSizePx));
-
- FrameLayout fl = new FrameLayout(mContext);
- fl.addView(iv);
- fl.setPadding((numDrawablesToShow - i - 1) * mIconOffsetPx, 0, 0, 0);
- mViewGroup.addView(fl);
- }
-
- mViewGroup.setVisibility(numDrawablesToShow > 0 ? View.VISIBLE : View.GONE);
- }
-
- private void loadConversations() {
- // Load conversations
- new AsyncTask() {
- private List mDrawables = new ArrayList<>();
- @Override
- protected Void doInBackground(Void... unused) {
- mDrawables.clear();
- final int conversationSenders = mBackend.getPriorityConversationSenders();
- if (conversationSenders == CONVERSATION_SENDERS_NONE) {
- return null;
- }
- ParceledListSlice conversations =
- mNotificationBackend.getConversations(
- conversationSenders == CONVERSATION_SENDERS_IMPORTANT);
- if (conversations != null) {
- for (ConversationChannelWrapper conversation : conversations.getList()) {
- if (!conversation.getNotificationChannel().isDemoted()) {
- Drawable drawable = mNotificationBackend.getConversationDrawable(
- mContext,
- conversation.getShortcutInfo(),
- conversation.getPkg(),
- conversation.getUid(),
- conversation.getNotificationChannel()
- .isImportantConversation());
- if (drawable != null) {
- mDrawables.add(drawable);
- }
- }
- }
- }
-
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- if (mContext == null) {
- return;
- }
- mConversationDrawables.clear();
- mConversationDrawables.addAll(mDrawables);
- updateState(mPreference);
- }
- }.execute();
- }
-}
diff --git a/src/com/android/settings/notification/zen/ZenModeConversationsPreferenceController.java b/src/com/android/settings/notification/zen/ZenModeConversationsPreferenceController.java
deleted file mode 100644
index f23bf614ac5..00000000000
--- a/src/com/android/settings/notification/zen/ZenModeConversationsPreferenceController.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification.zen;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-/**
- * Controls the summary for preference found at:
- * Settings > Sound > Do Not Disturb > People > Conversations
- */
-public class ZenModeConversationsPreferenceController extends AbstractZenModePreferenceController {
- private final ZenModeBackend mBackend;
- private Preference mPreference;
-
- public ZenModeConversationsPreferenceController(Context context,
- String key, Lifecycle lifecycle) {
- super(context, key, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY;
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(KEY);
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- switch (getZenMode()) {
- case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
- case Settings.Global.ZEN_MODE_ALARMS:
- mPreference.setEnabled(false);
- mPreference.setSummary(mBackend.getAlarmsTotalSilencePeopleSummary(
- NotificationManager.Policy.PRIORITY_CATEGORY_CONVERSATIONS));
- break;
- default:
- preference.setEnabled(true);
- preference.setSummary(mBackend.getConversationSummary());
- }
- }
-}
diff --git a/src/com/android/settings/notification/zen/ZenModeConversationsSettings.java b/src/com/android/settings/notification/zen/ZenModeConversationsSettings.java
deleted file mode 100644
index 5c68126f044..00000000000
--- a/src/com/android/settings/notification/zen/ZenModeConversationsSettings.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification.zen;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-
-import com.android.settings.R;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.search.SearchIndexable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Settings > Sound > Do Not Disturb > Conversations
- */
-@SearchIndexable
-public class ZenModeConversationsSettings extends ZenModeSettingsBase {
- private final NotificationBackend mNotificationBackend = new NotificationBackend();
-
- @Override
- protected List createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getSettingsLifecycle(), mNotificationBackend);
- }
-
- private static List buildPreferenceControllers(Context context,
- Lifecycle lifecycle, NotificationBackend notificationBackend) {
- List controllers = new ArrayList<>();
- controllers.add(new ZenModeConversationsImagePreferenceController(context,
- "zen_mode_conversations_image", lifecycle, notificationBackend));
- controllers.add(new ZenModePriorityConversationsPreferenceController(context,
- "zen_mode_conversations_radio_buttons", lifecycle, notificationBackend));
- return controllers;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_conversations_settings;
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DND_CONVERSATIONS;
- }
-
- /**
- * For Search.
- */
- public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.zen_mode_conversations_settings) {
-
- @Override
- public List createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null, null);
- }
- };
-}
diff --git a/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceController.java b/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceController.java
deleted file mode 100644
index a8387a3e41f..00000000000
--- a/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceController.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification.zen;
-
-import android.app.NotificationManager;
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.content.pm.ParceledListSlice;
-import android.icu.text.MessageFormat;
-import android.os.AsyncTask;
-import android.service.notification.ConversationChannelWrapper;
-import android.view.View;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settings.notification.app.ConversationListSettings;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.widget.SelectorWithWidgetPreference;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * Options to choose the priority conversations that are allowed to bypass DND.
- */
-public class ZenModePriorityConversationsPreferenceController
- extends AbstractZenModePreferenceController {
- private static final int UNSET = -1;
- @VisibleForTesting static final String KEY_ALL = "conversations_all";
- @VisibleForTesting static final String KEY_IMPORTANT = "conversations_important";
- @VisibleForTesting static final String KEY_NONE = "conversations_none";
-
- private final NotificationBackend mNotificationBackend;
-
- private int mNumImportantConversations = UNSET;
- private int mNumConversations = UNSET;
- private PreferenceCategory mPreferenceCategory;
- private List mSelectorWithWidgetPreferences = new ArrayList<>();
- private Context mPreferenceScreenContext;
-
- public ZenModePriorityConversationsPreferenceController(Context context, String key,
- Lifecycle lifecycle, NotificationBackend notificationBackend) {
- super(context, key, lifecycle);
- mNotificationBackend = notificationBackend;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- mPreferenceScreenContext = screen.getContext();
- mPreferenceCategory = screen.findPreference(getPreferenceKey());
- if (mPreferenceCategory.findPreference(KEY_ALL) == null) {
- makeRadioPreference(KEY_ALL, R.string.zen_mode_from_all_conversations);
- makeRadioPreference(KEY_IMPORTANT, R.string.zen_mode_from_important_conversations);
- makeRadioPreference(KEY_NONE, R.string.zen_mode_from_no_conversations);
- updateChannelCounts();
- }
-
- super.displayPreference(screen);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- updateChannelCounts();
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY;
- }
-
- @Override
- public void updateState(Preference preference) {
- final int currSetting = mBackend.getPriorityConversationSenders();
-
- for (SelectorWithWidgetPreference pref : mSelectorWithWidgetPreferences) {
- pref.setChecked(keyToSetting(pref.getKey()) == currSetting);
- pref.setSummary(getSummary(pref.getKey()));
- }
- }
-
- private static int keyToSetting(String key) {
- switch (key) {
- case KEY_ALL:
- return NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
- case KEY_IMPORTANT:
- return NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
- default:
- return NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
- }
- }
-
- private String getSummary(String key) {
- int numConversations;
- if (KEY_ALL.equals(key)) {
- numConversations = mNumConversations;
- } else if (KEY_IMPORTANT.equals(key)) {
- numConversations = mNumImportantConversations;
- } else {
- return null;
- }
-
- if (numConversations == UNSET) {
- return null;
- } else {
- MessageFormat msgFormat = new MessageFormat(
- mContext.getString(R.string.zen_mode_conversations_count),
- Locale.getDefault());
- Map args = new HashMap<>();
- args.put("count", numConversations);
- return msgFormat.format(args);
- }
- }
-
- private void updateChannelCounts() {
- // Load conversations
- new AsyncTask() {
- @Override
- protected Void doInBackground(Void... unused) {
- ParceledListSlice allConversations =
- mNotificationBackend.getConversations(false);
- int numConversations = 0;
- if (allConversations != null) {
- for (ConversationChannelWrapper conversation : allConversations.getList()) {
- if (!conversation.getNotificationChannel().isDemoted()) {
- numConversations++;
- }
- }
- }
- mNumConversations = numConversations;
-
- ParceledListSlice impConversations =
- mNotificationBackend.getConversations(true);
- int numImportantConversations = 0;
- if (impConversations != null) {
- for (ConversationChannelWrapper conversation : impConversations.getList()) {
- if (!conversation.getNotificationChannel().isDemoted()) {
- numImportantConversations++;
- }
- }
- }
- mNumImportantConversations = numImportantConversations;
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- if (mContext == null) {
- return;
- }
- updateState(mPreferenceCategory);
- }
- }.execute();
- }
-
- private SelectorWithWidgetPreference makeRadioPreference(String key, int titleId) {
- final SelectorWithWidgetPreference pref =
- new SelectorWithWidgetPreference(mPreferenceCategory.getContext());
- if (KEY_ALL.equals(key) || KEY_IMPORTANT.equals(key)) {
- pref.setExtraWidgetOnClickListener(mConversationSettingsWidgetClickListener);
- }
- pref.setKey(key);
- pref.setTitle(titleId);
- pref.setOnClickListener(mRadioButtonClickListener);
- mPreferenceCategory.addPreference(pref);
- mSelectorWithWidgetPreferences.add(pref);
- return pref;
- }
-
- private View.OnClickListener mConversationSettingsWidgetClickListener =
- new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SubSettingLauncher(mPreferenceScreenContext)
- .setDestination(ConversationListSettings.class.getName())
- .setSourceMetricsCategory(SettingsEnums.DND_CONVERSATIONS)
- .launch();
- }
- };
-
- private SelectorWithWidgetPreference.OnClickListener mRadioButtonClickListener =
- new SelectorWithWidgetPreference.OnClickListener() {
- @Override
- public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
- int selectedConversationSetting = keyToSetting(preference.getKey());
- if (selectedConversationSetting != mBackend.getPriorityConversationSenders()) {
- mBackend.saveConversationSenders(selectedConversationSetting);
- }
- }
- };
-}
diff --git a/tests/robotests/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceControllerTest.java
deleted file mode 100644
index d5834f932c3..00000000000
--- a/tests/robotests/src/com/android/settings/notification/zen/ZenModePriorityConversationsPreferenceControllerTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification.zen;
-
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
-import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
-
-import static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_ALL;
-import static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_IMPORTANT;
-import static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_NONE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.NotificationManager;
-import android.content.ContentResolver;
-import android.content.Context;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.notification.NotificationBackend;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.widget.SelectorWithWidgetPreference;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-public class ZenModePriorityConversationsPreferenceControllerTest {
-
- private ZenModePriorityConversationsPreferenceController mController;
-
- @Mock
- private ZenModeBackend mZenBackend;
- @Mock
- private PreferenceCategory mMockPrefCategory;
- @Mock
- private NotificationManager.Policy mPolicy;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- @Mock
- private NotificationBackend mNotifBackend;
-
- private List mSelectorWithWidgetPreferences;
- private ContentResolver mContentResolver;
- private Context mContext;
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mController = new ZenModePriorityConversationsPreferenceController(
- mContext, "test_key", mock(Lifecycle.class), mNotifBackend);
- ReflectionHelpers.setField(mController, "mBackend", mZenBackend);
-
- when(mMockPrefCategory.getContext()).thenReturn(mContext);
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
- .thenReturn(mMockPrefCategory);
- captureRadioButtons();
- }
-
- @Test
- public void displayPreference_radioButtonsCreatedOnlyOnce() {
- when(mMockPrefCategory.findPreference(any())).thenReturn(mock(Preference.class));
-
- // radio buttons were already created, so don't re-create them
- mController.displayPreference(mPreferenceScreen);
- verify(mMockPrefCategory, never()).addPreference(any());
- }
-
- @Test
- public void clickAllConversations() {
- SelectorWithWidgetPreference allConversationsRb = getButton(KEY_ALL);
- allConversationsRb.onClick();
-
- verify(mZenBackend).saveConversationSenders(CONVERSATION_SENDERS_ANYONE);
- }
-
- @Test
- public void clickImportantConversations() {
- SelectorWithWidgetPreference importantConversationsRb = getButton(KEY_IMPORTANT);
- importantConversationsRb.onClick();
-
- verify(mZenBackend).saveConversationSenders(CONVERSATION_SENDERS_IMPORTANT);
- }
-
- @Test
- public void clickNoConversations() {
- SelectorWithWidgetPreference noConversationsRb = getButton(KEY_NONE);
- noConversationsRb.onClick();
-
- verify(mZenBackend)
- .saveConversationSenders(CONVERSATION_SENDERS_NONE);
- }
-
- private void captureRadioButtons() {
- ArgumentCaptor rbCaptor =
- ArgumentCaptor.forClass(SelectorWithWidgetPreference.class);
- mController.displayPreference(mPreferenceScreen);
-
- // verifies 3 buttons were added
- verify(mMockPrefCategory, times(3)).addPreference(rbCaptor.capture());
- mSelectorWithWidgetPreferences = rbCaptor.getAllValues();
- assertThat(mSelectorWithWidgetPreferences.size()).isEqualTo(3);
-
- reset(mMockPrefCategory);
- }
-
- private SelectorWithWidgetPreference getButton(String key) {
- for (SelectorWithWidgetPreference pref : mSelectorWithWidgetPreferences) {
- if (key.equals(pref.getKey())) {
- return pref;
- }
- }
- return null;
- }
-}