aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-02-01 11:56:55 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-02-01 11:56:55 +0000
commit9dc596b9076963d48a9ac7d08b965cb540f9983f (patch)
tree9f44443bba99f77a080564669f65d11de25209a5 /app/src/main/java
parent1f1d6a97fa423c98043ebf798fe19ebb4c1d9165 (diff)
downloadinfinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar.gz
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar.bz2
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar.lz
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar.xz
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.tar.zst
infinity-for-reddit-9dc596b9076963d48a9ac7d08b965cb540f9983f.zip
Show image preview for some posts which were classified as link posts before.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java29
3 files changed, 38 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index b58c87ee..e001e632 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -125,6 +125,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mHasMoreComments;
private boolean loadMoreCommentsFailed;
private int mCommentBackgroundColor;
+ private float mScale;
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
private CopyTextBottomSheetFragment mCopyTextBottomSheetFragment;
@@ -228,6 +229,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
isInitiallyLoadingFailed = false;
mHasMoreComments = false;
loadMoreCommentsFailed = false;
+ mScale = activity.getResources().getDisplayMetrics().density;
TypedValue typedValue = new TypedValue();
mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
@@ -498,6 +500,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
+ "-" + mPost.getId().substring(3) + ".jpg");
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;
case Post.LINK_TYPE:
((PostDetailViewHolder) holder).mTypeTextView.setText("LINK");
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index ad9c215d..12d6ac8e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -9,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
@@ -97,6 +98,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean canStartActivity = true;
private int mPostType;
private int mPostLayout;
+ private float mScale;
private boolean mDisplaySubredditName;
private boolean mVoteButtonsOnTheRight;
private boolean mNeedBlurNSFW;
@@ -126,6 +128,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mShowElapsedTime = showElapsedTime;
mShowDividerInCompactLayout = showDividerInCompactLayout;
mPostLayout = postLayout;
+ mScale = activity.getResources().getDisplayMetrics().density;
mGlide = Glide.with(mActivity.getApplicationContext());
mRedditDataRoomDatabase = redditDataRoomDatabase;
mUserDao = redditDataRoomDatabase.userDao();
@@ -170,7 +173,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
String authorPrefixed = "u/" + post.getAuthor();
final String postTime = post.getPostTime();
final String title = post.getTitle();
- final String permalink = post.getPermalink();
int voteType = post.getVoteType();
int gilded = post.getGilded();
boolean nsfw = post.isNSFW();
@@ -439,6 +441,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
+ "-" + id + ".jpg");
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;
case Post.LINK_TYPE:
((PostViewHolder) holder).typeTextView.setText(R.string.link);
@@ -727,7 +734,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
String authorPrefixed = "u/" + post.getAuthor();
final String postTime = post.getPostTime();
final String title = post.getTitle();
- final String permalink = post.getPermalink();
int voteType = post.getVoteType();
int gilded = post.getGilded();
boolean nsfw = post.isNSFW();
@@ -1433,6 +1439,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).flairTextView.setVisibility(View.GONE);
((PostViewHolder) holder).linkTextView.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).playButtonImageView.setVisibility(View.GONE);
((PostViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 435cce53..1d2e2e6f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -141,15 +141,28 @@ public class ParsePost {
}
}
} else {
- //No preview link post
- int postType = Post.NO_PREVIEW_LINK_TYPE;
- post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis,
- title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
- gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
- if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
- post.setSelfText("");
+ 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 {
- post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
+ //No preview link post
+ int postType = Post.NO_PREVIEW_LINK_TYPE;
+ post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis,
+ title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
+ gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
+ if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
+ post.setSelfText("");
+ } else {
+ post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
+ }
}
}
} else {