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.app;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.preference.PreferenceManager;
23 import android.text.TextUtils;
24 import android.util.Log;
25 
26 import com.android.internal.widget.LockPatternUtils;
27 import com.android.settings.R;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 public class ConversationNotificationSettings extends NotificationSettings {
34     private static final String TAG = "ConvoSettings";
35 
36     @Override
getMetricsCategory()37     public int getMetricsCategory() {
38         return SettingsEnums.NOTIFICATION_CONVERSATION_SETTINGS;
39     }
40 
41     @Override
onResume()42     public void onResume() {
43         super.onResume();
44         if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
45             Log.w(TAG, "Missing package or uid or packageinfo or channel");
46             finish();
47             return;
48         }
49         getActivity().setTitle(mConversationInfo == null
50                 ? mChannel.getName()
51                 : mConversationInfo.getLabel());
52 
53         for (NotificationPreferenceController controller : mControllers) {
54             controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,
55                     mConversationInfo, mSuspendedAppsAdmin, mPreferenceFilter);
56             controller.displayPreference(getPreferenceScreen());
57         }
58         updatePreferenceStates();
59         animatePanel();
60     }
61 
62     @Override
onActivityResult(int requestCode, int resultCode, Intent data)63     public void onActivityResult(int requestCode, int resultCode, Intent data) {
64         for (NotificationPreferenceController controller : mControllers) {
65             if (controller instanceof PreferenceManager.OnActivityResultListener) {
66                 ((PreferenceManager.OnActivityResultListener) controller)
67                         .onActivityResult(requestCode, resultCode, data);
68             }
69         }
70     }
71 
72     @Override
getLogTag()73     protected String getLogTag() {
74         return TAG;
75     }
76 
77     @Override
getPreferenceScreenResId()78     protected int getPreferenceScreenResId() {
79         return R.xml.conversation_notification_settings;
80     }
81 
82     @Override
createPreferenceControllers(Context context)83     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
84         mControllers = new ArrayList<>();
85         mControllers.add(new ConversationHeaderPreferenceController(context, this));
86         mControllers.add(new BlockPreferenceController(context, mDependentFieldListener, mBackend));
87         mControllers.add(new ConversationPriorityPreferenceController(
88                 context, mBackend, mDependentFieldListener));
89         mControllers.add(new HighImportancePreferenceController(
90                 context, mDependentFieldListener, mBackend));
91         mControllers.add(new SoundPreferenceController(context, this,
92                 mDependentFieldListener, mBackend));
93         mControllers.add(new VibrationPreferenceController(context, mBackend));
94         mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
95                 mBackend));
96         mControllers.add(new LightsPreferenceController(context, mBackend));
97         mControllers.add(new BadgePreferenceController(context, mBackend));
98         mControllers.add(new NotificationsOffPreferenceController(context));
99         mControllers.add(new BubblePreferenceController(context, getChildFragmentManager(),
100                 mBackend, false /* isAppPage */, null /* dependentFieldListener */));
101         mControllers.add(new ConversationDemotePreferenceController(context, this, mBackend));
102         mControllers.add(new ConversationPromotePreferenceController(context, this, mBackend));
103         mControllers.add(new BubbleCategoryPreferenceController(context));
104         mControllers.add(new BubbleLinkPreferenceController(context));
105         return new ArrayList<>(mControllers);
106     }
107 }
108