Fix image preview not available. Fix gif autoplay.

This commit is contained in:
Alex Ning 2020-11-06 14:50:36 +08:00
parent 50f5612a14
commit 0201a661b2
2 changed files with 20 additions and 2 deletions

View File

@ -612,7 +612,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
} else if (post.getPostType() == Post.GIF_TYPE) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
if (!mAutoplay) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
}
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
} else if (post.getPostType() == Post.IMAGE_TYPE) {
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.image));
@ -964,7 +966,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private void loadImage(final RecyclerView.ViewHolder holder, final Post post, @NonNull Post.Preview preview) {
if (preview != null) {
if (holder instanceof PostWithPreviewTypeViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener<Drawable>() {
String url;
if (post.getPostType() == Post.GIF_TYPE && mAutoplay) {
url = post.getUrl();
} else {
url = preview.getPreviewUrl();
}
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE);

View File

@ -199,6 +199,9 @@ public class ParsePost {
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0));
}
post.setPreviews(previews);
} else {
//No preview link post
@ -278,6 +281,9 @@ public class ParsePost {
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw,
stickied, archived, locked, saved, isCrosspost);
if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0));
}
post.setPreviews(previews);
} else if (url.endsWith("gif")){
//Gif post
@ -359,6 +365,10 @@ public class ParsePost {
authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0));
}
post.setPreviews(previews);
} else if (url.endsWith("mp4")) {
//Video post