diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-02 10:06:01 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-02 10:06:01 +0000 |
commit | 70e65565ae14792b4bbb93f5b4468e7a60d6ba98 (patch) | |
tree | 16daeed839642da9df1e6b2fe2c5215849ee2703 /app/src | |
parent | b42db1fbfeb0cd7aca448e311cf26e2d6a3b206f (diff) | |
download | infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar.gz infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar.bz2 infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar.lz infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar.xz infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.tar.zst infinity-for-reddit-70e65565ae14792b4bbb93f5b4468e7a60d6ba98.zip |
Show vote unavailable message if the vote buttons of an archived post are clicked.
Diffstat (limited to '')
7 files changed, 69 insertions, 18 deletions
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<RecyclerVie ((PostDetailViewHolder) holder).mImageView.setVisibility(View.GONE); } + if(mPost.isArchived()) { + ((PostDetailViewHolder) holder).mUpvoteButton + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + ((PostDetailViewHolder) holder).mDownvoteButton + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + } + if(mPost.isCrosspost()) { ((PostDetailViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE); } @@ -704,6 +711,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie }); mUpvoteButton.setOnClickListener(view -> { + 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<RecyclerVie }); mDownvoteButton.setOnClickListener(view -> { + 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<Post, RecyclerView.ViewHo boolean nsfw = post.isNSFW(); boolean spoiler = post.isSpoiler(); String flair = post.getFlair(); + boolean isArchived = post.isArchived(); ((DataViewHolder) holder).cardView.setOnClickListener(view -> { if(canStartActivity) { @@ -350,6 +351,13 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo glide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView); } + if(isArchived) { + ((DataViewHolder) holder).upvoteButton + .setColorFilter(ContextCompat.getColor(mContext, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).downvoteButton + .setColorFilter(ContextCompat.getColor(mContext, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + } + if(post.isCrosspost()) { ((DataViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); } @@ -441,6 +449,11 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo } ((DataViewHolder) holder).upvoteButton.setOnClickListener(view -> { + 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<Post, RecyclerView.ViewHo }); ((DataViewHolder) holder).downvoteButton.setOnClickListener(view -> { + 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(); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ff024d93..6bbfc9c6 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -27,4 +27,6 @@ <color name="roundedBottomSheetPrimaryBackground">#FFFFFF</color> <color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color> + + <color name="voteUnavailableVoteButtonColor">#F0F0F0</color> </resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f3d2bbfb..49e60111 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -149,4 +149,6 @@ <string name="open_link_with">Open link with</string> <string name="no_browser_found">No browser found</string> + + <string name="archived_post_vote_unavailable">Archived post. Vote unavailable.</string> </resources> |