Skip to content
Snippets Groups Projects
Commit 649d49f1 authored by Thibault Wittemberg's avatar Thibault Wittemberg Committed by Aline Bonnet
Browse files

vcard: prevent NPE when vcard has an empty photo

Change-Id: If7d0206eef39a4d309ccaf9a37625feaad008c84
Tuleap: #1143
parent 19352bac
No related branches found
No related tags found
No related merge requests found
...@@ -153,7 +153,15 @@ public class ContactDetailsTask implements Runnable { ...@@ -153,7 +153,15 @@ public class ContactDetailsTask implements Runnable {
if (vcard != null && !vcard.getPhotos().isEmpty()) { if (vcard != null && !vcard.getPhotos().isEmpty()) {
Photo tmp = vcard.getPhotos().get(0); Photo tmp = vcard.getPhotos().get(0);
externalBMP = CropImageUtils.cropImageToCircle(tmp.getData()); Bitmap croppedBitmap;
if (tmp != null && tmp.getData() != null) {
croppedBitmap = CropImageUtils.cropImageToCircle(tmp.getData());
} else {
croppedBitmap = decodeSampledBitmapFromResource(mContext.getResources(), R.drawable.ic_contact_picture, mViewWidth, mViewHeight);
}
externalBMP = croppedBitmap != null ? croppedBitmap : decodeSampledBitmapFromResource(mContext.getResources(), R.drawable.ic_contact_picture, mViewWidth, mViewHeight);
} else { } else {
Bitmap photoBmp; Bitmap photoBmp;
try { try {
......
...@@ -138,10 +138,14 @@ public class SmartListAdapter extends BaseAdapter { ...@@ -138,10 +138,14 @@ public class SmartListAdapter extends BaseAdapter {
} }
public class ViewHolder { public class ViewHolder {
@BindView(R.id.conv_participant) TextView convParticipants; @BindView(R.id.conv_participant)
@BindView(R.id.conv_last_item) TextView convStatus; TextView convParticipants;
@BindView(R.id.conv_last_time) TextView convTime; @BindView(R.id.conv_last_item)
@BindView(R.id.photo) ImageView photo; TextView convStatus;
@BindView(R.id.conv_last_time)
TextView convTime;
@BindView(R.id.photo)
ImageView photo;
int position; int position;
public Conversation conv; public Conversation conv;
......
...@@ -949,7 +949,12 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta ...@@ -949,7 +949,12 @@ public class CallFragment extends Fragment implements CallInterface, ContactDeta
if (!vcard.getPhotos().isEmpty()) { if (!vcard.getPhotos().isEmpty()) {
Photo tmp = vcard.getPhotos().get(0); Photo tmp = vcard.getPhotos().get(0);
if(tmp.getData() != null) {
contactBubbleView.setImageBitmap(CropImageUtils.cropImageToCircle(tmp.getData())); contactBubbleView.setImageBitmap(CropImageUtils.cropImageToCircle(tmp.getData()));
}
else{
setDefaultPhoto();
}
} else { } else {
setDefaultPhoto(); setDefaultPhoto();
} }
......
...@@ -36,9 +36,13 @@ public class CropImageUtils { ...@@ -36,9 +36,13 @@ public class CropImageUtils {
@Nullable @Nullable
public static Bitmap cropImageToCircle(@NonNull byte[] bArray) { public static Bitmap cropImageToCircle(@NonNull byte[] bArray) {
Bitmap bitmap = BitmapFactory.decodeByteArray(bArray, 0, bArray.length); Bitmap bitmap = BitmapFactory.decodeByteArray(bArray, 0, bArray.length);
if (bitmap != null) {
return cropImageToCircle(bitmap); return cropImageToCircle(bitmap);
} }
return null;
}
@Nullable @Nullable
public static Bitmap cropImageToCircle(@NonNull Bitmap image) { public static Bitmap cropImageToCircle(@NonNull Bitmap image) {
int side = Math.min(image.getWidth(), image.getHeight()); int side = Math.min(image.getWidth(), image.getHeight());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment