summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/searchfragment/remote
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-01-19 23:10:24 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-01-19 23:10:24 +0000
commit274b285b60fe2e054bcfb5f22e2f3bfa0340b1ce (patch)
treea90f1a29600bea4d937435fdd40424c7f0fece12 /java/com/android/dialer/searchfragment/remote
parentf101f6da201042951341939875be285348ae2425 (diff)
parenta6523ddb1db3d456ba4d16a120dea1ccd6c72d24 (diff)
Merge "Improve & reorganize logic related to directories/remote contacts in the search fragment."
Diffstat (limited to 'java/com/android/dialer/searchfragment/remote')
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java7
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java26
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java77
3 files changed, 21 insertions, 89 deletions
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
index e9e83c19b..9510443b9 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
@@ -24,7 +24,8 @@ import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import com.android.dialer.common.Assert;
import com.android.dialer.searchfragment.common.SearchCursor;
-import com.android.dialer.searchfragment.remote.RemoteDirectoriesCursorLoader.Directory;
+import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader;
+import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader.Directory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -33,7 +34,7 @@ import java.util.List;
* {@link MergeCursor} used for combining remote directory cursors into one cursor.
*
* <p>Usually a device with multiple Google accounts will have multiple remote directories returned
- * by {@link RemoteDirectoriesCursorLoader}, each represented as a {@link Directory}.
+ * by {@link DirectoriesCursorLoader}, each represented as a {@link Directory}.
*
* <p>This cursor merges them together with a header at the start of each cursor/list using {@link
* Directory#getDisplayName()} as the header text.
@@ -98,7 +99,7 @@ public final class RemoteContactsCursor extends MergeCursor implements SearchCur
return cursorList.toArray(new Cursor[cursorList.size()]);
}
- private static MatrixCursor createHeaderCursor(Context context, String name, int id) {
+ private static MatrixCursor createHeaderCursor(Context context, String name, long id) {
MatrixCursor headerCursor = new MatrixCursor(PROJECTION, 1);
headerCursor.addRow(new Object[] {context.getString(R.string.directory, name), id});
return headerCursor;
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java
index 5f92c4902..9feeb7e99 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursorLoader.java
@@ -27,9 +27,8 @@ import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
-import android.text.TextUtils;
import com.android.dialer.searchfragment.common.Projections;
-import com.android.dialer.searchfragment.remote.RemoteDirectoriesCursorLoader.Directory;
+import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader.Directory;
import java.util.ArrayList;
import java.util.List;
@@ -70,15 +69,13 @@ public final class RemoteContactsCursorLoader extends CursorLoader {
public Cursor loadInBackground() {
for (int i = 0; i < directories.size(); i++) {
Directory directory = directories.get(i);
- // Since the on device contacts could be queried as remote directories and we already query
- // them in SearchContactsCursorLoader, avoid querying them again.
- // TODO(calderwoodra): It's a happy coincidence that on device contacts don't have directory
- // names set, leaving this todo to investigate a better way to isolate them from other remote
- // directories.
- if (TextUtils.isEmpty(directory.getDisplayName())) {
+
+ // Filter out local directories
+ if (!isRemoteDirectory(directory.getId())) {
cursors[i] = null;
continue;
}
+
Cursor cursor =
getContext()
.getContentResolver()
@@ -96,6 +93,17 @@ public final class RemoteContactsCursorLoader extends CursorLoader {
return RemoteContactsCursor.newInstance(getContext(), cursors, directories);
}
+ private static boolean isRemoteDirectory(long directoryId) {
+ return VERSION.SDK_INT >= VERSION_CODES.N
+ ? ContactsContract.Directory.isRemoteDirectoryId(directoryId)
+ : (directoryId != ContactsContract.Directory.DEFAULT
+ && directoryId != ContactsContract.Directory.LOCAL_INVISIBLE
+ // Directory.ENTERPRISE_DEFAULT is the default work profile directory for locally stored
+ // contacts
+ && directoryId != ContactsContract.Directory.ENTERPRISE_DEFAULT
+ && directoryId != ContactsContract.Directory.ENTERPRISE_LOCAL_INVISIBLE);
+ }
+
private MatrixCursor createMatrixCursorFilteringNullNumbers(Cursor cursor) {
if (cursor == null) {
return null;
@@ -140,7 +148,7 @@ public final class RemoteContactsCursorLoader extends CursorLoader {
}
@VisibleForTesting
- static Uri getContentFilterUri(String query, int directoryId) {
+ static Uri getContentFilterUri(String query, long directoryId) {
Uri baseUri =
VERSION.SDK_INT >= VERSION_CODES.N
? ENTERPRISE_CONTENT_FILTER_URI
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java b/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java
deleted file mode 100644
index de71025cd..000000000
--- a/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
-
-* Copyright (C) 2017 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.dialer.searchfragment.remote;
-
-import android.content.Context;
-import android.content.CursorLoader;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Build.VERSION;
-import android.os.Build.VERSION_CODES;
-import android.provider.ContactsContract;
-import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
-import com.google.auto.value.AutoValue;
-
-/** CursorLoader to load the list of remote directories on the device. */
-public final class RemoteDirectoriesCursorLoader extends CursorLoader {
-
- /** Positions of columns in {@code PROJECTIONS}. */
- private static final int ID = 0;
-
- private static final int DISPLAY_NAME = 1;
- private static final int PHOTO_SUPPORT = 2;
-
- @VisibleForTesting
- static final String[] PROJECTION = {
- ContactsContract.Directory._ID,
- ContactsContract.Directory.DISPLAY_NAME,
- ContactsContract.Directory.PHOTO_SUPPORT,
- };
-
- public RemoteDirectoriesCursorLoader(Context context) {
- super(context, getContentUri(), PROJECTION, null, null, ContactsContract.Directory._ID);
- }
-
- /** @return current cursor row represented as a {@link Directory}. */
- public static Directory readDirectory(Cursor cursor) {
- return Directory.create(
- cursor.getInt(ID), cursor.getString(DISPLAY_NAME), cursor.getInt(PHOTO_SUPPORT) != 0);
- }
-
- private static Uri getContentUri() {
- return VERSION.SDK_INT >= VERSION_CODES.N
- ? ContactsContract.Directory.ENTERPRISE_CONTENT_URI
- : ContactsContract.Directory.CONTENT_URI;
- }
-
- /** POJO representing the results returned from {@link RemoteDirectoriesCursorLoader}. */
- @AutoValue
- public abstract static class Directory {
- public static Directory create(int id, @Nullable String displayName, boolean supportsPhotos) {
- return new AutoValue_RemoteDirectoriesCursorLoader_Directory(id, displayName, supportsPhotos);
- }
-
- public abstract int getId();
-
- /** Returns a user facing display name of the directory. Null if none exists. */
- abstract @Nullable String getDisplayName();
-
- abstract boolean supportsPhotos();
- }
-}