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

Commit dffb27dc authored by Ricky Wai's avatar Ricky Wai
Browse files

Add work contacts search and directory in ContactsCommon

Add CallableCompat, ContactsCompat, PhoneCompat to simplify the logic in code

Bug: 25836833
Change-Id: I2cdb3bc32ab069f2bb81f41c08cef852f8526d52
parent ac99d622
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.common.compat;

import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Callable;

import com.android.contacts.common.ContactsUtils;

public class CallableCompat {

    // TODO: Use N APIs
    private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
            Uri.withAppendedPath(Callable.CONTENT_URI, "filter_enterprise");

    public static Uri getContentFilterUri() {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
            return ENTERPRISE_CONTENT_FILTER_URI;
        }
        return Callable.CONTENT_FILTER_URI;
    }
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.common.compat;

import android.net.Uri;
import android.provider.ContactsContract.Contacts;

import com.android.contacts.common.ContactsUtils;

public class ContactsCompat {

    // TODO: Use N APIs
    private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
            Uri.withAppendedPath(Contacts.CONTENT_URI, "filter_enterprise");

    public static Uri getContentUri() {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
            return ENTERPRISE_CONTENT_FILTER_URI;
        }
        return Contacts.CONTENT_FILTER_URI;
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.common.compat;

import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Directory;

import com.android.contacts.common.ContactsUtils;

public class DirectoryCompat {

    // TODO: Use N APIs
    private static final Uri ENTERPRISE_CONTENT_URI =
            Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, "directories_enterprise");
    // TODO: Use N APIs
    private static final long ENTERPRISE_LOCAL_INVISIBLE = 1000000000L + Directory.LOCAL_INVISIBLE;

    public static Uri getContentUri() {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
            return ENTERPRISE_CONTENT_URI;
        }
        return Directory.CONTENT_URI;
    }

    public static boolean isInvisibleDirectory(long directoryId) {
        return (directoryId == Directory.LOCAL_INVISIBLE
                || directoryId == ENTERPRISE_LOCAL_INVISIBLE);
    }

    public static boolean isRemoteDirectory(long directoryId) {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
            return Directory.isRemoteDirectory(directoryId);
        }
        return !(directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE);
    }
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.common.compat;

import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;

import com.android.contacts.common.ContactsUtils;

public class PhoneCompat {

    // TODO: Use N APIs
    private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
            Uri.withAppendedPath(Phone.CONTENT_URI, "filter_enterprise");

    public static Uri getContentFilterUri() {
        // TODO: Use N APIs
        if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
            return ENTERPRISE_CONTENT_FILTER_URI;
        }
        return Phone.CONTENT_FILTER_URI;
    }
}
+3 −7
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.R;
import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.compat.DirectoryCompat;
import com.android.contacts.common.util.SearchUtil;

import java.util.HashSet;
@@ -416,7 +417,7 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter {
            if (getPartitionByDirectoryId(id) == -1) {
                DirectoryPartition partition = new DirectoryPartition(false, true);
                partition.setDirectoryId(id);
                if (isRemoteDirectory(id)) {
                if (DirectoryCompat.isRemoteDirectory(id)) {
                    partition.setLabel(mContext.getString(R.string.directory_search_label));
                } else {
                    partition.setLabel(mDefaultFilterHeaderText.toString());
@@ -621,7 +622,7 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter {
        TextView labelTextView = (TextView)view.findViewById(R.id.label);
        TextView displayNameTextView = (TextView)view.findViewById(R.id.display_name);
        labelTextView.setText(directoryPartition.getLabel());
        if (!isRemoteDirectory(directoryId)) {
        if (!DirectoryCompat.isRemoteDirectory(directoryId)) {
            displayNameTextView.setText(null);
        } else {
            String directoryName = directoryPartition.getDisplayName();
@@ -777,11 +778,6 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter {
        return uri;
    }

    public static boolean isRemoteDirectory(long directoryId) {
        return directoryId != Directory.DEFAULT
                && directoryId != Directory.LOCAL_INVISIBLE;
    }

    /**
     * Retrieves the lookup key and display name from a cursor, and returns a
     * {@link DefaultImageRequest} containing these contact details
Loading