Don't pass null contact uri into glide

Fixes #5216
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2016-02-12 11:19:11 -08:00
parent 5cb7b7a981
commit f1cec5a2ca
2 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
@ -41,7 +42,13 @@ public class ContactPhotoFactory {
return getContactPhoto(context, uri, name, targetSize); return getContactPhoto(context, uri, name, targetSize);
} }
public static ContactPhoto getContactPhoto(Context context, Uri uri, String name, int targetSize) { public static ContactPhoto getContactPhoto(@NonNull Context context,
@Nullable Uri uri,
@Nullable String name,
int targetSize)
{
if (uri == null) return getDefaultContactPhoto(name);
try { try {
Bitmap bitmap = Glide.with(context) Bitmap bitmap = Glide.with(context)
.load(new ContactPhotoUri(uri)).asBitmap() .load(new ContactPhotoUri(uri)).asBitmap()

View File

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.mms;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.GenericLoaderFactory; import com.bumptech.glide.load.model.GenericLoaderFactory;
@ -41,9 +42,9 @@ public class ContactPhotoUriLoader implements StreamModelLoader<ContactPhotoUri>
} }
public static class ContactPhotoUri { public static class ContactPhotoUri {
public Uri uri; public @NonNull Uri uri;
public ContactPhotoUri(Uri uri) { public ContactPhotoUri(@NonNull Uri uri) {
this.uri = uri; this.uri = uri;
} }
} }