1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification.zen;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 
22 import androidx.preference.Preference;
23 import androidx.preference.PreferenceScreen;
24 
25 import com.android.settings.R;
26 import com.android.settings.notification.NotificationBackend;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.widget.FooterPreference;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 public class ZenCustomRuleMessagesSettings extends ZenCustomRuleSettingsBase {
34     private static final String MESSAGES_KEY = "zen_mode_messages";
35     private static final String PREFERENCE_CATEGORY_KEY = "zen_mode_settings_category_messages";
36 
37     @Override
getPreferenceScreenResId()38     protected int getPreferenceScreenResId() {
39         return com.android.settings.R.xml.zen_mode_custom_rule_messages_settings;
40     }
41 
42     @Override
getMetricsCategory()43     public int getMetricsCategory() {
44         return SettingsEnums.ZEN_CUSTOM_RULE_MESSAGES;
45     }
46 
47     @Override
createPreferenceControllers(Context context)48     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
49         mControllers = new ArrayList<>();
50         mControllers.add(new ZenRulePrioritySendersPreferenceController(context,
51                 PREFERENCE_CATEGORY_KEY, getSettingsLifecycle(), true,
52                 new NotificationBackend()));
53         return mControllers;
54     }
55 
56     @Override
getPreferenceCategoryKey()57     String getPreferenceCategoryKey() {
58         return PREFERENCE_CATEGORY_KEY;
59     }
60 
61     @Override
updatePreferences()62     public void updatePreferences() {
63         super.updatePreferences();
64         PreferenceScreen screen = getPreferenceScreen();
65         // TODO(b/200600958): It seems that this string does not currently update to indicate when
66         //   messages aren't in fact blocked by the rule.
67         Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER);
68         footerPreference.setTitle(mContext.getResources().getString(
69                 R.string.zen_mode_custom_messages_footer, mRule.getName()));
70     }
71 }
72