From 2e3d8b8cae9fc4cf3141c41452ccee3ff89787e5 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Mon, 17 Apr 2017 11:03:05 +0200 Subject: [PATCH] fixes crash when media url is empty --- .../keylesspalace/tusky/StatusViewHolder.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 9addd6565..682155287 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -102,7 +102,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder { } private void setContent(Spanned content, Status.Mention[] mentions, - final StatusActionListener listener) { + final StatusActionListener listener) { /* Redirect URLSpan's in the status content to the listener for viewing tag pages and * account pages. */ SpannableStringBuilder builder = new SpannableStringBuilder(content); @@ -230,7 +230,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder { } private void setMediaPreviews(final Status.MediaAttachment[] attachments, - boolean sensitive, final StatusActionListener listener) { + boolean sensitive, final StatusActionListener listener) { final ImageView[] previews = { mediaPreview0, mediaPreview1, @@ -249,20 +249,32 @@ class StatusViewHolder extends RecyclerView.ViewHolder { previews[i].setVisibility(View.VISIBLE); - Picasso.with(context) - .load(previewUrl) - .placeholder(mediaPreviewUnloadedId) - .into(previews[i]); + if(previewUrl == null || previewUrl.isEmpty()) { + Picasso.with(context) + .load(mediaPreviewUnloadedId) + .into(previews[i]); + } else { + Picasso.with(context) + .load(previewUrl) + .placeholder(mediaPreviewUnloadedId) + .into(previews[i]); + } final String url = attachments[i].url; final Status.MediaAttachment.Type type = attachments[i].type; - previews[i].setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - listener.onViewMedia(url, type); - } - }); + if(url == null || url.isEmpty()) { + previews[i].setOnClickListener(null); + } else { + previews[i].setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.onViewMedia(url, type); + } + }); + } + + } if (sensitive) {