Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87e14288 authored by Marcus Hagerott's avatar Marcus Hagerott Committed by Android (Google) Code Review
Browse files

Merge "Don't show null account on customize contacts to display." into ub-contactsdialer-h-dev

parents 21988cc1 67a0639c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -143,7 +143,10 @@ public class CustomContactListFilterActivity extends Activity implements

            final AccountSet accounts = new AccountSet();

            final List<AccountWithDataSet> sourceAccounts = accountTypes.getAccounts(false);
            // Don't include the null account because it doesn't support writing to
            // ContactsContract.Settings
            final List<AccountWithDataSet> sourceAccounts = accountTypes.getAccounts(
                    AccountTypeManager.nonNullAccountFilter());
            final AccountDisplayInfoFactory displayableAccountFactory =
                    new AccountDisplayInfoFactory(context, sourceAccounts);
            for (AccountWithDataSet account : sourceAccounts) {
+24 −0
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ import com.android.contacts.common.util.DeviceLocalAccountTypeFactory;
import com.android.contactsbind.ObjectFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -76,6 +78,8 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.Nullable;

import static com.android.contacts.common.util.DeviceLocalAccountTypeFactory.Util.isLocalAccountType;

/**
@@ -127,6 +131,11 @@ public abstract class AccountTypeManager {
            return Collections.emptyList();
        }

        @Override
        public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
            return Collections.emptyList();
        }

        @Override
        public List<AccountWithDataSet> getGroupWritableAccounts() {
            return Collections.emptyList();
@@ -166,6 +175,8 @@ public abstract class AccountTypeManager {
    // TODO: Consider splitting this into getContactWritableAccounts() and getAllAccounts()
    public abstract List<AccountWithDataSet> getAccounts(boolean contactWritableOnly);

    public abstract List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter);

    public abstract List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet defaultAccount,
            boolean contactWritableOnly);

@@ -272,6 +283,14 @@ public abstract class AccountTypeManager {
        return canGetAccounts && canReadContacts;
    }

    public static Predicate<AccountWithDataSet> nonNullAccountFilter() {
        return new Predicate<AccountWithDataSet>() {
            @Override
            public boolean apply(@Nullable AccountWithDataSet account) {
                return account != null && account.name != null && account.type != null;
            }
        };
    }
}

class AccountComparator implements Comparator<AccountWithDataSet> {
@@ -755,6 +774,11 @@ class AccountTypeManagerImpl extends AccountTypeManager
        return Lists.newArrayList(contactWritableOnly ? mContactWritableAccounts : mAccounts);
    }

    @Override
    public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
        return new ArrayList<>(Collections2.filter(mAccounts, filter));
    }

    /**
     * Return list of all known or contact writable {@link AccountWithDataSet}'s sorted by
     * {@code defaultAccount}.
+7 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import com.android.contacts.common.model.account.AccountTypeWithDataSet;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.account.BaseAccountType;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

@@ -67,6 +69,11 @@ public class MockAccountTypeManager extends AccountTypeManager {
        return Arrays.asList(mAccounts);
    }

    @Override
    public List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter) {
        return Lists.newArrayList(Collections2.filter(Arrays.asList(mAccounts), filter));
    }

    @Override
    public List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet account,
            boolean writableOnly) {