Show image preview for some posts which were classified as link posts before.

This commit is contained in:
Alex Ning 2020-02-01 19:56:55 +08:00
parent 1f1d6a97fa
commit 9dc596b907
4 changed files with 38 additions and 13 deletions

View File

@ -125,6 +125,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mHasMoreComments; private boolean mHasMoreComments;
private boolean loadMoreCommentsFailed; private boolean loadMoreCommentsFailed;
private int mCommentBackgroundColor; private int mCommentBackgroundColor;
private float mScale;
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment; private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
private CopyTextBottomSheetFragment mCopyTextBottomSheetFragment; private CopyTextBottomSheetFragment mCopyTextBottomSheetFragment;
@ -228,6 +229,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
isInitiallyLoadingFailed = false; isInitiallyLoadingFailed = false;
mHasMoreComments = false; mHasMoreComments = false;
loadMoreCommentsFailed = false; loadMoreCommentsFailed = false;
mScale = activity.getResources().getDisplayMetrics().density;
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
@ -498,6 +500,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
+ "-" + mPost.getId().substring(3) + ".jpg"); + "-" + mPost.getId().substring(3) + ".jpg");
mActivity.startActivity(intent); mActivity.startActivity(intent);
}); });
if (mPost.getPreviewWidth() <= 0 || mPost.getPreviewHeight() <= 0) {
((PostDetailViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostDetailViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale);
}
break; break;
case Post.LINK_TYPE: case Post.LINK_TYPE:
((PostDetailViewHolder) holder).mTypeTextView.setText("LINK"); ((PostDetailViewHolder) holder).mTypeTextView.setText("LINK");

View File

@ -9,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@ -97,6 +98,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean canStartActivity = true; private boolean canStartActivity = true;
private int mPostType; private int mPostType;
private int mPostLayout; private int mPostLayout;
private float mScale;
private boolean mDisplaySubredditName; private boolean mDisplaySubredditName;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mNeedBlurNSFW; private boolean mNeedBlurNSFW;
@ -126,6 +128,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mShowDividerInCompactLayout = showDividerInCompactLayout; mShowDividerInCompactLayout = showDividerInCompactLayout;
mPostLayout = postLayout; mPostLayout = postLayout;
mScale = activity.getResources().getDisplayMetrics().density;
mGlide = Glide.with(mActivity.getApplicationContext()); mGlide = Glide.with(mActivity.getApplicationContext());
mRedditDataRoomDatabase = redditDataRoomDatabase; mRedditDataRoomDatabase = redditDataRoomDatabase;
mUserDao = redditDataRoomDatabase.userDao(); mUserDao = redditDataRoomDatabase.userDao();
@ -170,7 +173,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
String authorPrefixed = "u/" + post.getAuthor(); String authorPrefixed = "u/" + post.getAuthor();
final String postTime = post.getPostTime(); final String postTime = post.getPostTime();
final String title = post.getTitle(); final String title = post.getTitle();
final String permalink = post.getPermalink();
int voteType = post.getVoteType(); int voteType = post.getVoteType();
int gilded = post.getGilded(); int gilded = post.getGilded();
boolean nsfw = post.isNSFW(); boolean nsfw = post.isNSFW();
@ -439,6 +441,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
+ "-" + id + ".jpg"); + "-" + id + ".jpg");
mActivity.startActivity(intent); mActivity.startActivity(intent);
}); });
if (post.getPreviewWidth() <= 0 || post.getPreviewHeight() <= 0) {
((PostViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
}
break; break;
case Post.LINK_TYPE: case Post.LINK_TYPE:
((PostViewHolder) holder).typeTextView.setText(R.string.link); ((PostViewHolder) holder).typeTextView.setText(R.string.link);
@ -727,7 +734,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
String authorPrefixed = "u/" + post.getAuthor(); String authorPrefixed = "u/" + post.getAuthor();
final String postTime = post.getPostTime(); final String postTime = post.getPostTime();
final String title = post.getTitle(); final String title = post.getTitle();
final String permalink = post.getPermalink();
int voteType = post.getVoteType(); int voteType = post.getVoteType();
int gilded = post.getGilded(); int gilded = post.getGilded();
boolean nsfw = post.isNSFW(); boolean nsfw = post.isNSFW();
@ -1433,6 +1439,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).flairTextView.setVisibility(View.GONE); ((PostViewHolder) holder).flairTextView.setVisibility(View.GONE);
((PostViewHolder) holder).linkTextView.setVisibility(View.GONE); ((PostViewHolder) holder).linkTextView.setVisibility(View.GONE);
((PostViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostViewHolder) holder).progressBar.setVisibility(View.GONE);
((PostViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.FIT_START);
((PostViewHolder) holder).imageView.getLayoutParams().height = FrameLayout.LayoutParams.WRAP_CONTENT;
((PostViewHolder) holder).imageView.setVisibility(View.GONE); ((PostViewHolder) holder).imageView.setVisibility(View.GONE);
((PostViewHolder) holder).playButtonImageView.setVisibility(View.GONE); ((PostViewHolder) holder).playButtonImageView.setVisibility(View.GONE);
((PostViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); ((PostViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);

View File

@ -140,6 +140,18 @@ public class ParsePost {
post.setSelfTextPlainTrimmed(selfTextPlain); post.setSelfTextPlainTrimmed(selfTextPlain);
} }
} }
} else {
if (url.endsWith("jpg") || url.endsWith("png")) {
//Image post
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink,
score, postType, voteType, gilded, nComments, flair, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight);
} else { } else {
//No preview link post //No preview link post
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
@ -152,6 +164,7 @@ public class ParsePost {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
} }
} }
}
} else { } else {
if (previewUrl.equals("")) { if (previewUrl.equals("")) {
previewUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0) previewUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)

View File

@ -419,7 +419,4 @@
<string name="save_comment">Save comment</string> <string name="save_comment">Save comment</string>
<string name="unsave_comment">Unsave comment</string> <string name="unsave_comment">Unsave comment</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources> </resources>