prevent crash in NotificationsAdapter when avatar url is not set

This commit is contained in:
Conny Duck 2018-01-15 17:06:21 +01:00
parent 0426e8725a
commit 8fa1320afe

View file

@ -264,6 +264,9 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
displayNameView.setText(displayName); displayNameView.setText(displayName);
if (TextUtils.isEmpty(avatarUrl)) {
avatar.setImageResource(R.drawable.avatar_default);
} else {
Picasso.with(context) Picasso.with(context)
.load(avatarUrl) .load(avatarUrl)
.fit() .fit()
@ -271,6 +274,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
.placeholder(R.drawable.avatar_default) .placeholder(R.drawable.avatar_default)
.into(avatar); .into(avatar);
} }
}
void setupButtons(final NotificationActionListener listener, final String accountId) { void setupButtons(final NotificationActionListener listener, final String accountId) {
avatar.setOnClickListener(v -> listener.onViewAccount(accountId)); avatar.setOnClickListener(v -> listener.onViewAccount(accountId));
@ -407,7 +411,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
void setAvatars(@Nullable String statusAvatarUrl, @Nullable String notificationAvatarUrl) { void setAvatars(@Nullable String statusAvatarUrl, @Nullable String notificationAvatarUrl) {
Context context = statusAvatar.getContext(); Context context = statusAvatar.getContext();
if (statusAvatarUrl == null || statusAvatarUrl.isEmpty()) { if (TextUtils.isEmpty(statusAvatarUrl)) {
statusAvatar.setImageResource(R.drawable.avatar_default); statusAvatar.setImageResource(R.drawable.avatar_default);
} else { } else {
Picasso.with(context) Picasso.with(context)
@ -417,7 +421,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
.into(statusAvatar); .into(statusAvatar);
} }
if (notificationAvatarUrl == null || notificationAvatarUrl.isEmpty()) { if (TextUtils.isEmpty(notificationAvatarUrl)) {
notificationAvatar.setImageResource(R.drawable.avatar_default); notificationAvatar.setImageResource(R.drawable.avatar_default);
} else { } else {
Picasso.with(context) Picasso.with(context)