Remove getGroupWritableAccounts method
This method would block on accounts loading. Replaced with asynchronous
loading of the group writable accounts.
Test: manually verify that labels are still shown in nav drawer
Bug 33627801
Change-Id: If1b344d5bfee59dd5b8cc5446b02742ceec1f459
diff --git a/src/com/android/contacts/ContactsDrawerActivity.java b/src/com/android/contacts/ContactsDrawerActivity.java
index fc7639a..ad4c2ac 100644
--- a/src/com/android/contacts/ContactsDrawerActivity.java
+++ b/src/com/android/contacts/ContactsDrawerActivity.java
@@ -67,6 +67,7 @@
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.account.AccountDisplayInfo;
import com.android.contacts.model.account.AccountDisplayInfoFactory;
+import com.android.contacts.model.account.AccountInfo;
import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.preference.ContactsPreferenceActivity;
import com.android.contacts.util.AccountFilterUtil;
@@ -76,6 +77,7 @@
import com.android.contacts.util.ViewUtil;
import com.android.contactsbind.HelpUtils;
import com.android.contactsbind.ObjectFactory;
+import com.google.common.util.concurrent.Futures;
import java.util.HashMap;
import java.util.Iterator;
@@ -401,7 +403,8 @@
}
@Override
- public void onGroupsLoaded(List<GroupListItem> groupListItems) {
+ public void onGroupsLoaded(List<GroupListItem> groupListItems,
+ boolean areGroupWritableAccountsAvailable) {
final Menu menu = mNavigationView.getMenu();
final MenuItem groupsMenuItem = menu.findItem(R.id.nav_groups);
final SubMenu subMenu = groupsMenuItem.getSubMenu();
@@ -442,7 +445,7 @@
}
// Don't show "Create new..." menu if there's no group-writable accounts available.
- if (!ContactsUtils.areGroupWritableAccountsAvailable(this)) {
+ if (!areGroupWritableAccountsAvailable) {
return;
}
@@ -678,8 +681,10 @@
}
private void selectAccountForNewGroup() {
- final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(this)
- .getGroupWritableAccounts();
+ // This should never block because the GroupsFragment loads the accounts and the
+ // "Create Label" item only exists when that loading finishes
+ final List<AccountInfo> accounts = Futures.getUnchecked(AccountTypeManager.getInstance(this)
+ .filterAccountsAsync(AccountTypeManager.AccountFilter.GROUPS_WRITABLE));
if (accounts.isEmpty()) {
// We shouldn't present the add group button if there are no writable accounts
// but check it since it's possible we are started with an Intent.
@@ -688,7 +693,7 @@
}
// If there is a single writable account, use it w/o showing a dialog.
if (accounts.size() == 1) {
- onAccountChosen(accounts.get(0), /* extraArgs */ null);
+ onAccountChosen(accounts.get(0).getAccount(), /* extraArgs */ null);
return;
}
SelectAccountDialogFragment.show(getFragmentManager(), R.string.dialog_new_group_account,