summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/searchfragment/remote
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/searchfragment/remote')
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteContactViewHolder.java9
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java40
-rw-r--r--java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java2
3 files changed, 44 insertions, 7 deletions
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactViewHolder.java b/java/com/android/dialer/searchfragment/remote/RemoteContactViewHolder.java
index 5fb12d349..df3eacc5b 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteContactViewHolder.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteContactViewHolder.java
@@ -22,6 +22,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.Contacts;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
@@ -119,10 +120,14 @@ public final class RemoteContactViewHolder extends RecyclerView.ViewHolder
return (String) Phone.getTypeLabel(resources, numberType, numberLabel);
}
- private static Uri getContactUri(Cursor cursor) {
+ private static Uri getContactUri(SearchCursor cursor) {
long contactId = cursor.getLong(Projections.PHONE_ID);
String lookupKey = cursor.getString(Projections.PHONE_LOOKUP_KEY);
- return ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
+ return Contacts.getLookupUri(contactId, lookupKey)
+ .buildUpon()
+ .appendQueryParameter(
+ ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(cursor.getDirectoryId()))
+ .build();
}
@Override
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
index d7c4f3805..e6f3c2607 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteContactsCursor.java
@@ -26,6 +26,7 @@ import com.android.dialer.common.Assert;
import com.android.dialer.searchfragment.common.SearchCursor;
import com.android.dialer.searchfragment.remote.RemoteDirectoriesCursorLoader.Directory;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -41,6 +42,16 @@ import java.util.List;
public final class RemoteContactsCursor extends MergeCursor implements SearchCursor {
/**
+ * {@link SearchCursor#HEADER_PROJECTION} with {@link #COLUMN_DIRECTORY_ID} appended on the end.
+ *
+ * <p>This is needed to get the directoryId associated with each contact. directoryIds are needed
+ * to load the correct quick contact card.
+ */
+ private static final String[] PROJECTION = buildProjection();
+
+ private static final String COLUMN_DIRECTORY_ID = "directory_id";
+
+ /**
* Returns a single cursor with headers inserted between each non-empty cursor. If all cursors are
* empty, null or closed, this method returns null.
*/
@@ -78,18 +89,24 @@ public final class RemoteContactsCursor extends MergeCursor implements SearchCur
continue;
}
- cursorList.add(createHeaderCursor(context, directory.getDisplayName()));
+ cursorList.add(createHeaderCursor(context, directory.getDisplayName(), directory.getId()));
cursorList.add(cursor);
}
return cursorList.toArray(new Cursor[cursorList.size()]);
}
- private static MatrixCursor createHeaderCursor(Context context, String name) {
- MatrixCursor headerCursor = new MatrixCursor(HEADER_PROJECTION, 1);
- headerCursor.addRow(new String[] {context.getString(R.string.directory, name)});
+ private static MatrixCursor createHeaderCursor(Context context, String name, int id) {
+ MatrixCursor headerCursor = new MatrixCursor(PROJECTION, 1);
+ headerCursor.addRow(new Object[] {context.getString(R.string.directory, name), id});
return headerCursor;
}
+ private static String[] buildProjection() {
+ String[] projection = Arrays.copyOf(HEADER_PROJECTION, HEADER_PROJECTION.length + 1);
+ projection[projection.length - 1] = COLUMN_DIRECTORY_ID;
+ return projection;
+ }
+
/** Returns true if the current position is a header row. */
@Override
public boolean isHeader() {
@@ -97,6 +114,21 @@ public final class RemoteContactsCursor extends MergeCursor implements SearchCur
}
@Override
+ public long getDirectoryId() {
+ int position = getPosition();
+ // proceed backwards until we reach the header row, which contains the directory ID.
+ while (moveToPrevious()) {
+ int id = getInt(getColumnIndex(COLUMN_DIRECTORY_ID));
+ if (id != -1) {
+ // return the cursor to it's original position/state
+ moveToPosition(position);
+ return id;
+ }
+ }
+ throw Assert.createIllegalStateFailException("No directory id for contact at: " + position);
+ }
+
+ @Override
public boolean updateQuery(@Nullable String query) {
// When the query changes, a new network request is made for nearby places. Meaning this cursor
// will be closed and another created, so return false.
diff --git a/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java b/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java
index 327a62c7b..de71025cd 100644
--- a/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java
+++ b/java/com/android/dialer/searchfragment/remote/RemoteDirectoriesCursorLoader.java
@@ -67,7 +67,7 @@ public final class RemoteDirectoriesCursorLoader extends CursorLoader {
return new AutoValue_RemoteDirectoriesCursorLoader_Directory(id, displayName, supportsPhotos);
}
- abstract int getId();
+ public abstract int getId();
/** Returns a user facing display name of the directory. Null if none exists. */
abstract @Nullable String getDisplayName();