summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2017-08-31 02:01:35 -0700
committerEric Erfanian <erfanian@google.com>2017-09-06 16:42:02 -0700
commitdede7e703541f81af4533ce4a53f18f327090568 (patch)
treee85d530eef4e2ffe4b450ff937c188832ed22d72 /java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java
parent6627396c33440abd1bd32daa617aa4848be167e1 (diff)
NewSearchFragment contact photos now properly open quick contact cards.
There was an issue where businesses' and remote contacts' contact photos wouldn't open contact cards correctly. The issue was rooted in the incorrect contact uri being assigned to the quick contact badge. from the bugbash: 16. Tap on business icon from search results says “ no application found” instead of opening the business info 17. Same as #16 but with contact from Directory Google.com - “The contact doesn’t exist” when tapping contact icon Bug: 64902476 Test: existing PiperOrigin-RevId: 167111016 Change-Id: I4b6f7ca812d2fc4dc220951e8c05db2c8b8d6114
Diffstat (limited to 'java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java')
-rw-r--r--java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java b/java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java
index 6807a6e6b..c8bb36a73 100644
--- a/java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java
+++ b/java/com/android/dialer/searchfragment/nearbyplaces/NearbyPlacesCursorLoader.java
@@ -21,21 +21,37 @@ import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
+import android.support.annotation.NonNull;
import com.android.contacts.common.extensions.PhoneDirectoryExtenderAccessor;
+import com.android.dialer.common.LogUtil;
import com.android.dialer.searchfragment.common.Projections;
+import java.util.List;
/** Cursor loader for nearby places search results. */
public final class NearbyPlacesCursorLoader extends CursorLoader {
private static final String MAX_RESULTS = "3";
+ private static final long INVALID_DIRECTORY_ID = Long.MAX_VALUE;
+ private final long directoryId;
- public NearbyPlacesCursorLoader(Context context, String query) {
+ /**
+ * @param directoryIds List of directoryIds associated with all directories on device. Required in
+ * order to find a directory ID for the nearby places cursor that doesn't collide with
+ * existing directories.
+ */
+ public NearbyPlacesCursorLoader(
+ Context context, String query, @NonNull List<Integer> directoryIds) {
super(context, getContentUri(context, query), Projections.PHONE_PROJECTION, null, null, null);
+ this.directoryId = getDirectoryId(directoryIds);
}
@Override
public Cursor loadInBackground() {
- return NearbyPlacesCursor.newInstnace(getContext(), super.loadInBackground());
+ if (directoryId == INVALID_DIRECTORY_ID) {
+ LogUtil.i("NearbyPlacesCursorLoader.loadInBackground", "directory id not set.");
+ return null;
+ }
+ return NearbyPlacesCursor.newInstance(getContext(), super.loadInBackground(), directoryId);
}
private static Uri getContentUri(Context context, String query) {
@@ -46,4 +62,22 @@ public final class NearbyPlacesCursorLoader extends CursorLoader {
.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY, MAX_RESULTS)
.build();
}
+
+ private static long getDirectoryId(List<Integer> directoryIds) {
+ if (directoryIds.isEmpty()) {
+ return INVALID_DIRECTORY_ID;
+ }
+
+ // The Directory.LOCAL_INVISIBLE might not be a directory we use, but we can't reuse it's
+ // "special" ID.
+ long maxId = ContactsContract.Directory.LOCAL_INVISIBLE;
+ for (int i = 0, n = directoryIds.size(); i < n; i++) {
+ long id = directoryIds.get(i);
+ if (id > maxId) {
+ maxId = id;
+ }
+ }
+ // Add one so that the nearby places ID doesn't collide with extended directory IDs.
+ return maxId + 1;
+ }
}