diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/DualBadgeDrawable.java b/app/src/main/java/eu/toldi/infinityforlemmy/DualBadgeDrawable.java new file mode 100644 index 00000000..2851f9b1 --- /dev/null +++ b/app/src/main/java/eu/toldi/infinityforlemmy/DualBadgeDrawable.java @@ -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); + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsRecyclerViewAdapter.java index f76deac1..b4931856 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsRecyclerViewAdapter.java @@ -43,6 +43,7 @@ import java.util.regex.Pattern; import butterknife.BindView; import butterknife.ButterKnife; +import eu.toldi.infinityforlemmy.DualBadgeDrawable; import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.RetrofitHolder; import eu.toldi.infinityforlemmy.SaveComment; @@ -155,6 +156,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter previews = new ArrayList<>(); if (!post.isNull("thumbnail_url")) { @@ -198,7 +198,7 @@ public class ParsePost { return parseData(data, permalink, id, communityInfo, authorInfo, postTimeMillis, title, previews, 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, boolean nsfw, boolean locked, boolean saved, boolean deleted, - String distinguished, String suggestedSort) throws JSONException { + boolean isModerator, boolean isAdmin, String suggestedSort) throws JSONException { Post post; @@ -226,7 +226,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, - locked, saved, deleted, distinguished, suggestedSort); + locked, saved, deleted, isModerator, isAdmin, suggestedSort); String body = data.getJSONObject("post").getString("body"); post.setSelfText(body); post.setSelfTextPlain(body); @@ -238,7 +238,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, 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()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -250,7 +250,7 @@ public class ParsePost { int postType = Post.VIDEO_TYPE; 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.setPreviews(new ArrayList<>(List.of(preview))); post.setVideoUrl(url); @@ -260,7 +260,7 @@ public class ParsePost { int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, communityInfo, author, 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)) { post.setSelfText(""); } else { @@ -289,7 +289,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, - locked, saved, deleted, distinguished, suggestedSort); + locked, saved, deleted, isModerator, isAdmin, suggestedSort); String body = ""; post.setSelfText(body); post.setSelfTextPlain(body); @@ -326,7 +326,7 @@ public class ParsePost { String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY); 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.setVideoUrl(videoUrl); @@ -339,7 +339,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, postTimeMillis, title, url, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, - distinguished, suggestedSort); + isModerator, isAdmin, suggestedSort); if (previews.isEmpty()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -352,7 +352,7 @@ public class ParsePost { postTimeMillis, title, url, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, - distinguished, suggestedSort); + isModerator, isAdmin, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); @@ -368,7 +368,7 @@ public class ParsePost { postTimeMillis, title, url, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, - distinguished, suggestedSort); + isModerator, isAdmin, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -380,7 +380,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, postTimeMillis, title, url, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, - distinguished, suggestedSort); + isModerator, isAdmin, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -391,7 +391,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, postTimeMillis, title, url, permalink, downvotes, upvotes, postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, - distinguished, suggestedSort); + isModerator, isAdmin, suggestedSort); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -425,7 +425,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, 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()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -437,7 +437,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, 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.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -447,7 +447,7 @@ public class ParsePost { post = new Post(id, communityInfo, author, 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 if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/post/Post.java b/app/src/main/java/eu/toldi/infinityforlemmy/post/Post.java index 5b82453c..cda5b81e 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/post/Post.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/post/Post.java @@ -73,8 +73,9 @@ public class Post implements Parcelable { private boolean isRead; private boolean deleted; + private boolean moderator; + private boolean admin; private String crosspostParentId; - private String distinguished; private String suggestedSort; private ArrayList previews = new ArrayList<>(); private ArrayList 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, int upvoteRatio, boolean nsfw, boolean locked, boolean saved, boolean deleted, - String distinguished, String suggestedSort) { + boolean moderator, boolean admin, String suggestedSort) { this.id = id; this.communityInfo = communityInfo; this.author = userInfo; @@ -104,7 +105,8 @@ public class Post implements Parcelable { this.locked = locked; this.saved = saved; this.isCrosspost = isCrosspost; - this.distinguished = distinguished; + this.moderator = moderator; + this.admin = admin; this.suggestedSort = suggestedSort; isRead = false; } @@ -113,7 +115,7 @@ public class Post implements Parcelable { BasicUserInfo author, long postTimeMillis, String title, String url, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments, 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.communityInfo = communityInfo; this.author = author; @@ -134,7 +136,8 @@ public class Post implements Parcelable { this.saved = saved; this.deleted = deleted; this.isCrosspost = isCrosspost; - this.distinguished = distinguished; + this.moderator = moderator; + this.admin = admin; this.suggestedSort = suggestedSort; isRead = false; } @@ -174,7 +177,8 @@ public class Post implements Parcelable { isCrosspost = in.readByte() != 0; isRead = in.readByte() != 0; crosspostParentId = in.readString(); - distinguished = in.readString(); + moderator = in.readByte() != 0; + admin = in.readByte() != 0; suggestedSort = in.readString(); in.readTypedList(previews, Preview.CREATOR); in.readTypedList(gallery, Gallery.CREATOR); @@ -354,11 +358,11 @@ public class Post implements Parcelable { } public boolean isModerator() { - return distinguished != null && distinguished.equals("moderator"); + return moderator; } public boolean isAdmin() { - return distinguished != null && distinguished.equals("admin"); + return admin; } public String getSuggestedSort() { @@ -538,7 +542,8 @@ public class Post implements Parcelable { parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isRead ? 1 : 0)); parcel.writeString(crosspostParentId); - parcel.writeString(distinguished); + parcel.writeByte((byte) (moderator ? 1 : 0)); + parcel.writeByte((byte) (admin ? 1 : 0)); parcel.writeString(suggestedSort); parcel.writeTypedList(previews); parcel.writeTypedList(gallery); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/utils/CustomThemeSharedPreferencesUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/utils/CustomThemeSharedPreferencesUtils.java index 1389d4ac..51c28ab4 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/utils/CustomThemeSharedPreferencesUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/utils/CustomThemeSharedPreferencesUtils.java @@ -74,6 +74,7 @@ public class CustomThemeSharedPreferencesUtils { public static final String AUTHOR_FLAIR_TEXT_COLOR = "authorFlairTextColor"; public static final String SUBMITTER = "submitter"; public static final String MODERATOR = "moderator"; + public static final String ADMIN = "admin"; public static final String CURRENT_USER = "currentUser"; public static final String SINGLE_COMMENT_THREAD_BACKGROUND_COLOR = "singleCommentThreadBackgroundColor"; public static final String UNREAD_MESSAGE_BACKGROUND_COLOR = "unreadMessageBackgroundColor";