• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.people.IPeopleManager;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.ServiceManager;
24 import android.service.notification.ConversationChannelWrapper;
25 
26 import com.android.settings.R;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.notification.NotificationBackend;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 public class ConversationListSettings extends DashboardFragment {
35     private static final String TAG = "ConvoListSettings";
36 
37     NotificationBackend mBackend = new NotificationBackend();
38     IPeopleManager mPs;
39 
40     protected List<AbstractPreferenceController> mControllers = new ArrayList<>();
41     private NoConversationsPreferenceController mNoConversationsController;
42     private PriorityConversationsPreferenceController mPriorityConversationsController;
43     private AllConversationsPreferenceController mAllConversationsController;
44     private RecentConversationsPreferenceController mRecentConversationsController;
45     private boolean mUpdatedInOnCreate = false;
46 
ConversationListSettings()47     public ConversationListSettings() {
48         mPs = IPeopleManager.Stub.asInterface(
49                 ServiceManager.getService(Context.PEOPLE_SERVICE));
50     }
51 
52     @Override
getMetricsCategory()53     public int getMetricsCategory() {
54         return SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS;
55     }
56 
57     @Override
getLogTag()58     protected String getLogTag() {
59         return TAG;
60     }
61 
62     @Override
getPreferenceScreenResId()63     protected int getPreferenceScreenResId() {
64         return R.xml.conversation_list_settings;
65     }
66 
67     @Override
createPreferenceControllers(Context context)68     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
69         mControllers = new ArrayList<>();
70         mNoConversationsController = new NoConversationsPreferenceController(context);
71         mControllers.add(mNoConversationsController);
72         mPriorityConversationsController =
73                 new PriorityConversationsPreferenceController(context, mBackend);
74         mControllers.add(mPriorityConversationsController);
75         mAllConversationsController = new AllConversationsPreferenceController(context, mBackend);
76         mControllers.add(mAllConversationsController);
77         mRecentConversationsController =
78                 new RecentConversationsPreferenceController(context, mBackend, mPs);
79         mControllers.add(mRecentConversationsController);
80         return new ArrayList<>(mControllers);
81     }
82 
83     @Override
onCreate(Bundle icicle)84     public void onCreate(Bundle icicle) {
85         super.onCreate(icicle);
86         update();
87         mUpdatedInOnCreate = true;
88     }
89 
90     @Override
onStart()91     public void onStart() {
92         super.onStart();
93         if (mUpdatedInOnCreate) {
94             mUpdatedInOnCreate = false;
95         } else {
96             update();
97         }
98     }
99 
update()100     private void update() {
101         List<ConversationChannelWrapper> conversationList =
102                 mBackend.getConversations(false).getList();
103         boolean hasContent = mPriorityConversationsController.updateList(conversationList)
104                 | mAllConversationsController.updateList(conversationList)
105                 | mRecentConversationsController.updateList();
106         mNoConversationsController.setAvailable(!hasContent);
107         mNoConversationsController.displayPreference(getPreferenceScreen());
108     }
109 }
110