Proper Admin/Moderator indication

This commit adds proper indicators if a post or comment is made by a moderator or an admin. If a user is both an admin and a moderator, both indicators will be shown.

Closes #267
This commit is contained in:
Balazs Toldi 2024-07-30 09:32:16 +02:00
parent 4ccb1a38bf
commit 6457a4db2f
10 changed files with 180 additions and 44 deletions

View File

@ -0,0 +1,78 @@
package eu.toldi.infinityforlemmy;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
public class DualBadgeDrawable extends Drawable {
private Drawable leftBadge;
private Drawable rightBadge;
public DualBadgeDrawable(Drawable leftBadge, Drawable rightBadge) {
this.leftBadge = leftBadge;
this.rightBadge = rightBadge;
}
@Override
public void draw(Canvas canvas) {
if (leftBadge == null || rightBadge == null) {
return;
}
int width = getBounds().width();
int height = getBounds().height();
// Draw the left badge on the left half of the canvas
Rect leftRect = new Rect(0, 0, width / 2, height);
leftBadge.setBounds(leftRect);
leftBadge.draw(canvas);
// Draw the right badge on the right half of the canvas
Rect rightRect = new Rect(width / 2, 0, width, height);
rightBadge.setBounds(rightRect);
rightBadge.draw(canvas);
}
@Override
public void setAlpha(int alpha) {
if (leftBadge != null) {
leftBadge.setAlpha(alpha);
}
if (rightBadge != null) {
rightBadge.setAlpha(alpha);
}
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
if (leftBadge != null) {
leftBadge.setColorFilter(colorFilter);
}
if (rightBadge != null) {
rightBadge.setColorFilter(colorFilter);
}
}
@Override
public int getOpacity() {
return leftBadge != null ? leftBadge.getOpacity() : rightBadge.getOpacity();
}
@Override
public int getIntrinsicWidth() {
int leftWidth = leftBadge != null ? leftBadge.getIntrinsicWidth() : 0;
int rightWidth = rightBadge != null ? rightBadge.getIntrinsicWidth() : 0;
return leftWidth + rightWidth;
}
@Override
public int getIntrinsicHeight() {
int leftHeight = leftBadge != null ? leftBadge.getIntrinsicHeight() : 0;
int rightHeight = rightBadge != null ? rightBadge.getIntrinsicHeight() : 0;
return Math.max(leftHeight, rightHeight);
}
}

View File

@ -43,6 +43,7 @@ import java.util.regex.Pattern;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.DualBadgeDrawable;
import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder; import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SaveComment; import eu.toldi.infinityforlemmy.SaveComment;
@ -155,6 +156,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private int mUsernameColor; private int mUsernameColor;
private int mSubmitterColor; private int mSubmitterColor;
private int mModeratorColor; private int mModeratorColor;
private int mAdminColor;
private int mCurrentUserColor; private int mCurrentUserColor;
private int mAuthorFlairTextColor; private int mAuthorFlairTextColor;
private int mUpvotedColor; private int mUpvotedColor;
@ -271,6 +273,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mCommentBackgroundColor = customThemeWrapper.getCommentBackgroundColor(); mCommentBackgroundColor = customThemeWrapper.getCommentBackgroundColor();
mSubmitterColor = customThemeWrapper.getSubmitter(); mSubmitterColor = customThemeWrapper.getSubmitter();
mModeratorColor = customThemeWrapper.getModerator(); mModeratorColor = customThemeWrapper.getModerator();
mAdminColor = customThemeWrapper.getAdmin();
mCurrentUserColor = customThemeWrapper.getCurrentUser(); mCurrentUserColor = customThemeWrapper.getCurrentUser();
mAuthorFlairTextColor = customThemeWrapper.getAuthorFlairTextColor(); mAuthorFlairTextColor = customThemeWrapper.getAuthorFlairTextColor();
mUsernameColor = customThemeWrapper.getUsername(); mUsernameColor = customThemeWrapper.getUsername();
@ -392,11 +395,23 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor); Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds( ((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
submitterDrawable, null, null, null); submitterDrawable, null, null, null);
} else if (comment.isModerator() && comment.isAdmin()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
Drawable dualDrawable = new DualBadgeDrawable(adminDrawable, moderatorDrawable);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
dualDrawable, null, null, null);
} else if (comment.isModerator()) { } else if (comment.isModerator()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor); ((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor); Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds( ((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null); moderatorDrawable, null, null, null);
} else if (comment.isAdmin()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mAdminColor);
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
adminDrawable, null, null, null);
} else if (comment.getAuthorQualifiedName().equals(mAccountQualifiedName)) { } else if (comment.getAuthorQualifiedName().equals(mAccountQualifiedName)) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor); ((CommentBaseViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor); Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor);

