aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-04-17 09:34:04 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-04-17 09:34:04 +0000
commitea779ff74be39ed58589c423035d787764fcb271 (patch)
tree4d5e13e5dd4990540fce428b4b679cb48e8134d4 /app/src/main
parent58efcce3a09f23b01dbd199fc422f44a0ba79dbc (diff)
downloadinfinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar.gz
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar.bz2
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar.lz
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar.xz
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.tar.zst
infinity-for-reddit-ea779ff74be39ed58589c423035d787764fcb271.zip
Minor bugs fixed.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java146
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java14
-rw-r--r--app/src/main/res/layout/item_post_detail.xml2
10 files changed, 138 insertions, 113 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
index ce53e892..323cd7ab 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
@@ -64,7 +64,7 @@ import pl.droidsonroids.gif.GifImageView;
public class ViewGIFActivity extends AppCompatActivity {
- public static final String IMAGE_URL_KEY = "IUK";
+ public static final String GIF_URL_KEY = "GUK";
public static final String FILE_NAME_KEY = "FNK";
public static final String POST_TITLE_KEY = "PTK";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@@ -120,11 +120,15 @@ public class ViewGIFActivity extends AppCompatActivity {
glide = Glide.with(this);
Intent intent = getIntent();
- mImageUrl = intent.getStringExtra(IMAGE_URL_KEY);
+ mImageUrl = intent.getStringExtra(GIF_URL_KEY);
mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
postTitle = intent.getStringExtra(POST_TITLE_KEY);
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ if (postTitle != null) {
+ setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ } else {
+ setTitle("");
+ }
mLoadErrorLinearLayout.setOnClickListener(view -> {
if (!isSwiping) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
index 6b0e0c7d..1ec2de8d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
@@ -129,7 +129,11 @@ public class ViewImageActivity extends AppCompatActivity {
mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
postTitle = intent.getStringExtra(POST_TITLE_KEY);
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ if (postTitle != null) {
+ setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ } else {
+ setTitle("");
+ }
mLoadErrorLinearLayout.setOnClickListener(view -> {
if (!isSwiping) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
index 2bb35763..11e0d56d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -135,7 +135,11 @@ public class ViewVideoActivity extends AppCompatActivity {
videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4";
postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ if (postTitle != null) {
+ setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ } else {
+ setTitle("");
+ }
final float pxHeight = getResources().getDisplayMetrics().heightPixels;
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 c003a876..ccbd0e61 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -494,14 +494,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (mPost.getAuthorFlairHTML() != null && !mPost.getAuthorFlairHTML().equals("")) {
((PostDetailViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE);
- Spannable flairHTML;
- GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailViewHolder) holder).mAuthorFlairTextView);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
- flairHTML = (Spannable) Html.fromHtml(mPost.getAuthorFlairHTML(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
- } else {
- flairHTML = (Spannable) Html.fromHtml(mPost.getAuthorFlairHTML(), glideImageGetter, null);
- }
- ((PostDetailViewHolder) holder).mAuthorFlairTextView.setText(flairHTML);
+ Utils.setHTMLWithImageToTextView(((PostDetailViewHolder) holder).mAuthorFlairTextView, mPost.getAuthorFlairHTML());
((PostDetailViewHolder) holder).mAuthorFlairTextView.setOnClickListener(view -> ((PostDetailViewHolder) holder).mUserTextView.performClick());
} else if (mPost.getAuthorFlair() != null && !mPost.getAuthorFlair().equals("")) {
((PostDetailViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE);
@@ -587,14 +580,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (mPost.getAwards() != null && !mPost.getAwards().equals("")) {
((PostDetailViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE);
- Spannable awardsHTML;
- GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailViewHolder) holder).mAwardsTextView);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
- awardsHTML = (Spannable) Html.fromHtml(mPost.getAwards(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
- } else {
- awardsHTML = (Spannable) Html.fromHtml(mPost.getAwards(), glideImageGetter, null);
- }
- ((PostDetailViewHolder) holder).mAwardsTextView.setText(awardsHTML);
+ Utils.setHTMLWithImageToTextView(((PostDetailViewHolder) holder).mAwardsTextView, mPost.getAwards());
}
if (mPost.isNSFW()) {
@@ -630,6 +616,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPost.getUrl());
intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
+ "-" + mPost.getId().substring(3) + ".jpg");
+ intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle());
mActivity.startActivity(intent);
});
@@ -663,7 +650,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mActivity, ViewGIFActivity.class);
intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName()
+ "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewGIFActivity.IMAGE_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle());
mActivity.startActivity(intent);
});
@@ -679,6 +667,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
mActivity.startActivity(intent);
});
@@ -844,14 +833,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
- Spannable flairHTML;
- GlideImageGetter glideImageGetter = new GlideImageGetter(((CommentViewHolder) holder).authorFlairTextView);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
- flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlairHTML(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
- } else {
- flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlairHTML(), glideImageGetter, null);
- }
- ((CommentViewHolder) holder).authorFlairTextView.setText(flairHTML);
+ Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML());
((CommentViewHolder) holder).authorFlairTextView.setOnClickListener(view -> ((CommentViewHolder) holder).authorTextView.performClick());
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
@@ -2217,7 +2199,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
commentMarkdownView.setTextColor(mCommentTextColor);
authorFlairTextView.setTextColor(mAuthorFlairTextColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
- awardsTextView.setTextColor(mCommentTextColor);
+ awardsTextView.setTextColor(mSecondaryTextColor);
commentDivider.setBackgroundColor(mDividerColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
index 12b05085..ce0d30eb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
@@ -74,6 +74,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private int mCommentColor;
private int mDividerColor;
private int mUsernameColor;
+ private int mAuthorFlairColor;
private int mSubredditColor;
private int mUpvotedColor;
private int mDownvotedColor;
@@ -135,6 +136,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mDividerColor = customThemeWrapper.getDividerColor();
mSubredditColor = customThemeWrapper.getSubreddit();
mUsernameColor = customThemeWrapper.getUsername();
+ mAuthorFlairColor = customThemeWrapper.getAuthorFlairTextColor();
mUpvotedColor = customThemeWrapper.getUpvoted();
mDownvotedColor = customThemeWrapper.getDownvoted();
mButtonTextColor = customThemeWrapper.getButtonTextColor();
@@ -146,7 +148,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_DATA) {
- return new DataViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
+ return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
} else if (viewType == VIEW_TYPE_ERROR) {
return new ErrorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false));
} else {
@@ -156,53 +158,65 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
- if (holder instanceof DataViewHolder) {
+ if (holder instanceof CommentViewHolder) {
CommentData comment = getItem(holder.getAdapterPosition());
if (comment != null) {
if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) {
- ((DataViewHolder) holder).authorTextView.setText("u/" + comment.getLinkAuthor());
- ((DataViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
- ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).authorTextView.setText("u/" + comment.getLinkAuthor());
+ ((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
+ ((CommentViewHolder) holder).authorTextView.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getLinkAuthor());
mContext.startActivity(intent);
});
} else {
- ((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
- ((DataViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
- ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
+ ((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
+ ((CommentViewHolder) holder).authorTextView.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
mContext.startActivity(intent);
});
}
+ if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
+ ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
+ Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML());
+ } else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
+ ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
+ ((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
+ }
+
if (mShowElapsedTime) {
- ((DataViewHolder) holder).commentTimeTextView.setText(
+ ((CommentViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mContext, comment.getCommentTimeMillis()));
} else {
- ((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
+ ((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
+ }
+
+ if (comment.getAwards() != null && !comment.getAwards().equals("")) {
+ Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards());
}
- mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
+ mMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
- ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
switch (comment.getVoteType()) {
case CommentData.VOTE_TYPE_UPVOTE:
- ((DataViewHolder) holder).upvoteButton
+ ((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
break;
case CommentData.VOTE_TYPE_DOWNVOTE:
- ((DataViewHolder) holder).downvoteButton
+ ((CommentViewHolder) holder).downvoteButton
.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
break;
}
- ((DataViewHolder) holder).moreButton.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).moreButton.setOnClickListener(view -> {
Bundle bundle = new Bundle();
if (comment.getAuthor().equals(mAccountName)) {
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
@@ -214,21 +228,21 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
commentMoreBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), commentMoreBottomSheetFragment.getTag());
});
- ((DataViewHolder) holder).linearLayout.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).linearLayout.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
mContext.startActivity(intent);
});
- ((DataViewHolder) holder).verticalBlock.setVisibility(View.GONE);
+ ((CommentViewHolder) holder).verticalBlock.setVisibility(View.GONE);
- ((DataViewHolder) holder).commentMarkdownView.setOnClickListener(view ->
- ((DataViewHolder) holder).linearLayout.callOnClick());
+ ((CommentViewHolder) holder).commentMarkdownView.setOnClickListener(view ->
+ ((CommentViewHolder) holder).linearLayout.callOnClick());
- ((DataViewHolder) holder).replyButton.setVisibility(View.GONE);
+ ((CommentViewHolder) holder).replyButton.setVisibility(View.GONE);
- ((DataViewHolder) holder).upvoteButton.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).upvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
@@ -237,24 +251,24 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
String newVoteType;
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (previousVoteType != CommentData.VOTE_TYPE_UPVOTE) {
//Not upvoted before
comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE);
newVoteType = RedditUtils.DIR_UPVOTE;
- ((DataViewHolder) holder).upvoteButton
+ ((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE);
newVoteType = RedditUtils.DIR_UNVOTE;
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
- ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@@ -262,16 +276,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void onVoteThingSuccess(int position) {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE);
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
} else {
comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE);
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
@@ -281,7 +295,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}, comment.getFullName(), newVoteType, holder.getAdapterPosition());
});
- ((DataViewHolder) holder).downvoteButton.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).downvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show();
return;
@@ -290,23 +304,23 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
String newVoteType;
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (previousVoteType != CommentData.VOTE_TYPE_DOWNVOTE) {
//Not downvoted before
comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE);
newVoteType = RedditUtils.DIR_DOWNVOTE;
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
} else {
//Downvoted before
comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE);
newVoteType = RedditUtils.DIR_UNVOTE;
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
- ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@@ -314,16 +328,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE);
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
} else {
comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE);
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
@@ -334,26 +348,26 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
});
if (comment.isSaved()) {
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
} else {
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
- ((DataViewHolder) holder).saveButton.setOnClickListener(view -> {
+ ((CommentViewHolder) holder).saveButton.setOnClickListener(view -> {
if (comment.isSaved()) {
comment.setSaved(false);
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
@Override
public void success() {
comment.setSaved(false);
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
Toast.makeText(mContext, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(true);
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
Toast.makeText(mContext, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
});
@@ -363,14 +377,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void success() {
comment.setSaved(true);
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
Toast.makeText(mContext, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(false);
- ((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
+ ((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
Toast.makeText(mContext, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
});
@@ -396,10 +410,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
- if (holder instanceof DataViewHolder) {
- ((DataViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
+ if (holder instanceof CommentViewHolder) {
+ ((CommentViewHolder) holder).authorFlairTextView.setText("");
+ ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
+ ((CommentViewHolder) holder).awardsTextView.setText("");
+ ((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
+ ((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ ((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
@@ -435,15 +453,19 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
void retryLoadingMore();
}
- class DataViewHolder extends RecyclerView.ViewHolder {
+ class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.linear_layout_item_comment)
LinearLayout linearLayout;
@BindView(R.id.vertical_block_item_post_comment)
View verticalBlock;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
+ @BindView(R.id.author_flair_text_view_item_post_comment)
+ TextView authorFlairTextView;
@BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView;
+ @BindView(R.id.awards_text_view_item_comment)
+ TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
TextView commentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
@@ -465,7 +487,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@BindView(R.id.divider_item_comment)
View commentDivider;
- DataViewHolder(View itemView) {
+ CommentViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
@@ -494,7 +516,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor);
+ authorFlairTextView.setTextColor(mAuthorFlairColor);
commentTimeTextView.setTextColor(mSecondaryTextColor);
+ awardsTextView.setTextColor(mSecondaryTextColor);
commentMarkdownView.setTextColor(mCommentColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
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 27e77146..ca001e85 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -453,14 +453,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (awards != null && !awards.equals("")) {
((PostViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
- Spannable awardsHTML;
- GlideImageGetter glideImageGetter = new GlideImageGetter(((PostViewHolder) holder).awardsTextView);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
- awardsHTML = (Spannable) Html.fromHtml(awards, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
- } else {
- awardsHTML = (Spannable) Html.fromHtml(awards, glideImageGetter, null);
- }
- ((PostViewHolder) holder).awardsTextView.setText(awardsHTML);
+ Utils.setHTMLWithImageToTextView(((PostViewHolder) holder).awardsTextView, awards);
}
switch (voteType) {
@@ -553,7 +546,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
intent.setData(gifVideoUri);
intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, subredditName
+ "-" + id + ".gif");
- intent.putExtra(ViewGIFActivity.IMAGE_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, post.getTitle());
mActivity.startActivity(intent);
});
@@ -1118,7 +1111,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
intent.setData(gifVideoUri);
intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, subredditName
+ "-" + id + ".gif");
- intent.putExtra(ViewGIFActivity.IMAGE_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
mActivity.startActivity(intent);
});
@@ -1691,7 +1684,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
archivedImageView.setColorFilter(mArchivedIconTint, PorterDuff.Mode.SRC_IN);
lockedImageView.setColorFilter(mLockedIconTint, PorterDuff.Mode.SRC_IN);
crosspostImageView.setColorFilter(mCrosspostIconTint, PorterDuff.Mode.SRC_IN);
- awardsTextView.setTextColor(mPostTitleColor);
+ awardsTextView.setTextColor(mSecondaryTextColor);
linkTextView.setTextColor(mSecondaryTextColor);
progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
noPreviewLinkImageView.setBackgroundColor(mNoPreviewLinkBackgroundColor);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index b8f4bfd4..6990c287 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -125,9 +125,9 @@ public class ParseComment {
JSONObject flairObject = flairArray.getJSONObject(i);
String e = flairObject.getString(JSONUtils.E_KEY);
if (e.equals("text")) {
- authorFlairHTMLBuilder.append(flairObject.getString(JSONUtils.T_KEY));
+ authorFlairHTMLBuilder.append(Html.escapeHtml(flairObject.getString(JSONUtils.T_KEY)));
} else if (e.equals("emoji")) {
- authorFlairHTMLBuilder.append("<img src=\"").append(flairObject.getString(JSONUtils.U_KEY)).append("\">");
+ authorFlairHTMLBuilder.append("<img src=\"").append(Html.escapeHtml(flairObject.getString(JSONUtils.U_KEY))).append("\">");
}
}
}
@@ -153,10 +153,10 @@ public class ParseComment {
JSONArray icons = award.getJSONArray(JSONUtils.RESIZED_ICONS_KEY);
if (icons.length() > 4) {
String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY);
- awardingsBuilder.append("<img src=\"").append(iconUrl).append("\"> ").append("x").append(count).append(" ");
+ awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
} else if (icons.length() > 0) {
String iconUrl = icons.getJSONObject(icons.length() - 1).getString(JSONUtils.URL_KEY);
- awardingsBuilder.append("<img src=\"").append(iconUrl).append("\"> ").append("x").append(count).append(" ");
+ awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
}
}
int score = singleCommentData.getInt(JSONUtils.SCORE_KEY);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 49329844..b8cd4977 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -46,7 +46,7 @@ public class ParsePost {
if (e.equals("text")) {
authorFlairHTMLBuilder.append(flairObject.getString(JSONUtils.T_KEY));
} else if (e.equals("emoji")) {
- authorFlairHTMLBuilder.append("<img src=\"").append(flairObject.getString(JSONUtils.U_KEY)).append("\">");
+ authorFlairHTMLBuilder.append("<img src=\"").append(Html.escapeHtml(flairObject.getString(JSONUtils.U_KEY))).append("\">");
}
}
}
@@ -70,9 +70,9 @@ public class ParsePost {
JSONObject flairObject = flairArray.getJSONObject(i);
String e = flairObject.getString(JSONUtils.E_KEY);
if (e.equals("text")) {
- postFlairHTMLBuilder.append(flairObject.getString(JSONUtils.T_KEY));
+ postFlairHTMLBuilder.append(Html.escapeHtml(flairObject.getString(JSONUtils.T_KEY)));
} else if (e.equals("emoji")) {
- postFlairHTMLBuilder.append("<img src=\"").append(flairObject.getString(JSONUtils.U_KEY)).append("\">");
+ postFlairHTMLBuilder.append("<img src=\"").append(Html.escapeHtml(flairObject.getString(JSONUtils.U_KEY))).append("\">");
}
}
}
@@ -85,10 +85,10 @@ public class ParsePost {
JSONArray icons = award.getJSONArray(JSONUtils.RESIZED_ICONS_KEY);
if (icons.length() > 4) {
String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY);
- awardingsBuilder.append("<img src=\"").append(iconUrl).append("\"> ").append("x").append(count).append(" ");
+ awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
} else if (icons.length() > 0) {
String iconUrl = icons.getJSONObject(icons.length() - 1).getString(JSONUtils.URL_KEY);
- awardingsBuilder.append("<img src=\"").append(iconUrl).append("\"> ").append("x").append(count).append(" ");
+ awardingsBuilder.append("<img src=\"").append(Html.escapeHtml(iconUrl)).append("\"> ").append("x").append(count).append(" ");
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
index fea670d0..f3788ff8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
@@ -1,6 +1,9 @@
package ml.docilealligator.infinityforreddit.Utils;
import android.content.Context;
+import android.text.Html;
+import android.text.Spannable;
+import android.widget.TextView;
import java.util.Locale;
@@ -73,4 +76,15 @@ public class Utils {
return String.format(Locale.US, "%.1f", (float) votes / 1000) + "K";
}
}
+
+ public static void setHTMLWithImageToTextView(TextView textView, String content) {
+ Spannable html;
+ GlideImageGetter glideImageGetter = new GlideImageGetter(textView);
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ html = (Spannable) Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null);
+ } else {
+ html = (Spannable) Html.fromHtml(content, glideImageGetter, null);
+ }
+ textView.setText(html);
+ }
}
diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml
index dd8b842f..61cf7399 100644
--- a/app/src/main/res/layout/item_post_detail.xml
+++ b/app/src/main/res/layout/item_post_detail.xml
@@ -58,7 +58,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:textColor="?attr/username"
- android:textSize="?attr/font_default"
+ android:textSize="?attr/font_12"
android:maxLines="2"
android:ellipsize="end"
android:visibility="gone"