Skip to content

Commit 437ffba

Browse files
committed
Fix for NPE when Recipients is empty for thread.
// FREEBIE
1 parent 2be8a9b commit 437ffba

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/org/thoughtcrime/securesms/components/AvatarImageView.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import android.content.Context;
44
import android.content.Intent;
55
import android.provider.ContactsContract;
6+
import android.support.annotation.Nullable;
67
import android.util.AttributeSet;
78
import android.view.View;
89
import android.widget.ImageView;
910

11+
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
1012
import org.thoughtcrime.securesms.recipients.Recipient;
1113

1214
public class AvatarImageView extends ImageView {
@@ -21,9 +23,14 @@ public AvatarImageView(Context context, AttributeSet attrs) {
2123
setScaleType(ScaleType.CENTER_INSIDE);
2224
}
2325

24-
public void setAvatar(Recipient recipient, boolean quickContactEnabled) {
25-
setImageDrawable(recipient.getContactPhoto());
26-
setAvatarClickHandler(recipient, quickContactEnabled);
26+
public void setAvatar(@Nullable Recipient recipient, boolean quickContactEnabled) {
27+
if (recipient != null) {
28+
setImageDrawable(recipient.getContactPhoto());
29+
setAvatarClickHandler(recipient, quickContactEnabled);
30+
} else {
31+
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(getContext(), null));
32+
setOnClickListener(null);
33+
}
2734
}
2835

2936
private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) {

src/org/thoughtcrime/securesms/recipients/Recipients.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.thoughtcrime.securesms.recipients;
1818

19+
import android.support.annotation.Nullable;
1920
import android.util.Patterns;
2021

2122
import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener;
@@ -109,7 +110,7 @@ public boolean isSingleRecipient() {
109110
return this.recipients.size() == 1;
110111
}
111112

112-
public Recipient getPrimaryRecipient() {
113+
public @Nullable Recipient getPrimaryRecipient() {
113114
if (!isEmpty())
114115
return this.recipients.get(0);
115116
else

0 commit comments

Comments
 (0)