mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Show vote unavailable message if the vote buttons of an archived post are clicked.
This commit is contained in:
parent
b42db1fbfe
commit
70e65565ae
@ -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();
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
||||
|
@ -27,4 +27,6 @@
|
||||
<color name="roundedBottomSheetPrimaryBackground">#FFFFFF</color>
|
||||
|
||||
<color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color>
|
||||
|
||||
<color name="voteUnavailableVoteButtonColor">#F0F0F0</color>
|
||||
</resources>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user