From 51d92945476dc068a2baf7aa5bccce29b38ec83c Mon Sep 17 00:00:00 2001 From: malinajirka Date: Mon, 23 Jul 2018 09:44:14 +0200 Subject: [PATCH] Replace Volley with Glide in custom reader tag header view --- .../ui/reader/views/ReaderTagHeaderView.java | 17 ++++++++++------- .../main/res/layout/reader_tag_header_view.xml | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderTagHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderTagHeaderView.java index a4bec8615628..ea7b6a1e268c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderTagHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderTagHeaderView.java @@ -3,6 +3,8 @@ import android.content.Context; import android.util.AttributeSet; import android.view.View; +import android.widget.ImageView; +import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.TextView; @@ -18,7 +20,8 @@ import org.wordpress.android.ui.reader.utils.ReaderUtils; import org.wordpress.android.util.JSONUtils; import org.wordpress.android.util.PhotonUtils; -import org.wordpress.android.widgets.WPNetworkImageView; +import org.wordpress.android.util.image.ImageManager; +import org.wordpress.android.util.image.ImageType; import java.util.HashMap; @@ -26,7 +29,7 @@ * topmost view in post adapter when showing tag preview - displays tag name and follow button */ public class ReaderTagHeaderView extends RelativeLayout { - private WPNetworkImageView mImageView; + private ImageView mImageView; private TextView mTxtAttribution; private ReaderTag mCurrentTag; @@ -49,8 +52,8 @@ public ReaderTagHeaderView(Context context, AttributeSet attrs, int defStyleAttr private void initView(Context context) { View view = inflate(context, R.layout.reader_tag_header_view, this); - mImageView = (WPNetworkImageView) view.findViewById(R.id.image_tag_header); - mTxtAttribution = (TextView) view.findViewById(R.id.text_attribution); + mImageView = view.findViewById(R.id.image_tag_header); + mTxtAttribution = view.findViewById(R.id.text_attribution); } public void setCurrentTag(final ReaderTag tag) { @@ -62,11 +65,11 @@ public void setCurrentTag(final ReaderTag tag) { if (isTagChanged) { mTxtAttribution.setText(null); - mImageView.resetImage(); + ImageManager.getInstance().cancelRequestAndClearImageView(mImageView); mCurrentTag = tag; } - TextView txtTagName = (TextView) findViewById(R.id.text_tag); + TextView txtTagName = findViewById(R.id.text_tag); txtTagName.setText(tag.getLabel()); // use cached info if it's available, otherwise request it if the tag has changed @@ -81,7 +84,7 @@ private void setTagHeaderInfo(final ReaderTagHeaderInfo info) { int imageWidth = mImageView.getWidth(); int imageHeight = getContext().getResources().getDimensionPixelSize(R.dimen.reader_tag_header_image_height); String photonUrl = PhotonUtils.getPhotonImageUrl(info.getImageUrl(), imageWidth, imageHeight); - mImageView.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO); + ImageManager.getInstance().load(mImageView, ImageType.PHOTO, photonUrl, ScaleType.CENTER_CROP); // show attribution line - author name when available, otherwise blog name or nothing if (info.hasAuthorName()) { diff --git a/WordPress/src/main/res/layout/reader_tag_header_view.xml b/WordPress/src/main/res/layout/reader_tag_header_view.xml index e42e28ec72c7..c6336071efb9 100644 --- a/WordPress/src/main/res/layout/reader_tag_header_view.xml +++ b/WordPress/src/main/res/layout/reader_tag_header_view.xml @@ -6,11 +6,11 @@ android:layout_height="@dimen/reader_tag_header_image_height" android:layout_marginBottom="@dimen/margin_extra_small"> - + android:contentDescription="@null"/>