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

Commit f7d733a0 authored by Walter Jang's avatar Walter Jang
Browse files

Manualy sync Contacts to match ContactsCommon (1/2)

Bug 30759296

Change-Id: I3f1d1960c7a44ebcd9b8e12db5f8da7989e367ab
parent 2c236d23
Loading
Loading
Loading
Loading
+21 −12
Original line number Diff line number Diff line
@@ -39,6 +39,13 @@
        android:id="@+id/contact_list">

        <include layout="@layout/contact_list_card"/>

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:enabled="false" >

            <view
                class="com.android.contacts.common.list.PinnedHeaderListView"
                android:id="@android:id/list"
@@ -53,6 +60,8 @@
                android:fastScrollEnabled="true"
		android:visibility="gone"
                android:fadingEdge="none" />
        </android.support.v4.widget.SwipeRefreshLayout>

        <ProgressBar
            android:id="@+id/search_progress"
            style="?android:attr/progressBarStyleLarge"
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,16 @@ package com.android.contacts.common;
 */
public final class Experiments {

    /**
     * Flag to control pullToRefresh feature.
     */
    public static final String PULL_TO_REFRESH = "pull_to_refresh";

    /**
     * Search study boolean indicating whether to inject yenta search results before CP2 results.
     */
    public static final String SEARCH_YENTA = "Search__yenta";

    private Experiments() {
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
    private boolean mEnabled = true;

    private T mAdapter;
    private View mView;
    protected View mView;
    private ListView mListView;

    /**
+61 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.contacts.common.list;

import android.accounts.Account;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -25,6 +26,11 @@ import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;

import com.android.contacts.common.logging.ListEvent;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.account.GoogleAccountType;

import java.util.ArrayList;
import java.util.List;

/**
 * Contact list filter parameters.
@@ -364,4 +370,59 @@ public final class ContactListFilter implements Comparable<ContactListFilter>, P
                return "(unknown)";
        }
    }

    /**
     * Returns true if this ContactListFilter contains at least one Google account.
     * (see {@link #isGoogleAccountType)
     */
    public boolean isSyncable(List<AccountWithDataSet> accounts) {
        // TODO(samchen): Check FILTER_TYPE_CUSTOM
        if (isGoogleAccountType() && filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) {
            return true;
        }
        if (filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS
                || filterType == ContactListFilter.FILTER_TYPE_DEFAULT) {
            if (accounts != null && accounts.size() > 0) {
                // If we're showing all contacts and there is any Google account on the device then
                // we're syncable.
                for (AccountWithDataSet account : accounts) {
                    if (GoogleAccountType.ACCOUNT_TYPE.equals(account.type)
                            && account.dataSet == null) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /**
     * Returns the Google accounts (see {@link #isGoogleAccountType) for this ContactListFilter.
     */
    public List<Account> getSyncableAccounts(List<AccountWithDataSet> accounts) {
        final List<Account> syncableAccounts = new ArrayList<>();
        // TODO(samchen): Check FILTER_TYPE_CUSTOM
        if (isGoogleAccountType() && filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) {
            syncableAccounts.add(new Account(accountName, accountType));
        } else if (filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS
                || filterType == ContactListFilter.FILTER_TYPE_DEFAULT) {
            if (accounts != null && accounts.size() > 0) {
                for (AccountWithDataSet account : accounts) {
                    if (GoogleAccountType.ACCOUNT_TYPE.equals(account.type)
                            && account.dataSet == null) {
                        syncableAccounts.add(new Account(account.name, account.type));
                    }
                }
            }
        }
        return syncableAccounts;
    }

    /**
     * Returns true if this ContactListFilter is Google account type. (i.e. where
     * accountType = "com.google" and dataSet = null)
     */
    public boolean isGoogleAccountType() {
        return GoogleAccountType.ACCOUNT_TYPE.equals(accountType) && dataSet == null;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -501,7 +501,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
            boolean syncable =
                ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;

            if (syncable) {
            if (syncable || GoogleAccountType.ACCOUNT_TYPE.equals(account.type)) {
                List<AccountType> accountTypes = accountTypesByType.get(account.type);
                if (accountTypes != null) {
                    // Add an account-with-data-set entry for each account type that is
Loading