1 /*
2  * Copyright (C) 2020 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.Activity;
20 import android.app.Application;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 
24 import androidx.fragment.app.Fragment;
25 import androidx.fragment.app.FragmentManager;
26 
27 import com.android.settings.R;
28 import com.android.settings.notification.NotificationBackend;
29 import com.android.settings.search.BaseSearchIndexProvider;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 import com.android.settingslib.core.lifecycle.Lifecycle;
32 import com.android.settingslib.search.Indexable;
33 import com.android.settingslib.search.SearchIndexable;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 @SearchIndexable
39 public class ZenModePeopleSettings extends ZenModeSettingsBase implements Indexable {
40 
41     @Override
createPreferenceControllers(Context context)42     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
43         final Activity activity = getActivity();
44         final Application app;
45         if (activity != null) {
46             app = activity.getApplication();
47         } else {
48             app = null;
49         }
50         return buildPreferenceControllers(
51                 context, getSettingsLifecycle(), app, this, getFragmentManager(),
52                 new NotificationBackend());
53     }
54 
buildPreferenceControllers(Context context, Lifecycle lifecycle, Application app, Fragment host, FragmentManager fragmentManager, NotificationBackend notificationBackend)55     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
56             Lifecycle lifecycle, Application app, Fragment host, FragmentManager fragmentManager,
57             NotificationBackend notificationBackend) {
58         List<AbstractPreferenceController> controllers = new ArrayList<>();
59         controllers.add(new ZenModeConversationsImagePreferenceController(context,
60                 "zen_mode_conversations_image", lifecycle, notificationBackend));
61         controllers.add(new ZenModeConversationsPreferenceController(context,
62                 "zen_mode_conversations", lifecycle));
63         controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
64                 "zen_mode_people_calls"));
65         controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
66                 "zen_mode_people_messages"));
67         controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle,
68                 fragmentManager));
69         return controllers;
70     }
71 
72     @Override
getPreferenceScreenResId()73     protected int getPreferenceScreenResId() {
74         return R.xml.zen_mode_people_settings;
75     }
76 
77     @Override
getMetricsCategory()78     public int getMetricsCategory() {
79         return SettingsEnums.DND_PEOPLE;
80     }
81 
82     /**
83      * For Search.
84      */
85     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
86             new BaseSearchIndexProvider(R.xml.zen_mode_people_settings) {
87 
88                 @Override
89                 public List<AbstractPreferenceController> createPreferenceControllers(
90                         Context context) {
91                     return buildPreferenceControllers(context, null, null, null,
92                             null, null);
93                 }
94             };
95 }
96