diff options
author | twyen <twyen@google.com> | 2018-05-23 18:03:48 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2018-05-30 14:03:22 +0000 |
commit | 33291b5f43eb97eb80119b565ce9130aacea9c35 (patch) | |
tree | a9c51008f2ac933c84757ae43fa1a113134852f8 | |
parent | 0fe130fed43cd295d4ef852d52b9dd102350016f (diff) |
Use lookup key to determine the letter tile color
The lookup key is part of the lookup URI that is supposed to be stable even if the row is moved around.
TEST=TAP
Bug: 78266240
Test: TAP
PiperOrigin-RevId: 197822055
Change-Id: Iee09556c284efaa68f71e1e0a69a511944c6b46e
-rw-r--r-- | java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java index 515a3ccbb..eeeae13ae 100644 --- a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java +++ b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java @@ -20,6 +20,7 @@ import android.content.ContentUris; import android.content.Context; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; import android.support.annotation.MainThread; import android.support.annotation.Nullable; @@ -35,10 +36,15 @@ import com.android.dialer.glidephotomanager.GlidePhotoManager; import com.android.dialer.glidephotomanager.PhotoInfo; import com.android.dialer.inject.ApplicationContext; import com.android.dialer.lettertile.LetterTileDrawable; +import java.util.List; import javax.inject.Inject; /** Implementation of {@link GlidePhotoManager} */ public class GlidePhotoManagerImpl implements GlidePhotoManager { + + private static final int LOOKUP_URI_PATH_SEGMENTS = + Contacts.CONTENT_LOOKUP_URI.getPathSegments().size(); + private final Context appContext; @Inject @@ -126,7 +132,7 @@ public class GlidePhotoManagerImpl implements GlidePhotoManager { : photoInfo.getName(); } else { displayName = photoInfo.getName(); - identifier = photoInfo.getLookupUri(); + identifier = getIdentifier(photoInfo.getLookupUri()); } letterTileDrawable.setCanonicalDialerLetterTileDetails( displayName, @@ -145,4 +151,27 @@ public class GlidePhotoManagerImpl implements GlidePhotoManager { private static Uri parseUri(@Nullable String uri) { return TextUtils.isEmpty(uri) ? null : Uri.parse(uri); } + + /** + * Return the "lookup key" inside the lookup URI. If the URI does not contain the key (i.e, JSON + * based prepopulated URIs for non-contact entries), the URI itself is returned. + * + * <p>The lookup URI has the format of Contacts.CONTENT_LOOKUP_URI/lookupKey/rowId. For JSON based + * URI, it would be Contacts.CONTENT_LOOKUP_URI/encoded#JSON + */ + private static String getIdentifier(String lookupUri) { + if (!lookupUri.startsWith(Contacts.CONTENT_LOOKUP_URI.toString())) { + return lookupUri; + } + + List<String> segments = Uri.parse(lookupUri).getPathSegments(); + if (segments.size() < LOOKUP_URI_PATH_SEGMENTS) { + return lookupUri; + } + String lookupKey = segments.get(LOOKUP_URI_PATH_SEGMENTS); + if ("encoded".equals(lookupKey)) { + return lookupUri; + } + return lookupKey; + } } |