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

Unverified Commit 89b8fdf1 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 ec766988
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -357,7 +357,8 @@ public class DrawerAdapter extends BaseAdapter {
        final AccountDisplayInfo displayableAccount =
                mAccountDisplayFactory.getAccountDisplayInfoFor(item.account);
        final TextView textView = ((TextView) result.findViewById(R.id.title));
        textView.setText(displayableAccount.getNameLabel());
        textView.setText(mActivity.getPackageName().equals(account.accountType) ?
                mActivity.getString(R.string.account_phone) : displayableAccount.getNameLabel());
        final boolean activated = account.equals(mSelectedAccount)
                && mSelectedView == ContactsView.ACCOUNT_VIEW;
        textView.setTextAppearance(mActivity, activated
+15 −6
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 {
@@ -398,7 +399,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
     */
    public AccountTypeManagerImpl(Context context) {
        mContext = context;
        mLocalAccountLocator = new DeviceLocalAccountLocator(context, AccountManager.get(context));
        mLocalAccountLocator = new DeviceLocalAccountLocator(context);
        mTypeProvider = new AccountTypeProvider(context);
        mFallbackAccountType = new FallbackAccountType(context);

@@ -629,15 +630,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 −8
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.Context;
import android.provider.ContactsContract;

import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.model.account.GoogleAccountType;

import java.util.Collections;
import java.util.List;
@@ -32,12 +31,10 @@ import java.util.List;
public final class DeviceLocalAccountLocator {

    private final Context mContext;
    private final AccountManager mAccountManager;
    private final List<AccountWithDataSet> mLocalAccount;

    public DeviceLocalAccountLocator(Context context, AccountManager accountManager) {
    public DeviceLocalAccountLocator(Context context) {
        mContext = context;
        mAccountManager = accountManager;
        mLocalAccount = Collections.singletonList(AccountWithDataSet.getLocalAccount(context));
    }

@@ -45,10 +42,7 @@ public final class DeviceLocalAccountLocator {
     * Returns a list of device local accounts
     */
    public List<AccountWithDataSet> getDeviceLocalAccounts() {
        @SuppressWarnings("MissingPermission") final Account[] accounts = mAccountManager
                .getAccountsByType(GoogleAccountType.ACCOUNT_TYPE);

        if (accounts.length > 0 && !mLocalAccount.get(0).hasData(mContext)) {
        if (!mLocalAccount.get(0).hasData(mContext)) {
            return Collections.emptyList();
        } else {
            return mLocalAccount;
+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 || mLocalAccountTypeFactory.classifyAccount(accountType)
                == DeviceLocalAccountTypeFactory.TYPE_SIM) {
+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