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

Commit 841903d8 authored by Toha's avatar Toha Committed by Michael Bestas
Browse files

Contacts: Enable support for device contact.



Change-Id: I8f2e907deadced5316be5a418dab2538476a4033
Signed-off-by: default avatarToha <tohenk@yahoo.com>

Contacts: Ignore device null account.

As of commit 2cb5e075 which adds device contact,
the behavior is correct if there is a google account already setup, otherwise
there are two device contacts shown. So, always ignore null account.

Change-Id: I9f18a45efcaa93b8583013beb5995bf85ae58dcd
Signed-off-by: default avatarToha <tohenk@yahoo.com>
parent 6e08aca6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -272,7 +272,8 @@ public class DrawerAdapter extends BaseAdapter {
        }
        final ContactListFilter account = item.account;
        final TextView textView = ((TextView) result.findViewById(R.id.title));
        textView.setText(account.accountName);
        textView.setText(mActivity.getPackageName().equals(account.accountType) ?
                mActivity.getString(R.string.account_phone) : account.accountName);
        final boolean activated = account.equals(mSelectedAccount)
                && mSelectedView == ContactsView.ACCOUNT_VIEW;
        textView.setTextAppearance(mActivity, activated
+14 −5
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public abstract class AccountTypeManager {

    public static final String BROADCAST_ACCOUNTS_CHANGED = AccountTypeManager.class.getName() +
            ".AccountsChanged";
    public static final String DEVICE_ACCOUNT_NAME = "DEVICE";

    public enum AccountFilter implements Predicate<AccountInfo> {
        ALL {
@@ -590,15 +591,23 @@ class AccountTypeManagerImpl extends AccountTypeManager
    private List<AccountWithDataSet> getAccountsWithDataSets(Account[] accounts,
            AccountTypeProvider typeProvider) {
        List<AccountWithDataSet> result = new ArrayList<>();
        // add local device account
        populateAccountsDataSet(typeProvider, new Account(DEVICE_ACCOUNT_NAME,
                mContext.getPackageName()), result);
        for (Account account : accounts) {
            populateAccountsDataSet(typeProvider, account, result);
        }
        return result;
    }

    private void populateAccountsDataSet(AccountTypeProvider typeProvider, Account account,
            List<AccountWithDataSet> result) {
        final List<AccountType> types = typeProvider.getAccountTypes(account.type);
        for (AccountType type : types) {
            result.add(new AccountWithDataSet(
                    account.name, account.type, type.dataSet));
        }
    }
        return result;
    }

    /**
     * Returns the default google account specified in preferences, the first google account
+2 −18
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.Context;

import com.android.contacts.Experiments;
import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.model.account.GoogleAccountType;
import com.android.contactsbind.ObjectFactory;
import com.android.contactsbind.experiments.Flags;

@@ -69,7 +68,7 @@ public abstract class DeviceLocalAccountLocator {
            return new Cp2DeviceLocalAccountLocator(context.getContentResolver(),
                    ObjectFactory.getDeviceLocalAccountTypeFactory(context), knownTypes);
        } else {
            return new NexusDeviceAccountLocator(accountManager);
            return new NexusDeviceAccountLocator();
        }
    }

@@ -82,24 +81,9 @@ public abstract class DeviceLocalAccountLocator {
     * </p>
     */
    public static class NexusDeviceAccountLocator extends DeviceLocalAccountLocator {

        private final AccountManager mAccountManager;

        public NexusDeviceAccountLocator(AccountManager accountManager) {
            mAccountManager = accountManager;
        }

        @Override
        public List<AccountWithDataSet> getDeviceLocalAccounts() {
            @SuppressWarnings("MissingPermission")
            final Account[] accounts = mAccountManager
                    .getAccountsByType(GoogleAccountType.ACCOUNT_TYPE);

            if (accounts.length > 0) {
            return Collections.emptyList();
            } else {
                return Collections.singletonList(AccountWithDataSet.getNullAccount());
            }
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ public class AccountTypeProvider {
     * </p>
     */
    public List<AccountType> getAccountTypes(String accountType) {
        if (mContext.getPackageName().equals(accountType)) {
            accountType = null;
        }
        // ConcurrentHashMap doesn't support null keys
        if (accountType == null) {
            AccountType type = mLocalAccountTypeFactory.getAccountType(accountType);
+2 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ public class AccountSelectionUtil {

                text1.setText(accountType.getDisplayLabel(context));
                text2.setText(account.name);
                text2.setVisibility(context.getPackageName().equals(account.type) ?
                        View.GONE : View.VISIBLE);
                icon.setImageDrawable(accountType.getDisplayIcon(getContext()));

                return convertView;
Loading