View File

@ -58,6 +58,7 @@ import java.util.regex.Pattern;
import javax.inject.Provider; import javax.inject.Provider;
import eu.toldi.infinityforlemmy.DualBadgeDrawable;
import eu.toldi.infinityforlemmy.FetchRedgifsVideoLinks; import eu.toldi.infinityforlemmy.FetchRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo; import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.R;
@ -195,6 +196,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private int mSubredditColor; private int mSubredditColor;
private int mUsernameColor; private int mUsernameColor;
private int mModeratorColor; private int mModeratorColor;
private int mAdminColor;
private int mAuthorFlairTextColor; private int mAuthorFlairTextColor;
private int mSpoilerBackgroundColor; private int mSpoilerBackgroundColor;
private int mSpoilerTextColor; private int mSpoilerTextColor;
@ -380,6 +382,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mSubredditColor = customThemeWrapper.getSubreddit(); mSubredditColor = customThemeWrapper.getSubreddit();
mUsernameColor = customThemeWrapper.getUsername(); mUsernameColor = customThemeWrapper.getUsername();
mModeratorColor = customThemeWrapper.getModerator(); mModeratorColor = customThemeWrapper.getModerator();
mAdminColor = customThemeWrapper.getAdmin();
mUpvotedColor = customThemeWrapper.getUpvoted(); mUpvotedColor = customThemeWrapper.getUpvoted();
mDownvotedColor = customThemeWrapper.getDownvoted(); mDownvotedColor = customThemeWrapper.getDownvoted();
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor(); mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
@ -600,14 +603,25 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mUserInstanceTextView.setText('@' + mPost.getAuthorNamePrefixed().split(Pattern.quote("@"))[1]); ((PostDetailBaseViewHolder) holder).mUserInstanceTextView.setText('@' + mPost.getAuthorNamePrefixed().split(Pattern.quote("@"))[1]);
((PostDetailBaseViewHolder) holder).mCommunityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mSubredditColor, 0.7f)); ((PostDetailBaseViewHolder) holder).mCommunityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mSubredditColor, 0.7f));
((PostDetailBaseViewHolder) holder).mUserInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mPost.isModerator() || mPost.isAdmin() ? mModeratorColor : mUsernameColor, 0.7f)); ((PostDetailBaseViewHolder) holder).mUserInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mPost.isModerator() ? mModeratorColor : mPost.isAdmin() ? mAdminColor : mUsernameColor, 0.7f));
} }
if (mPost.isAdmin() && mPost.isModerator()) {
if (mPost.isModerator() || mPost.isAdmin()) { ((PostDetailBaseViewHolder) holder).userTextView.setTextColor(mModeratorColor);
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
Drawable dualBadge = new DualBadgeDrawable(adminDrawable, moderatorDrawable);
((PostDetailBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
dualBadge, null, null, null);
} else if (mPost.isModerator()) {
((PostDetailBaseViewHolder) holder).userTextView.setTextColor(mModeratorColor); ((PostDetailBaseViewHolder) holder).userTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor); Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((PostDetailBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds( ((PostDetailBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null); moderatorDrawable, null, null, null);
} else if (mPost.isAdmin()) {
((PostDetailBaseViewHolder) holder).userTextView.setTextColor(mAdminColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
((PostDetailBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null);
} }
if (mShowElapsedTime) { if (mShowElapsedTime) {

View File

@ -67,6 +67,7 @@ import javax.inject.Provider;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.DualBadgeDrawable;
import eu.toldi.infinityforlemmy.FetchRedgifsVideoLinks; import eu.toldi.infinityforlemmy.FetchRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo; import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface; import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
@ -198,6 +199,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private int mSubredditColor; private int mSubredditColor;
private int mUsernameColor; private int mUsernameColor;
private int mModeratorColor; private int mModeratorColor;
private int mAdminColor;
private int mSpoilerBackgroundColor; private int mSpoilerBackgroundColor;
private int mSpoilerTextColor; private int mSpoilerTextColor;
private int mFlairBackgroundColor; private int mFlairBackgroundColor;
@ -365,6 +367,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mSubredditColor = customThemeWrapper.getSubreddit(); mSubredditColor = customThemeWrapper.getSubreddit();
mUsernameColor = customThemeWrapper.getUsername(); mUsernameColor = customThemeWrapper.getUsername();
mModeratorColor = customThemeWrapper.getModerator(); mModeratorColor = customThemeWrapper.getModerator();
mAdminColor = customThemeWrapper.getAdmin();
mSpoilerBackgroundColor = customThemeWrapper.getSpoilerBackgroundColor(); mSpoilerBackgroundColor = customThemeWrapper.getSpoilerBackgroundColor();
mSpoilerTextColor = customThemeWrapper.getSpoilerTextColor(); mSpoilerTextColor = customThemeWrapper.getSpoilerTextColor();
mFlairBackgroundColor = customThemeWrapper.getFlairBackgroundColor(); mFlairBackgroundColor = customThemeWrapper.getFlairBackgroundColor();
@ -633,12 +636,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostBaseViewHolder) holder).communityInstanceTextView.setText('@' + post.getSubredditNamePrefixed().split(Pattern.quote("@"))[1]); ((PostBaseViewHolder) holder).communityInstanceTextView.setText('@' + post.getSubredditNamePrefixed().split(Pattern.quote("@"))[1]);
((PostBaseViewHolder) holder).userInstanceTextView.setText('@' + post.getAuthorNamePrefixed().split(Pattern.quote("@"))[1]); ((PostBaseViewHolder) holder).userInstanceTextView.setText('@' + post.getAuthorNamePrefixed().split(Pattern.quote("@"))[1]);
((PostBaseViewHolder) holder).communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mSubredditColor, 0.7f)); ((PostBaseViewHolder) holder).communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(mSubredditColor, 0.7f));
((PostBaseViewHolder) holder).userInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(post.isModerator() || post.isAdmin() ? mModeratorColor : mUsernameColor, 0.7f)); ((PostBaseViewHolder) holder).userInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(post.isModerator() ? mModeratorColor : post.isAdmin() ? mAdminColor : mUsernameColor, 0.7f));
} }
((PostBaseViewHolder) holder).userTextView.setTextColor( ((PostBaseViewHolder) holder).userTextView.setTextColor(
post.isModerator() || post.isAdmin() ? mModeratorColor : mUsernameColor); post.isModerator() || post.isAdmin() ? mModeratorColor : mUsernameColor);
if (post.isAdmin() && post.isModerator()) {
((PostBaseViewHolder) holder).userTextView.setTextColor(mModeratorColor);
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
Drawable dualBadge = new DualBadgeDrawable(adminDrawable, moderatorDrawable);
((PostBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
dualBadge, null, null, null);
} else if (post.isModerator()) {
((PostBaseViewHolder) holder).userTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((PostBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null);
} else if (post.isAdmin()) {
((PostBaseViewHolder) holder).userTextView.setTextColor(mAdminColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
((PostBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null);
}
if (mDisplaySubredditName) { if (mDisplaySubredditName) {
if (authorPrefixed.equals(post.getSubredditNamePrefixed())) { if (authorPrefixed.equals(post.getSubredditNamePrefixed())) {
if (post.getAuthorIconUrl() == null) { if (post.getAuthorIconUrl() == null) {
@ -2538,6 +2560,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} }
mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView); mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView);
((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); ((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor);
((PostBaseViewHolder) holder).userTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
if (holder instanceof PostBaseVideoAutoplayViewHolder) { if (holder instanceof PostBaseVideoAutoplayViewHolder) {
((PostBaseVideoAutoplayViewHolder) holder).mediaUri = null; ((PostBaseVideoAutoplayViewHolder) holder).mediaUri = null;
if (((PostBaseVideoAutoplayViewHolder) holder).fetchStreamableVideoCall != null && !((PostBaseVideoAutoplayViewHolder) holder).fetchStreamableVideoCall.isCanceled()) { if (((PostBaseVideoAutoplayViewHolder) holder).fetchStreamableVideoCall != null && !((PostBaseVideoAutoplayViewHolder) holder).fetchStreamableVideoCall.isCanceled()) {

View File

@ -44,7 +44,8 @@ public class Comment implements Parcelable {
private int upvotes; private int upvotes;
private int voteType; private int voteType;
private boolean isSubmitter; private boolean isSubmitter;
private String distinguished; private boolean isModerator;
private boolean isAdmin;
private String permalink; private String permalink;
private int depth; private int depth;
private int childCount; private int childCount;
@ -69,7 +70,7 @@ public class Comment implements Parcelable {
public Comment(int id, int postId, BasicUserInfo author, String linkAuthor, public Comment(int id, int postId, BasicUserInfo author, String linkAuthor,
long commentTimeMillis, String commentMarkdown, String commentRawText, long commentTimeMillis, String commentMarkdown, String commentRawText,
String linkId, String communityName, String communityQualifiedName, Integer parentId, int downvotes, int upvotes, String linkId, String communityName, String communityQualifiedName, Integer parentId, int downvotes, int upvotes,
int voteType, boolean isSubmitter, String distinguished, String permalink, int voteType, boolean isSubmitter, boolean isModerator, boolean isAdmin, String permalink,
int depth, boolean collapsed, boolean hasReply, boolean saved, boolean deleted,boolean removed, long edited, String[] path) { int depth, boolean collapsed, boolean hasReply, boolean saved, boolean deleted,boolean removed, long edited, String[] path) {
this.id = id; this.id = id;
this.postId = postId; this.postId = postId;
@ -86,7 +87,8 @@ public class Comment implements Parcelable {
this.upvotes = upvotes; this.upvotes = upvotes;
this.voteType = voteType; this.voteType = voteType;
this.isSubmitter = isSubmitter; this.isSubmitter = isSubmitter;
this.distinguished = distinguished; this.isModerator = isModerator;
this.isAdmin = isAdmin;
this.permalink = permalink; this.permalink = permalink;
this.depth = depth; this.depth = depth;
this.collapsed = collapsed; this.collapsed = collapsed;
@ -134,7 +136,8 @@ public class Comment implements Parcelable {
upvotes = in.readInt(); upvotes = in.readInt();
voteType = in.readInt(); voteType = in.readInt();
isSubmitter = in.readByte() != 0; isSubmitter = in.readByte() != 0;
distinguished = in.readString(); isModerator = in.readByte() != 0;
isAdmin = in.readByte() != 0;
permalink = in.readString(); permalink = in.readString();
depth = in.readInt(); depth = in.readInt();
childCount = in.readInt(); childCount = in.readInt();
@ -258,11 +261,11 @@ public class Comment implements Parcelable {
} }
public boolean isModerator() { public boolean isModerator() {
return distinguished != null && distinguished.equals("moderator"); return isModerator;
} }
public boolean isAdmin() { public boolean isAdmin() {
return distinguished != null && distinguished.equals("admin"); return isAdmin;
} }
public String getPermalink() { public String getPermalink() {
@ -447,7 +450,8 @@ public class Comment implements Parcelable {
parcel.writeInt(upvotes); parcel.writeInt(upvotes);
parcel.writeInt(voteType); parcel.writeInt(voteType);
parcel.writeByte((byte) (isSubmitter ? 1 : 0)); parcel.writeByte((byte) (isSubmitter ? 1 : 0));
parcel.writeString(distinguished); parcel.writeByte((byte) (isModerator ? 1 : 0));
parcel.writeByte((byte) (isAdmin ? 1 : 0));
parcel.writeString(permalink); parcel.writeString(permalink);
parcel.writeInt(depth); parcel.writeInt(depth);
parcel.writeInt(childCount); parcel.writeInt(childCount);
@ -506,8 +510,4 @@ public class Comment implements Parcelable {
public boolean isDeleted() { public boolean isDeleted() {
return isDeleted; return isDeleted;
} }
public String getDistinguished() {
return distinguished;
}
} }

View File

@ -345,7 +345,7 @@ public class ParseComment {
} }
} }
boolean isSubmitter = creatorObj.getInt("id") == postObj.getInt("creator_id"); boolean isSubmitter = creatorObj.getInt("id") == postObj.getInt("creator_id");
String distinguished = isModerator ? "moderator" : (isAdmin ? "admin" : "");
String permalink = commentObj.getString("ap_id"); String permalink = commentObj.getString("ap_id");
String[] path = commentObj.getString("path").split(Pattern.quote(".")); String[] path = commentObj.getString("path").split(Pattern.quote("."));
@ -362,7 +362,7 @@ public class ParseComment {
BasicUserInfo authorInfo = new BasicUserInfo(creatorObj.getInt("id"), author, authorQualifiedName, creatorObj.optString("avatar", ""), creatorObj.optString("display_name", author)); BasicUserInfo authorInfo = new BasicUserInfo(creatorObj.getInt("id"), author, authorQualifiedName, creatorObj.optString("avatar", ""), creatorObj.optString("display_name", author));
Comment comment = new Comment(id, postID, authorInfo, linkAuthor, commentTimeMillis, Comment comment = new Comment(id, postID, authorInfo, linkAuthor, commentTimeMillis,
commentMarkdown, commentRawText, linkId, communityName, communityQualifiedName, parentId, commentMarkdown, commentRawText, linkId, communityName, communityQualifiedName, parentId,
downvotes, upvotes, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, deleted,removed, edited, path); downvotes, upvotes, voteType, isSubmitter, isModerator, isAdmin, permalink, depth, collapsed, hasReply, saved, deleted, removed, edited, path);
int child_count = countsObj.getInt("child_count"); int child_count = countsObj.getInt("child_count");
comment.setChildCount(child_count); comment.setChildCount(child_count);
comment.setAuthorIconUrl(authorAvatar); comment.setAuthorIconUrl(authorAvatar);

View File

@ -348,7 +348,7 @@ public class CustomThemeWrapper {
} }
public int getAdmin() { public int getAdmin() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.MODERATOR, return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.ADMIN,
getDefaultColor("#a5222f", "#c94f6d", "#EE5396")); getDefaultColor("#a5222f", "#c94f6d", "#EE5396"));
} }

View File

@ -184,7 +184,7 @@ public class ParsePost {
boolean locked = post.getBoolean("locked"); boolean locked = post.getBoolean("locked");
boolean saved = data.getBoolean("saved"); boolean saved = data.getBoolean("saved");
boolean deleted = post.getBoolean("deleted"); boolean deleted = post.getBoolean("deleted");
String distinguished = (isModerator) ? "moderator" : (isAdmin) ? "admin" : "";
String suggestedSort = ""; String suggestedSort = "";
ArrayList<Post.Preview> previews = new ArrayList<>(); ArrayList<Post.Preview> previews = new ArrayList<>();
if (!post.isNull("thumbnail_url")) { if (!post.isNull("thumbnail_url")) {
@ -198,7 +198,7 @@ public class ParsePost {
return parseData(data, permalink, id, communityInfo, return parseData(data, permalink, id, communityInfo,
authorInfo, postTimeMillis, title, previews, authorInfo, postTimeMillis, title, previews,
downvotes, upvotes, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, downvotes, upvotes, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
} }
@ -207,7 +207,7 @@ public class ParsePost {
int downvotes, int upvotes, int voteType, int nComments, int upvoteRatio, int downvotes, int upvotes, int voteType, int nComments, int upvoteRatio,
boolean nsfw, boolean locked, boolean nsfw, boolean locked,
boolean saved, boolean deleted, boolean saved, boolean deleted,
String distinguished, String suggestedSort) throws JSONException { boolean isModerator, boolean isAdmin, String suggestedSort) throws JSONException {
Post post; Post post;
@ -226,7 +226,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, permalink, downvotes, upvotes, postTimeMillis, title, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, postType, voteType, nComments, upvoteRatio, nsfw,
locked, saved, deleted, distinguished, suggestedSort); locked, saved, deleted, isModerator, isAdmin, suggestedSort);
String body = data.getJSONObject("post").getString("body"); String body = data.getJSONObject("post").getString("body");
post.setSelfText(body); post.setSelfText(body);
post.setSelfTextPlain(body); post.setSelfTextPlain(body);
@ -238,7 +238,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
if (previews.isEmpty()) { if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0, "", "")); previews.add(new Post.Preview(url, 0, 0, "", ""));
@ -250,7 +250,7 @@ public class ParsePost {
int postType = Post.VIDEO_TYPE; int postType = Post.VIDEO_TYPE;
post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType, post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType,
nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
Post.Preview preview = new Post.Preview(url, 0, 0, "", ""); Post.Preview preview = new Post.Preview(url, 0, 0, "", "");
post.setPreviews(new ArrayList<>(List.of(preview))); post.setPreviews(new ArrayList<>(List.of(preview)));
post.setVideoUrl(url); post.setVideoUrl(url);
@ -260,7 +260,7 @@ public class ParsePost {
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -289,7 +289,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, permalink, downvotes, upvotes, postTimeMillis, title, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, postType, voteType, nComments, upvoteRatio, nsfw,
locked, saved, deleted, distinguished, suggestedSort); locked, saved, deleted, isModerator, isAdmin, suggestedSort);
String body = ""; String body = "";
post.setSelfText(body); post.setSelfText(body);
post.setSelfTextPlain(body); post.setSelfTextPlain(body);
@ -326,7 +326,7 @@ public class ParsePost {
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY); String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType, post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType,
nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
post.setPreviews(previews); post.setPreviews(previews);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
@ -339,7 +339,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
if (previews.isEmpty()) { if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0, "", "")); previews.add(new Post.Preview(url, 0, 0, "", ""));
@ -352,7 +352,7 @@ public class ParsePost {
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, postType, voteType, nComments, upvoteRatio,
nsfw, locked, saved, deleted, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
post.setPreviews(previews); post.setPreviews(previews);
post.setVideoUrl(url); post.setVideoUrl(url);
@ -368,7 +368,7 @@ public class ParsePost {
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, postType, voteType, nComments, upvoteRatio,
nsfw, locked, saved, deleted, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
post.setPreviews(previews); post.setPreviews(previews);
post.setVideoUrl(url); post.setVideoUrl(url);
post.setVideoDownloadUrl(url); post.setVideoDownloadUrl(url);
@ -380,7 +380,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
post.setPreviews(previews); post.setPreviews(previews);
post.setVideoUrl(url); post.setVideoUrl(url);
post.setVideoDownloadUrl(url); post.setVideoDownloadUrl(url);
@ -391,7 +391,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
distinguished, suggestedSort); isModerator, isAdmin, suggestedSort);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -425,7 +425,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
if (previews.isEmpty()) { if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0, "", "")); previews.add(new Post.Preview(url, 0, 0, "", ""));
@ -437,7 +437,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
post.setPreviews(previews); post.setPreviews(previews);
post.setVideoUrl(url); post.setVideoUrl(url);
post.setVideoDownloadUrl(url); post.setVideoDownloadUrl(url);
@ -447,7 +447,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author, post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes, postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort); postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, isModerator, isAdmin, suggestedSort);
//Need attention //Need attention
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");

View File

@ -73,8 +73,9 @@ public class Post implements Parcelable {
private boolean isRead; private boolean isRead;
private boolean deleted; private boolean deleted;
private boolean moderator;
private boolean admin;
private String crosspostParentId; private String crosspostParentId;
private String distinguished;
private String suggestedSort; private String suggestedSort;
private ArrayList<Preview> previews = new ArrayList<>(); private ArrayList<Preview> previews = new ArrayList<>();
private ArrayList<Gallery> gallery = new ArrayList<>(); private ArrayList<Gallery> gallery = new ArrayList<>();
@ -84,7 +85,7 @@ public class Post implements Parcelable {
String title, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments, String title, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments,
int upvoteRatio, int upvoteRatio,
boolean nsfw, boolean locked, boolean saved, boolean deleted, boolean nsfw, boolean locked, boolean saved, boolean deleted,
String distinguished, String suggestedSort) { boolean moderator, boolean admin, String suggestedSort) {
this.id = id; this.id = id;
this.communityInfo = communityInfo; this.communityInfo = communityInfo;
this.author = userInfo; this.author = userInfo;
@ -104,7 +105,8 @@ public class Post implements Parcelable {
this.locked = locked; this.locked = locked;
this.saved = saved; this.saved = saved;
this.isCrosspost = isCrosspost; this.isCrosspost = isCrosspost;
this.distinguished = distinguished; this.moderator = moderator;
this.admin = admin;
this.suggestedSort = suggestedSort; this.suggestedSort = suggestedSort;
isRead = false; isRead = false;
} }
@ -113,7 +115,7 @@ public class Post implements Parcelable {
BasicUserInfo author, long postTimeMillis, String title, BasicUserInfo author, long postTimeMillis, String title,
String url, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments, String url, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments,
int upvoteRatio, int upvoteRatio,
boolean nsfw, boolean locked, boolean saved, boolean deleted, String distinguished, String suggestedSort) { boolean nsfw, boolean locked, boolean saved, boolean deleted, boolean moderator, boolean admin, String suggestedSort) {
this.id = id; this.id = id;
this.communityInfo = communityInfo; this.communityInfo = communityInfo;
this.author = author; this.author = author;
@ -134,7 +136,8 @@ public class Post implements Parcelable {
this.saved = saved; this.saved = saved;
this.deleted = deleted; this.deleted = deleted;
this.isCrosspost = isCrosspost; this.isCrosspost = isCrosspost;
this.distinguished = distinguished; this.moderator = moderator;
this.admin = admin;
this.suggestedSort = suggestedSort; this.suggestedSort = suggestedSort;
isRead = false; isRead = false;
} }
@ -174,7 +177,8 @@ public class Post implements Parcelable {
isCrosspost = in.readByte() != 0; isCrosspost = in.readByte() != 0;
isRead = in.readByte() != 0; isRead = in.readByte() != 0;
crosspostParentId = in.readString(); crosspostParentId = in.readString();
distinguished = in.readString(); moderator = in.readByte() != 0;
admin = in.readByte() != 0;
suggestedSort = in.readString(); suggestedSort = in.readString();
in.readTypedList(previews, Preview.CREATOR); in.readTypedList(previews, Preview.CREATOR);
in.readTypedList(gallery, Gallery.CREATOR); in.readTypedList(gallery, Gallery.CREATOR);
@ -354,11 +358,11 @@ public class Post implements Parcelable {
} }
public boolean isModerator() { public boolean isModerator() {
return distinguished != null && distinguished.equals("moderator"); return moderator;
} }
public boolean isAdmin() { public boolean isAdmin() {
return distinguished != null && distinguished.equals("admin"); return admin;
} }
public String getSuggestedSort() { public String getSuggestedSort() {
@ -538,7 +542,8 @@ public class Post implements Parcelable {
parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0));
parcel.writeByte((byte) (isRead ? 1 : 0)); parcel.writeByte((byte) (isRead ? 1 : 0));
parcel.writeString(crosspostParentId); parcel.writeString(crosspostParentId);
parcel.writeString(distinguished); parcel.writeByte((byte) (moderator ? 1 : 0));
parcel.writeByte((byte) (admin ? 1 : 0));
parcel.writeString(suggestedSort); parcel.writeString(suggestedSort);
parcel.writeTypedList(previews); parcel.writeTypedList(previews);
parcel.writeTypedList(gallery); parcel.writeTypedList(gallery);

View File

@ -74,6 +74,7 @@ public class CustomThemeSharedPreferencesUtils {
public static final String AUTHOR_FLAIR_TEXT_COLOR = "authorFlairTextColor"; public static final String AUTHOR_FLAIR_TEXT_COLOR = "authorFlairTextColor";
public static final String SUBMITTER = "submitter"; public static final String SUBMITTER = "submitter";
public static final String MODERATOR = "moderator"; public static final String MODERATOR = "moderator";
public static final String ADMIN = "admin";
public static final String CURRENT_USER = "currentUser"; public static final String CURRENT_USER = "currentUser";
public static final String SINGLE_COMMENT_THREAD_BACKGROUND_COLOR = "singleCommentThreadBackgroundColor"; public static final String SINGLE_COMMENT_THREAD_BACKGROUND_COLOR = "singleCommentThreadBackgroundColor";
public static final String UNREAD_MESSAGE_BACKGROUND_COLOR = "unreadMessageBackgroundColor"; public static final String UNREAD_MESSAGE_BACKGROUND_COLOR = "unreadMessageBackgroundColor";