diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java index 9c98b6f728f9..c1c826cbf279 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java @@ -44,7 +44,7 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.post_list_activity); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (savedInstanceState == null) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/adapters/PostsListAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/adapters/PostsListAdapter.java index b22674236cc6..a5b0fce347bf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/adapters/PostsListAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/adapters/PostsListAdapter.java @@ -23,6 +23,7 @@ import android.view.animation.DecelerateInterpolator; import android.widget.AdapterView; import android.widget.ImageView; +import android.widget.ImageView.ScaleType; import android.widget.ProgressBar; import android.widget.TextView; @@ -53,8 +54,9 @@ import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.ImageUtils; import org.wordpress.android.util.SiteUtils; +import org.wordpress.android.util.image.ImageManager; +import org.wordpress.android.util.image.ImageType; import org.wordpress.android.widgets.PostListButton; -import org.wordpress.android.widgets.WPNetworkImageView; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -110,6 +112,7 @@ public enum LoadMode { @Inject protected PostStore mPostStore; @Inject protected MediaStore mMediaStore; @Inject protected UploadStore mUploadStore; + @Inject protected ImageManager mImageManager; public PostsListAdapter(Context context, @NonNull SiteModel site, boolean isPage) { ((WordPress) context.getApplicationContext()).component().inject(this); @@ -160,7 +163,7 @@ private boolean isValidPostPosition(int position) { } @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) { + public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); mRecyclerView = recyclerView; } @@ -183,7 +186,7 @@ public int getItemCount() { } @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_ENDLIST_INDICATOR) { View view = mLayoutInflater.inflate(R.layout.endlist_indicator, parent, false); view.getLayoutParams().height = mEndlistIndicatorHeight; @@ -210,7 +213,7 @@ private boolean canPublishPost(PostModel post) { } @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { // nothing to do if this is the static endlist indicator if (getItemViewType(position) == VIEW_TYPE_ENDLIST_INDICATOR) { return; @@ -333,24 +336,25 @@ public void onClick(View v) { }); } - private void showFeaturedImage(int postId, WPNetworkImageView imgFeatured) { + private void showFeaturedImage(int postId, ImageView imgFeatured) { String imageUrl = mFeaturedImageUrls.get(postId); if (imageUrl == null) { imgFeatured.setVisibility(View.GONE); + mImageManager.cancelRequestAndClearImageView(imgFeatured); } else if (imageUrl.startsWith("http")) { String photonUrl = ReaderUtils.getResizedImageUrl( imageUrl, mPhotonWidth, mPhotonHeight, !SiteUtils.isPhotonCapable(mSite)); imgFeatured.setVisibility(View.VISIBLE); - imgFeatured.setImageUrl(photonUrl, WPNetworkImageView.ImageType.PHOTO); + mImageManager.load(imgFeatured, ImageType.PHOTO, photonUrl, ScaleType.CENTER_CROP); } else { Bitmap bmp = ImageUtils.getWPImageSpanThumbnailFromFilePath( imgFeatured.getContext(), imageUrl, mPhotonWidth); if (bmp != null) { - imgFeatured.setImageUrl(null, WPNetworkImageView.ImageType.NONE); imgFeatured.setVisibility(View.VISIBLE); - imgFeatured.setImageBitmap(bmp); + mImageManager.load(imgFeatured, bmp); } else { imgFeatured.setVisibility(View.GONE); + mImageManager.cancelRequestAndClearImageView(imgFeatured); } } } @@ -431,6 +435,7 @@ private void updateStatusTextAndImage(TextView txtStatus, ImageView imgStatus, P if ((PostStatus.fromPost(post) == PostStatus.PUBLISHED) && !post.isLocalDraft() && !post.isLocallyChanged()) { txtStatus.setVisibility(View.GONE); imgStatus.setVisibility(View.GONE); + mImageManager.cancelRequestAndClearImageView(imgStatus); } else { int statusTextResId = 0; int statusIconResId = 0; @@ -490,6 +495,15 @@ private void updateStatusTextAndImage(TextView txtStatus, ImageView imgStatus, P statusIconResId = R.drawable.ic_gridicons_page; statusColorResId = R.color.alert_red; break; + case UNKNOWN: + // no-op + break; + case PUBLISHED: + // no-op + break; + default: + // no-op + return; } } @@ -506,10 +520,11 @@ private void updateStatusTextAndImage(TextView txtStatus, ImageView imgStatus, P if (drawable != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, resources.getColor(statusColorResId)); - imgStatus.setImageDrawable(drawable); imgStatus.setVisibility(View.VISIBLE); + mImageManager.load(imgStatus, drawable); } else { imgStatus.setVisibility(View.GONE); + mImageManager.cancelRequestAndClearImageView(imgStatus); } } } @@ -731,7 +746,7 @@ private class PostViewHolder extends RecyclerView.ViewHolder { private final PostListButton mBtnTrash; private final PostListButton mBtnBack; - private final WPNetworkImageView mImgFeatured; + private final ImageView mImgFeatured; private final ViewGroup mLayoutButtons; private final View mDisabledOverlay; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderPostAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderPostAdapter.java index 653fec38a7b0..65f547cd1ea9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderPostAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderPostAdapter.java @@ -906,7 +906,7 @@ private void updateBookmarkView(final ReaderPostViewHolder holder, final ReaderP } else { bookmarkButton.setVisibility(View.GONE); } - bookmarkButton.setImageResource(post.isBookmarked + mImageManager.load(bookmarkButton, post.isBookmarked ? R.drawable.ic_bookmark_blue_medium_18dp : R.drawable.ic_bookmark_grey_min_18dp); if (post.isBookmarked) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderThumbnailStrip.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderThumbnailStrip.java index c93ceb8fd99f..524ab3817db6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderThumbnailStrip.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderThumbnailStrip.java @@ -95,7 +95,7 @@ public void loadThumbnails(long blogId, long postId, boolean isPrivate) { mView.addView(view); String photonUrl = PhotonUtils.getPhotonImageUrl(imageUrl, mThumbnailWidth, mThumbnailHeight); - ImageManager.loadImage(imageView, ImageType.PHOTO, photonUrl, ScaleType.CENTER_CROP); + ImageManager.getInstance().load(imageView, ImageType.PHOTO, photonUrl, ScaleType.CENTER_CROP); // tapping a thumbnail opens the photo viewer imageView.setOnClickListener(new OnClickListener() { diff --git a/WordPress/src/main/java/org/wordpress/android/util/image/ImageManager.kt b/WordPress/src/main/java/org/wordpress/android/util/image/ImageManager.kt index 7c40ae2d7ddf..592367b4702b 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/image/ImageManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/image/ImageManager.kt @@ -47,6 +47,14 @@ class ImageManager @Inject constructor(val placeholderManager: ImagePlaceholderM .into(imageView) } + @JvmOverloads + fun load(imageView: ImageView, resourceId: Int, scaleType: ImageView.ScaleType = CENTER) { + GlideApp.with(imageView.context) + .load(resourceId) + .applyScaleType(scaleType) + .into(imageView) + } + fun loadIntoCircle(imageView: ImageView, imageType: ImageType, imgUrl: String) { GlideApp.with(imageView.context) .load(imgUrl) @@ -91,50 +99,7 @@ class ImageManager @Inject constructor(val placeholderManager: ImagePlaceholderM @Deprecated("Object for backward compatibility with code which doesn't support DI") companion object { @JvmStatic - @Deprecated("Use injected ImageManager", - ReplaceWith("imageManager.load(imageView, imgUrl, placeholder, scaleType)", - "org.wordpress.android.util.image.ImageManager")) - fun loadImage( - imageView: ImageView, - imageType: ImageType, - imgUrl: String, - scaleType: ImageView.ScaleType - ) { - ImageManager(ImagePlaceholderManager()).load(imageView, imageType, imgUrl, scaleType) - } - - @JvmStatic - @Deprecated("Use injected ImageManager", - ReplaceWith("imageManager.load(imageView, bitmap, scaleType)", - "org.wordpress.android.util.image.ImageManager")) - @JvmOverloads - fun loadImage(imageView: ImageView, bitmap: Bitmap, scaleType: ImageView.ScaleType = CENTER) { - ImageManager(ImagePlaceholderManager()).load(imageView, bitmap, scaleType) - } - - @JvmStatic - @Deprecated("Use injected ImageManager", - ReplaceWith("imageManager.load(imageView, drawable, scaleType)", - "org.wordpress.android.util.image.ImageManager")) - @JvmOverloads - fun loadImage(imageView: ImageView, drawable: Drawable, scaleType: ImageView.ScaleType = CENTER) { - ImageManager(ImagePlaceholderManager()).load(imageView, drawable, scaleType) - } - - @JvmStatic - @Deprecated("Use injected ImageManager", - ReplaceWith("imageManager.loadIntoCircle(imageView, imgType, imgUrl)", - "org.wordpress.android.util.image.ImageManager")) - fun loadImageIntoCircle(imageView: ImageView, imageType: ImageType, imgUrl: String) { - ImageManager(ImagePlaceholderManager()).loadIntoCircle(imageView, imageType, imgUrl) - } - - @JvmStatic - @Deprecated("Use injected ImageManager", - ReplaceWith("imageManager.clear(imageView)", - "org.wordpress.android.util.image.ImageManager")) - fun clear(imageView: ImageView) { - ImageManager(ImagePlaceholderManager()).cancelRequestAndClearImageView(imageView) - } + @Deprecated("Use injected ImageManager") + val instance: ImageManager by lazy { ImageManager(ImagePlaceholderManager()) } } } diff --git a/WordPress/src/main/res/layout/post_cardview.xml b/WordPress/src/main/res/layout/post_cardview.xml index 94c7b663745d..22c3bb0e7884 100644 --- a/WordPress/src/main/res/layout/post_cardview.xml +++ b/WordPress/src/main/res/layout/post_cardview.xml @@ -17,11 +17,10 @@ android:background="?android:selectableItemBackground" android:orientation="vertical"> -