From 7ae66a4ddc36259311303de34d5728b08daed446 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 7 Mar 2017 21:38:20 -0500 Subject: [PATCH] Fixed crash due to Picasso being handed empty strings for missing avatars and header images. --- .../java/com/keylesspalace/tusky/Account.java | 4 ++-- .../keylesspalace/tusky/AccountActivity.java | 22 ++++++++----------- .../keylesspalace/tusky/BlocksAdapter.java | 14 +++++++----- .../keylesspalace/tusky/FollowAdapter.java | 2 -- .../tusky/ViewThreadActivity.java | 1 - app/src/main/res/layout/item_blocked_user.xml | 2 +- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/Account.java b/app/src/main/java/com/keylesspalace/tusky/Account.java index 3b9ca997..ae88d2f3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/Account.java +++ b/app/src/main/java/com/keylesspalace/tusky/Account.java @@ -50,13 +50,13 @@ class Account { if (!avatarUrl.equals("/avatars/original/missing.png")) { account.avatar = avatarUrl; } else { - account.avatar = ""; + account.avatar = null; } String headerUrl = object.getString("header"); if (!headerUrl.equals("/headers/original/missing.png")) { account.header = headerUrl; } else { - account.header = ""; + account.header = null; } account.followersCount = object.getString("followers_count"); account.followingCount = object.getString("following_count"); diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index ef718b50..db7d2864 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -219,19 +219,15 @@ public class AccountActivity extends BaseActivity { note.setLinksClickable(true); note.setMovementMethod(LinkMovementMethod.getInstance()); - if (!account.avatar.isEmpty()) { - Picasso.with(this) - .load(account.avatar) - .placeholder(R.drawable.avatar_default) - .error(R.drawable.avatar_error) - .into(avatar); - } - if (!account.header.isEmpty()) { - Picasso.with(this) - .load(account.header) - .placeholder(R.drawable.account_header_missing) - .into(header); - } + Picasso.with(this) + .load(account.avatar) + .placeholder(R.drawable.avatar_default) + .error(R.drawable.avatar_error) + .into(avatar); + Picasso.with(this) + .load(account.header) + .placeholder(R.drawable.account_header_missing) + .into(header); openInWebUrl = account.url; java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); diff --git a/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java b/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java index 94fb7a3c..0b440547 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java @@ -20,9 +20,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageView; import android.widget.TextView; -import com.android.volley.toolbox.NetworkImageView; +import com.squareup.picasso.Picasso; import java.util.HashSet; import java.util.Set; @@ -88,7 +89,7 @@ class BlocksAdapter extends AccountAdapter { } private static class BlockedUserViewHolder extends RecyclerView.ViewHolder { - private NetworkImageView avatar; + private ImageView avatar; private TextView username; private TextView displayName; private Button unblock; @@ -96,7 +97,7 @@ class BlocksAdapter extends AccountAdapter { BlockedUserViewHolder(View itemView) { super(itemView); - avatar = (NetworkImageView) itemView.findViewById(R.id.blocked_user_avatar); + avatar = (ImageView) itemView.findViewById(R.id.blocked_user_avatar); displayName = (TextView) itemView.findViewById(R.id.blocked_user_display_name); username = (TextView) itemView.findViewById(R.id.blocked_user_username); unblock = (Button) itemView.findViewById(R.id.blocked_user_unblock); @@ -108,8 +109,11 @@ class BlocksAdapter extends AccountAdapter { String format = username.getContext().getString(R.string.status_username_format); String formattedUsername = String.format(format, account.username); username.setText(formattedUsername); - avatar.setImageUrl(account.avatar, - VolleySingleton.getInstance(avatar.getContext()).getImageLoader()); + Picasso.with(avatar.getContext()) + .load(account.avatar) + .error(R.drawable.avatar_error) + .placeholder(R.drawable.avatar_default) + .into(avatar); } void setupActionListener(final AccountActionListener listener, final boolean blocked, diff --git a/app/src/main/java/com/keylesspalace/tusky/FollowAdapter.java b/app/src/main/java/com/keylesspalace/tusky/FollowAdapter.java index 4e7b42c9..de70bcee 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FollowAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/FollowAdapter.java @@ -23,8 +23,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import com.android.volley.toolbox.ImageLoader; -import com.android.volley.toolbox.NetworkImageView; import com.squareup.picasso.Picasso; /** Both for follows and following lists. */ diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java index e9e0485e..0432fe8e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java @@ -15,7 +15,6 @@ package com.keylesspalace.tusky; -import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; diff --git a/app/src/main/res/layout/item_blocked_user.xml b/app/src/main/res/layout/item_blocked_user.xml index 661280c0..1d2a4a44 100644 --- a/app/src/main/res/layout/item_blocked_user.xml +++ b/app/src/main/res/layout/item_blocked_user.xml @@ -3,7 +3,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> -