From dd105d1c5448ab591d6efb0416206f0fbfb10166 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Mon, 23 Jul 2018 09:06:17 +0200 Subject: [PATCH] Replaces Volley with Glide in ReaderPostDetail section --- .../reader/views/ReaderLikingUsersView.java | 14 +++++--- .../views/ReaderPostDetailHeaderView.java | 32 ++++++++++--------- .../ui/reader/views/ReaderSimplePostView.java | 29 ++++++++--------- .../main/res/layout/reader_like_avatar.xml | 7 ++-- .../layout/reader_post_detail_header_view.xml | 11 ++++--- .../res/layout/reader_simple_post_view.xml | 11 ++++--- 6 files changed, 57 insertions(+), 47 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderLikingUsersView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderLikingUsersView.java index fab4cddbadd7..4cb0a7351937 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderLikingUsersView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderLikingUsersView.java @@ -5,6 +5,7 @@ import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; +import android.widget.ImageView; import android.widget.LinearLayout; import org.wordpress.android.R; @@ -14,7 +15,9 @@ import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.ReaderPost; import org.wordpress.android.models.ReaderUserIdList; -import org.wordpress.android.widgets.WPNetworkImageView; +import org.wordpress.android.util.StringUtils; +import org.wordpress.android.util.image.ImageManager; +import org.wordpress.android.util.image.ImageType; import java.util.ArrayList; @@ -27,6 +30,7 @@ public class ReaderLikingUsersView extends LinearLayout { private final int mLikeAvatarSz; @Inject AccountStore mAccountStore; + @Inject ImageManager mImageManager; public ReaderLikingUsersView(Context context) { this(context, null); @@ -100,15 +104,15 @@ private void showLikingAvatars(final ArrayList avatarUrls) { int index = 0; LayoutInflater inflater = LayoutInflater.from(getContext()); for (String url : avatarUrls) { - WPNetworkImageView imgAvatar; + ImageView imgAvatar; // reuse existing view when possible, otherwise inflate a new one if (index < numExistingViews) { - imgAvatar = (WPNetworkImageView) getChildAt(index); + imgAvatar = (ImageView) getChildAt(index); } else { - imgAvatar = (WPNetworkImageView) inflater.inflate(R.layout.reader_like_avatar, this, false); + imgAvatar = (ImageView) inflater.inflate(R.layout.reader_like_avatar, this, false); addView(imgAvatar); } - imgAvatar.setImageUrl(url, WPNetworkImageView.ImageType.AVATAR); + mImageManager.loadIntoCircle(imgAvatar, ImageType.AVATAR, StringUtils.notNullStr(url)); index++; } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderPostDetailHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderPostDetailHeaderView.java index 004371c10a47..d057f0005daf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderPostDetailHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderPostDetailHeaderView.java @@ -5,6 +5,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -19,7 +20,9 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.widgets.WPNetworkImageView; +import org.wordpress.android.util.image.ImageManager; +import org.wordpress.android.util.image.ImageType; + /** * topmost view in post detail - shows blavatar + avatar, author name, blog name, and follow button @@ -114,6 +117,7 @@ public void onClick(View v) { } private void showBlavatarAndAvatar(String blavatarUrl, String avatarUrl) { + ImageManager imageManager = ImageManager.getInstance(); boolean hasBlavatar = !TextUtils.isEmpty(blavatarUrl); boolean hasAvatar = !TextUtils.isEmpty(avatarUrl); @@ -122,8 +126,10 @@ private void showBlavatarAndAvatar(String blavatarUrl, String avatarUrl) { int frameSize = getResources().getDimensionPixelSize(R.dimen.reader_detail_header_avatar_frame); View avatarFrame = findViewById(R.id.frame_avatar); - WPNetworkImageView imgBlavatar = findViewById(R.id.image_header_blavatar); - WPNetworkImageView imgAvatar = findViewById(R.id.image_header_avatar); + ImageView imgBlavatar = findViewById(R.id.image_header_blavatar); + ImageView imgAvatar = findViewById(R.id.image_header_avatar); + imageManager.cancelRequestAndClearImageView(imgBlavatar); + imageManager.cancelRequestAndClearImageView(imgAvatar); /* * - if there's a blavatar and an avatar, show both of them overlaid using default sizing @@ -135,24 +141,21 @@ private void showBlavatarAndAvatar(String blavatarUrl, String avatarUrl) { int blavatarSz = getResources().getDimensionPixelSize(R.dimen.reader_detail_header_blavatar); imgBlavatar.getLayoutParams().height = blavatarSz; imgBlavatar.getLayoutParams().width = blavatarSz; - imgBlavatar.setImageUrl( - PhotonUtils.getPhotonImageUrl(blavatarUrl, blavatarSz, blavatarSz), - WPNetworkImageView.ImageType.BLAVATAR); + imageManager.load(imgBlavatar, ImageType.BLAVATAR, + PhotonUtils.getPhotonImageUrl(blavatarUrl, blavatarSz, blavatarSz)); imgBlavatar.setVisibility(View.VISIBLE); int avatarSz = getResources().getDimensionPixelSize(R.dimen.reader_detail_header_avatar); imgAvatar.getLayoutParams().height = avatarSz; imgAvatar.getLayoutParams().width = avatarSz; - imgAvatar.setImageUrl( - GravatarUtils.fixGravatarUrl(avatarUrl, avatarSz), - WPNetworkImageView.ImageType.AVATAR); + imageManager.loadIntoCircle(imgAvatar, ImageType.AVATAR, + GravatarUtils.fixGravatarUrl(avatarUrl, avatarSz)); imgAvatar.setVisibility(View.VISIBLE); } else if (hasBlavatar) { imgBlavatar.getLayoutParams().height = frameSize; imgBlavatar.getLayoutParams().width = frameSize; - imgBlavatar.setImageUrl( - PhotonUtils.getPhotonImageUrl(blavatarUrl, frameSize, frameSize), - WPNetworkImageView.ImageType.BLAVATAR); + imageManager.load(imgBlavatar, ImageType.BLAVATAR, + PhotonUtils.getPhotonImageUrl(blavatarUrl, frameSize, frameSize)); imgBlavatar.setVisibility(View.VISIBLE); imgAvatar.setVisibility(View.GONE); @@ -161,9 +164,8 @@ private void showBlavatarAndAvatar(String blavatarUrl, String avatarUrl) { imgAvatar.getLayoutParams().height = frameSize; imgAvatar.getLayoutParams().width = frameSize; - imgAvatar.setImageUrl( - GravatarUtils.fixGravatarUrl(avatarUrl, frameSize), - WPNetworkImageView.ImageType.AVATAR); + imageManager.loadIntoCircle(imgAvatar, ImageType.AVATAR, + GravatarUtils.fixGravatarUrl(avatarUrl, frameSize)); imgAvatar.setVisibility(View.VISIBLE); } else { imgBlavatar.setVisibility(View.GONE); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSimplePostView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSimplePostView.java index a9c4baad08dc..e2cf98d04e89 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSimplePostView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSimplePostView.java @@ -8,6 +8,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; +import android.widget.ImageView; +import android.widget.ImageView.ScaleType; import android.widget.LinearLayout; import android.widget.TextView; @@ -21,7 +23,8 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.widgets.WPNetworkImageView; +import org.wordpress.android.util.image.ImageManager; +import org.wordpress.android.util.image.ImageType; /** * single simple post view @@ -89,7 +92,7 @@ public void showPost(ReaderSimplePost simplePost, // site header only appears for global related posts if (isGlobal) { - WPNetworkImageView imgAvatar = siteHeader.findViewById(R.id.image_avatar); + ImageView imgAvatar = siteHeader.findViewById(R.id.image_avatar); TextView txtSiteName = siteHeader.findViewById(R.id.text_site_name); TextView txtAuthorName = siteHeader.findViewById(R.id.text_author_name); txtSiteName.setText(mSimplePost.getSiteName()); @@ -97,8 +100,9 @@ public void showPost(ReaderSimplePost simplePost, if (mSimplePost.hasAuthorAvatarUrl()) { imgAvatar.setVisibility(View.VISIBLE); String avatarUrl = GravatarUtils.fixGravatarUrl(mSimplePost.getAuthorAvatarUrl(), avatarSize); - imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR); + ImageManager.getInstance().loadIntoCircle(imgAvatar, ImageType.AVATAR, avatarUrl); } else { + ImageManager.getInstance().cancelRequestAndClearImageView(imgAvatar); imgAvatar.setVisibility(View.GONE); } @@ -174,14 +178,13 @@ public void onActionResult(boolean succeeded) { } private void showFeaturedImage(final View postView) { - final WPNetworkImageView imgFeatured = postView.findViewById(R.id.image_featured); + final ImageView imgFeatured = postView.findViewById(R.id.image_featured); // post must have an excerpt in order to show featured image (not enough space otherwise) if (!mSimplePost.hasFeaturedImageUrl() || !mSimplePost.hasExcerpt()) { imgFeatured.setVisibility(View.GONE); return; } - // featured image has height set to MATCH_PARENT so wait for parent view's layout to complete // before loading image so we can set the image height correctly, then tell the imageView // to crop the downloaded image to fit the exact width/height of the view @@ -189,19 +192,15 @@ private void showFeaturedImage(final View postView) { @Override public void onGlobalLayout() { postView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - int featuredImageWidth = DisplayUtils.dpToPx( - getContext(), - getContext().getResources().getDimensionPixelSize(R.dimen.reader_simple_post_image_width)); - int cropWidth = featuredImageWidth; + int cropWidth = + getContext().getResources().getDimensionPixelSize(R.dimen.reader_simple_post_image_width); int cropHeight = postView.getHeight(); String photonUrl = PhotonUtils.getPhotonImageUrl( mSimplePost.getFeaturedImageUrl(), cropWidth, cropHeight); - imgFeatured.setImageUrl( - photonUrl, - WPNetworkImageView.ImageType.PHOTO, - null, - cropWidth, - cropHeight); + ViewGroup.LayoutParams layoutParams = imgFeatured.getLayoutParams(); + layoutParams.height = cropHeight; + + ImageManager.getInstance().load(imgFeatured, ImageType.PHOTO, photonUrl, ScaleType.CENTER_CROP); } }); diff --git a/WordPress/src/main/res/layout/reader_like_avatar.xml b/WordPress/src/main/res/layout/reader_like_avatar.xml index a918298898d5..f47a0ffa7729 100644 --- a/WordPress/src/main/res/layout/reader_like_avatar.xml +++ b/WordPress/src/main/res/layout/reader_like_avatar.xml @@ -3,9 +3,12 @@ - + android:layout_marginEnd="@dimen/margin_small" + tools:ignore="ContentDescription"/> diff --git a/WordPress/src/main/res/layout/reader_post_detail_header_view.xml b/WordPress/src/main/res/layout/reader_post_detail_header_view.xml index 84ec15ace016..812615b51fb9 100644 --- a/WordPress/src/main/res/layout/reader_post_detail_header_view.xml +++ b/WordPress/src/main/res/layout/reader_post_detail_header_view.xml @@ -2,7 +2,6 @@ @@ -15,21 +14,23 @@ android:layout_marginRight="@dimen/margin_extra_large" android:layout_marginEnd="@dimen/margin_extra_large"> - + tools:src="@drawable/ic_placeholder_blavatar_grey_lighten_20_40dp" + android:contentDescription="@null"/> - + tools:src="@drawable/ic_placeholder_gravatar_grey_lighten_20_100dp" + android:contentDescription="@null"/> diff --git a/WordPress/src/main/res/layout/reader_simple_post_view.xml b/WordPress/src/main/res/layout/reader_simple_post_view.xml index 4f69892eb353..14feb5bb2cb7 100644 --- a/WordPress/src/main/res/layout/reader_simple_post_view.xml +++ b/WordPress/src/main/res/layout/reader_simple_post_view.xml @@ -8,16 +8,16 @@ android:layout_marginBottom="@dimen/margin_extra_large" android:background="?android:selectableItemBackground"> - + android:layout_marginEnd="@dimen/margin_large" + android:contentDescription="@null"/> - + android:layout_marginEnd="@dimen/margin_medium" + android:contentDescription="@null"/>