Merge "Fix Conversation page flickers" into tm-dev am: 7dc1aec524 am: 6c2ffc2220 am: 447f77c07d am: a64429b8e8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18475672

Change-Id: I032de9c1b368c7a7c4743fd4695511f063bc0598
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chaohui Wang
2022-05-25 15:41:25 +00:00
committed by Automerger Merge Worker
9 changed files with 220 additions and 291 deletions

View File

@@ -17,26 +17,18 @@
package com.android.settings.notification.app;
import android.content.Context;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import java.util.Collections;
import java.util.List;
public class AllConversationsPreferenceController extends ConversationListPreferenceController {
private static final String KEY = "other_conversations";
private List<ConversationChannelWrapper> mConversations;
public AllConversationsPreferenceController(Context context,
NotificationBackend backend) {
public AllConversationsPreferenceController(Context context, NotificationBackend backend) {
super(context, backend);
}
@@ -45,11 +37,6 @@ public class AllConversationsPreferenceController extends ConversationListPrefer
return KEY;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
Preference getSummaryPreference() {
Preference pref = new Preference(mContext);
@@ -63,15 +50,4 @@ public class AllConversationsPreferenceController extends ConversationListPrefer
boolean matchesFilter(ConversationChannelWrapper conversation) {
return !conversation.getNotificationChannel().isImportantConversation();
}
@Override
public void updateState(Preference preference) {
PreferenceCategory pref = (PreferenceCategory) preference;
// Load conversations
mConversations = mBackend.getConversations(false).getList();
Collections.sort(mConversations, mConversationComparator);
populateList(mConversations, pref);
}
}

View File

@@ -25,8 +25,10 @@ import android.provider.Settings;
import android.service.notification.ConversationChannelWrapper;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.AppInfoBase;
@@ -38,14 +40,15 @@ import com.android.settingslib.widget.AppPreference;
import java.text.Collator;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class ConversationListPreferenceController extends AbstractPreferenceController {
private static final String SUMMARY_KEY_SUFFIX = "_summary";
protected final NotificationBackend mBackend;
private PreferenceGroup mPreferenceGroup;
public ConversationListPreferenceController(Context context,
NotificationBackend backend) {
public ConversationListPreferenceController(Context context, NotificationBackend backend) {
super(context);
mBackend = backend;
}
@@ -55,44 +58,55 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
return true;
}
protected void populateList(List<ConversationChannelWrapper> conversations,
PreferenceGroup containerGroup) {
containerGroup.setVisible(false);
containerGroup.removeAll();
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreferenceGroup = screen.findPreference(getPreferenceKey());
}
/**
* Updates the conversation list.
* @return true if this controller has content to display.
*/
boolean updateList(List<ConversationChannelWrapper> conversations) {
mPreferenceGroup.setVisible(false);
mPreferenceGroup.removeAll();
if (conversations != null) {
populateConversations(conversations, containerGroup);
populateConversations(conversations);
}
if (containerGroup.getPreferenceCount() != 0) {
boolean hasContent = mPreferenceGroup.getPreferenceCount() != 0;
if (hasContent) {
Preference summaryPref = getSummaryPreference();
if (summaryPref != null) {
summaryPref.setKey(getPreferenceKey() + SUMMARY_KEY_SUFFIX);
containerGroup.addPreference(summaryPref);
mPreferenceGroup.addPreference(summaryPref);
}
containerGroup.setVisible(true);
mPreferenceGroup.setVisible(true);
}
return hasContent;
}
abstract Preference getSummaryPreference();
abstract boolean matchesFilter(ConversationChannelWrapper conversation);
protected void populateConversations(List<ConversationChannelWrapper> conversations,
PreferenceGroup containerGroup) {
int order = 100;
for (ConversationChannelWrapper conversation : conversations) {
if (conversation.getNotificationChannel().isDemoted()
|| !matchesFilter(conversation)) {
continue;
}
containerGroup.addPreference(createConversationPref(conversation, order++));
}
@VisibleForTesting
void populateConversations(List<ConversationChannelWrapper> conversations) {
AtomicInteger order = new AtomicInteger(100);
conversations.stream()
.filter(conversation -> !conversation.getNotificationChannel().isDemoted()
&& matchesFilter(conversation))
.sorted(mConversationComparator)
.map(this::createConversationPref)
.forEachOrdered(preference -> {
preference.setOrder(order.getAndIncrement());
mPreferenceGroup.addPreference(preference);
});
}
protected Preference createConversationPref(final ConversationChannelWrapper conversation,
int order) {
private Preference createConversationPref(final ConversationChannelWrapper conversation) {
AppPreference pref = new AppPreference(mContext);
pref.setOrder(order);
pref.setTitle(getTitle(conversation));
pref.setSummary(getSummary(conversation));
@@ -141,7 +155,8 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS);
}
protected Comparator<ConversationChannelWrapper> mConversationComparator =
@VisibleForTesting
Comparator<ConversationChannelWrapper> mConversationComparator =
new Comparator<ConversationChannelWrapper>() {
private final Collator sCollator = Collator.getInstance();
@Override

View File

@@ -19,8 +19,9 @@ package com.android.settings.notification.app;
import android.app.people.IPeopleManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.os.ServiceManager;
import android.util.Log;
import android.service.notification.ConversationChannelWrapper;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -32,12 +33,16 @@ import java.util.List;
public class ConversationListSettings extends DashboardFragment {
private static final String TAG = "ConvoListSettings";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
NotificationBackend mBackend = new NotificationBackend();
IPeopleManager mPs;
protected List<AbstractPreferenceController> mControllers = new ArrayList<>();
private NoConversationsPreferenceController mNoConversationsController;
private PriorityConversationsPreferenceController mPriorityConversationsController;
private AllConversationsPreferenceController mAllConversationsController;
private RecentConversationsPreferenceController mRecentConversationsController;
private boolean mUpdatedInOnCreate = false;
public ConversationListSettings() {
mPs = IPeopleManager.Stub.asInterface(
@@ -62,10 +67,43 @@ public class ConversationListSettings extends DashboardFragment {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new NoConversationsPreferenceController(context, mBackend, mPs));
mControllers.add(new PriorityConversationsPreferenceController(context, mBackend));
mControllers.add(new AllConversationsPreferenceController(context, mBackend));
mControllers.add(new RecentConversationsPreferenceController(context, mBackend, mPs));
mNoConversationsController = new NoConversationsPreferenceController(context);
mControllers.add(mNoConversationsController);
mPriorityConversationsController =
new PriorityConversationsPreferenceController(context, mBackend);
mControllers.add(mPriorityConversationsController);
mAllConversationsController = new AllConversationsPreferenceController(context, mBackend);
mControllers.add(mAllConversationsController);
mRecentConversationsController =
new RecentConversationsPreferenceController(context, mBackend, mPs);
mControllers.add(mRecentConversationsController);
return new ArrayList<>(mControllers);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
update();
mUpdatedInOnCreate = true;
}
@Override
public void onStart() {
super.onStart();
if (mUpdatedInOnCreate) {
mUpdatedInOnCreate = false;
} else {
update();
}
}
private void update() {
List<ConversationChannelWrapper> conversationList =
mBackend.getConversations(false).getList();
boolean hasContent = mPriorityConversationsController.updateList(conversationList)
| mAllConversationsController.updateList(conversationList)
| mRecentConversationsController.updateList();
mNoConversationsController.setAvailable(!hasContent);
mNoConversationsController.displayPreference(getPreferenceScreen());
}
}

View File

@@ -16,32 +16,18 @@
package com.android.settings.notification.app;
import android.app.people.IPeopleManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.service.notification.ConversationChannelWrapper;
import android.util.Log;
import android.view.View;
import androidx.preference.Preference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.widget.LayoutPreference;
class NoConversationsPreferenceController extends AbstractPreferenceController {
public class NoConversationsPreferenceController extends ConversationListPreferenceController {
private static String TAG = "NoConversationsPC";
private static final String KEY = "no_conversations";
private IPeopleManager mPs;
private int mConversationCount = 0;
private boolean mIsAvailable = false;
public NoConversationsPreferenceController(Context context,
NotificationBackend backend, IPeopleManager ps) {
super(context, backend);
mPs = ps;
NoConversationsPreferenceController(Context context) {
super(context);
}
@Override
@@ -51,44 +37,10 @@ public class NoConversationsPreferenceController extends ConversationListPrefere
@Override
public boolean isAvailable() {
return true;
return mIsAvailable;
}
@Override
Preference getSummaryPreference() {
return null;
}
@Override
boolean matchesFilter(ConversationChannelWrapper conversation) {
return false;
}
@Override
public void updateState(Preference preference) {
LayoutPreference pref = (LayoutPreference) preference;
// Load conversations
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... unused) {
mConversationCount = mBackend.getConversations(false).getList().size();
try {
mConversationCount += mPs.getRecentConversations().getList().size();
} catch (RemoteException e) {
Log.w(TAG, "Error calling PS", e);
}
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (mContext == null) {
return;
}
pref.findViewById(R.id.onboarding).setVisibility(mConversationCount == 0
? View.VISIBLE : View.GONE);
preference.setVisible(mConversationCount == 0);
}
}.execute();
void setAvailable(boolean available) {
mIsAvailable = available;
}
}

View File

@@ -17,26 +17,19 @@
package com.android.settings.notification.app;
import android.content.Context;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import java.util.Collections;
import java.util.List;
public class PriorityConversationsPreferenceController extends
ConversationListPreferenceController {
private static final String KEY = "important_conversations";
private List<ConversationChannelWrapper> mConversations;
public PriorityConversationsPreferenceController(Context context,
NotificationBackend backend) {
public PriorityConversationsPreferenceController(Context context, NotificationBackend backend) {
super(context, backend);
}
@@ -45,11 +38,6 @@ public class PriorityConversationsPreferenceController extends
return KEY;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
Preference getSummaryPreference() {
Preference pref = new Preference(mContext);
@@ -63,14 +51,4 @@ public class PriorityConversationsPreferenceController extends
boolean matchesFilter(ConversationChannelWrapper conversation) {
return conversation.getNotificationChannel().isImportantConversation();
}
@Override
public void updateState(Preference preference) {
PreferenceCategory pref = (PreferenceCategory) preference;
// Load conversations
mConversations = mBackend.getConversations(true).getList();
Collections.sort(mConversations, mConversationComparator);
populateList(mConversations, pref);
}
}

View File

@@ -30,9 +30,10 @@ import android.provider.Settings;
import android.util.Slog;
import android.widget.Button;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.AppInfoBase;
@@ -45,18 +46,20 @@ import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public class RecentConversationsPreferenceController extends AbstractPreferenceController {
private static final String TAG = "RecentConversationsPC";
private static final String KEY = "recent_conversations";
private static final String CLEAR_ALL_KEY_SUFFIX = "_clear_all";
private List<ConversationChannel> mConversations;
private final IPeopleManager mPs;
private final NotificationBackend mBackend;
private PreferenceGroup mPreferenceGroup;
public RecentConversationsPreferenceController(Context context, NotificationBackend backend,
IPeopleManager ps) {
public RecentConversationsPreferenceController(
Context context, NotificationBackend backend, IPeopleManager ps) {
super(context);
mBackend = backend;
mPs = ps;
@@ -103,63 +106,69 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC
}
@Override
public void updateState(Preference preference) {
PreferenceCategory pref = (PreferenceCategory) preference;
// Load conversations
try {
mConversations = mPs.getRecentConversations().getList();
} catch (RemoteException e) {
Slog.w(TAG, "Could get recents", e);
}
Collections.sort(mConversations, mConversationComparator);
populateList(mConversations, pref);
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreferenceGroup = screen.findPreference(getPreferenceKey());
}
protected void populateList(List<ConversationChannel> conversations,
PreferenceGroup containerGroup) {
containerGroup.removeAll();
/**
* Updates the conversation list.
*
* @return true if this controller has content to display.
*/
boolean updateList() {
// Load conversations
List<ConversationChannel> conversations = Collections.emptyList();
try {
conversations = mPs.getRecentConversations().getList();
} catch (RemoteException e) {
Slog.w(TAG, "Could not get recent conversations", e);
}
return populateList(conversations);
}
@VisibleForTesting
boolean populateList(List<ConversationChannel> conversations) {
mPreferenceGroup.removeAll();
boolean hasClearable = false;
if (conversations != null) {
hasClearable = populateConversations(conversations, containerGroup);
hasClearable = populateConversations(conversations);
}
if (containerGroup.getPreferenceCount() == 0) {
containerGroup.setVisible(false);
} else {
containerGroup.setVisible(true);
if (hasClearable) {
Preference clearAll = getClearAll(containerGroup);
if (clearAll != null) {
containerGroup.addPreference(clearAll);
}
boolean hashContent = mPreferenceGroup.getPreferenceCount() != 0;
mPreferenceGroup.setVisible(hashContent);
if (hashContent && hasClearable) {
Preference clearAll = getClearAll(mPreferenceGroup);
if (clearAll != null) {
mPreferenceGroup.addPreference(clearAll);
}
}
return hashContent;
}
protected boolean populateConversations(List<ConversationChannel> conversations,
PreferenceGroup containerGroup) {
int order = 100;
boolean hasClearable = false;
for (ConversationChannel conversation : conversations) {
if (conversation.getNotificationChannel().getImportance() == IMPORTANCE_NONE
|| (conversation.getNotificationChannelGroup() != null
&& conversation.getNotificationChannelGroup().isBlocked())) {
continue;
}
RecentConversationPreference pref =
createConversationPref(containerGroup, conversation, order++);
containerGroup.addPreference(pref);
if (pref.hasClearListener()) {
hasClearable = true;
}
}
return hasClearable;
protected boolean populateConversations(List<ConversationChannel> conversations) {
AtomicInteger order = new AtomicInteger(100);
AtomicBoolean hasClearable = new AtomicBoolean(false);
conversations.stream()
.filter(conversation ->
conversation.getNotificationChannel().getImportance() != IMPORTANCE_NONE
&& (conversation.getNotificationChannelGroup() == null
|| !conversation.getNotificationChannelGroup().isBlocked()))
.sorted(mConversationComparator)
.map(this::createConversationPref)
.forEachOrdered(pref -> {
pref.setOrder(order.getAndIncrement());
mPreferenceGroup.addPreference(pref);
if (pref.hasClearListener()) {
hasClearable.set(true);
}
});
return hasClearable.get();
}
protected RecentConversationPreference createConversationPref(PreferenceGroup parent,
final ConversationChannel conversation, int order) {
protected RecentConversationPreference createConversationPref(
final ConversationChannel conversation) {
final String pkg = conversation.getShortcutInfo().getPackage();
final int uid = conversation.getUid();
final String conversationId = conversation.getShortcutInfo().getId();
@@ -171,13 +180,12 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC
mPs.removeRecentConversation(pkg, UserHandle.getUserId(uid), conversationId);
pref.getClearView().announceForAccessibility(
mContext.getString(R.string.recent_convo_removed));
parent.removePreference(pref);
mPreferenceGroup.removePreference(pref);
} catch (RemoteException e) {
Slog.w(TAG, "Could not clear recent", e);
}
});
}
pref.setOrder(order);
pref.setTitle(getTitle(conversation));
pref.setSummary(getSummary(conversation));
@@ -230,9 +238,11 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS);
}
protected Comparator<ConversationChannel> mConversationComparator =
@VisibleForTesting
Comparator<ConversationChannel> mConversationComparator =
new Comparator<ConversationChannel>() {
private final Collator sCollator = Collator.getInstance();
@Override
public int compare(ConversationChannel o1, ConversationChannel o2) {
int labelComparison = 0;