Fixing list adapter concurrency in Contacts Display Options
Bug: 2353600
Change-Id: I7b109899375e17ecab61a1ccc1c08e674ef0d376
diff --git a/src/com/android/contacts/ui/ContactsPreferencesActivity.java b/src/com/android/contacts/ui/ContactsPreferencesActivity.java
index aad7b12..23f55c7 100644
--- a/src/com/android/contacts/ui/ContactsPreferencesActivity.java
+++ b/src/com/android/contacts/ui/ContactsPreferencesActivity.java
@@ -118,6 +118,7 @@
mList.setHeaderDividersEnabled(true);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mContactsPrefs = new ContactsPreferences(this);
+ mAdapter = new DisplayAdapter(this);
final LayoutInflater inflater = getLayoutInflater();
@@ -205,6 +206,8 @@
mList.addHeaderView(mHeaderSeparator, null, false);
+ setListAdapter(mAdapter);
+
bindView();
// Start background query to find account details
@@ -342,21 +345,10 @@
@Override
protected void onPostExecute(ContactsPreferencesActivity target, AccountSet result) {
- // Build adapter to show available groups
- final Context context = target;
- final DisplayAdapter adapter = new DisplayAdapter(context, result);
- target.setListAdapter(adapter);
+ target.mAdapter.setAccounts(result);
}
}
- public void setListAdapter(DisplayAdapter adapter) {
- mAdapter = adapter;
- if (mAdapter != null) {
- mAdapter.setChildDescripWithPhones(mDisplayPhones.isChecked());
- }
- super.setListAdapter(mAdapter);
- }
-
private static final int DEFAULT_SHOULD_SYNC = 1;
private static final int DEFAULT_VISIBLE = 0;
@@ -658,17 +650,19 @@
private Context mContext;
private LayoutInflater mInflater;
private Sources mSources;
-
private AccountSet mAccounts;
private boolean mChildWithPhones = false;
- public DisplayAdapter(Context context, AccountSet accounts) {
+ public DisplayAdapter(Context context) {
mContext = context;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mSources = Sources.getInstance(context);
+ }
+ public void setAccounts(AccountSet accounts) {
mAccounts = accounts;
+ notifyDataSetChanged();
}
/**
@@ -780,6 +774,9 @@
/** {@inheritDoc} */
public int getGroupCount() {
+ if (mAccounts == null) {
+ return 0;
+ }
return mAccounts.size();
}