From 70e65565ae14792b4bbb93f5b4468e7a60d6ba98 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 2 Aug 2019 18:06:01 +0800 Subject: Show vote unavailable message if the vote buttons of an archived post are clicked. --- .../CommentAndPostRecyclerViewAdapter.java | 17 +++++++++++++ .../infinityforreddit/JSONUtils.java | 1 + .../infinityforreddit/ParsePost.java | 29 +++++++++++----------- .../ml/docilealligator/infinityforreddit/Post.java | 18 +++++++++++--- .../infinityforreddit/PostRecyclerViewAdapter.java | 18 ++++++++++++++ 5 files changed, 65 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index d99fc6c6..26776df0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -255,6 +255,13 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + ColorFilter previousUpvoteButtonColorFilter = mUpvoteButton.getColorFilter(); ColorFilter previousDownvoteButtonColorFilter = mDownvoteButton.getColorFilter(); int previousVoteType = mPost.getVoteType(); @@ -758,6 +770,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + ColorFilter previousUpvoteButtonColorFilter = mUpvoteButton.getColorFilter(); ColorFilter previousDownvoteButtonColorFilter = mDownvoteButton.getColorFilter(); int previousVoteType = mPost.getVoteType(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index f0f72a28..f4301aab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -71,4 +71,5 @@ public class JSONUtils { static final String RULES_KEY = "rules"; static final String SHORT_NAME_KEY = "short_name"; static final String DESCRIPTION_HTML_KEY = "description_html"; + static final String ARCHIVED_KEY = "archived"; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index a1f614ce..7003d91a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -145,6 +145,7 @@ class ParsePost { boolean spoiler = data.getBoolean(JSONUtils.SPOILER_KEY); boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY); boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY); + boolean archived = data.getBoolean(JSONUtils.ARCHIVED_KEY); String flair = null; if(!data.isNull(JSONUtils.LINK_FLAIR_TEXT_KEY)) { flair = data.getString(JSONUtils.LINK_FLAIR_TEXT_KEY); @@ -179,11 +180,11 @@ class ParsePost { data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); return parseData(data, permalink, id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, true, i); + score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, true, i); } else { return parseData(data, permalink, id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, false, i); + score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, false, i); } } @@ -191,7 +192,7 @@ class ParsePost { String subredditNamePrefixed, String author, String formattedPostTime, String title, String previewUrl, int previewWidth, int previewHeight, int score, int voteType, int gilded, String flair, boolean spoiler, - boolean nsfw, boolean stickied, boolean isCrosspost, int i) throws JSONException { + boolean nsfw, boolean stickied, boolean archived, boolean isCrosspost, int i) throws JSONException { Post post; boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); @@ -204,7 +205,7 @@ class ParsePost { int postType = Post.TEXT_TYPE; post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, permalink, score, postType, voteType, gilded, flair, spoiler, nsfw, - stickied, isCrosspost); + stickied, archived, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfText(""); } else { @@ -216,7 +217,7 @@ class ParsePost { int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfText(""); } else { @@ -238,7 +239,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, isCrosspost, true); + gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, true); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -255,7 +256,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, isCrosspost, false); + gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, false); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -270,7 +271,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, isCrosspost, true); + gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, true); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -283,7 +284,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, url, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -295,7 +296,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, permalink, score, postType, voteType, gilded, flair, spoiler, - nsfw, stickied, isCrosspost); + nsfw, stickied, archived, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -311,8 +312,8 @@ class ParsePost { int postType = Post.LINK_TYPE; post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, url, permalink, score, - postType, voteType, gilded, flair, spoiler, nsfw, stickied, isCrosspost); + title, previewUrl, url, permalink, score, postType, voteType, gilded, + flair, spoiler, nsfw, stickied, archived, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfText(""); } else { @@ -332,7 +333,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { @@ -342,7 +343,7 @@ class ParsePost { post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title, url, url, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, isCrosspost); + gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index f6159533..69e37c31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -40,14 +40,15 @@ class Post implements Parcelable { private boolean spoiler; private boolean nsfw; private boolean stickied; + private boolean archived; private boolean isCrosspost; private boolean isDashVideo; private boolean isDownloadableGifOrVideo; - private Post crosspostParentPost; Post(String id, String fullName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, - int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean isCrosspost, boolean isDashVideo) { + int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, + boolean isCrosspost, boolean isDashVideo) { this.id = id; this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; @@ -65,6 +66,7 @@ class Post implements Parcelable { this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; + this.archived = archived; this.isCrosspost = isCrosspost; this.isDashVideo = isDashVideo; } @@ -72,7 +74,7 @@ class Post implements Parcelable { Post(String id, String fullName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, - boolean isCrosspost) { + boolean archived, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; @@ -91,12 +93,13 @@ class Post implements Parcelable { this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; + this.archived = archived; this.isCrosspost = isCrosspost; } Post(String id, String fullName, String subredditNamePrefixed, String author, String postTime, String title, String permalink, int score, int postType, int voteType, int gilded, String flair, - boolean spoiler, boolean nsfw, boolean stickied, boolean isCrosspost) { + boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditNamePrefixed = subredditNamePrefixed; @@ -113,6 +116,7 @@ class Post implements Parcelable { this.spoiler = spoiler; this.nsfw = nsfw; this.stickied = stickied; + this.archived = archived; this.isCrosspost= isCrosspost; } @@ -142,6 +146,7 @@ class Post implements Parcelable { spoiler = in.readByte() != 0; nsfw = in.readByte() != 0; stickied = in.readByte() != 0; + archived = in.readByte() != 0; isCrosspost = in.readByte() != 0; isDashVideo = in.readByte() != 0; isDownloadableGifOrVideo = in.readByte() != 0; @@ -316,6 +321,10 @@ class Post implements Parcelable { return stickied; } + boolean isArchived() { + return archived; + } + boolean isCrosspost() { return isCrosspost; } @@ -347,6 +356,7 @@ class Post implements Parcelable { parcel.writeByte((byte) (spoiler ? 1 : 0)); parcel.writeByte((byte) (nsfw ? 1 : 0)); parcel.writeByte((byte) (stickied ? 1 : 0)); + parcel.writeByte((byte) (archived ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isDashVideo ? 1 : 0)); parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index b84e8a85..724b00ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -147,6 +147,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter { if(canStartActivity) { @@ -350,6 +351,13 @@ class PostRecyclerViewAdapter extends PagedListAdapter { + if(isArchived) { + Toast.makeText(mContext, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + ColorFilter previousUpvoteButtonColorFilter = ((DataViewHolder) holder).upvoteButton.getColorFilter(); ColorFilter previousDownvoteButtonColorFilter = ((DataViewHolder) holder).downvoteButton.getColorFilter(); int previousVoteType = post.getVoteType(); @@ -495,6 +508,11 @@ class PostRecyclerViewAdapter extends PagedListAdapter { + if(isArchived) { + Toast.makeText(mContext, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + ColorFilter previousUpvoteButtonColorFilter = ((DataViewHolder) holder).upvoteButton.getColorFilter(); ColorFilter previousDownvoteButtonColorFilter = ((DataViewHolder) holder).downvoteButton.getColorFilter(); -- cgit v1.2.3