Skip to content

Commit

Permalink
Merge pull request #7989 from wordpress-mobile/feature/glide-pages-po…
Browse files Browse the repository at this point in the history
…sts-list

Replace Volley with Glide in the PostsListAdapter
  • Loading branch information
oguzkocer authored Jul 16, 2018
2 parents 0059e92 + 2129142 commit 5dedbc0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()) }
}
}
3 changes: 1 addition & 2 deletions WordPress/src/main/res/layout/post_cardview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
android:background="?android:selectableItemBackground"
android:orientation="vertical">

<org.wordpress.android.widgets.WPNetworkImageView
<ImageView
android:id="@+id/image_featured"
android:layout_width="match_parent"
android:layout_height="@dimen/postlist_featured_image_height"
android:scaleType="centerCrop"
android:visibility="gone"
android:contentDescription="@string/featured_image_desc"
tools:visibility="visible" />
Expand Down

0 comments on commit 5dedbc0

Please sign in to comment.