Highlight pinned posts

This commits adds a pin icon to featured posts on communities or on the instance.
This commit is contained in:
Balazs Toldi 2023-08-10 21:44:36 +02:00
parent 7a39b2341b
commit 82414bba55
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
5 changed files with 40 additions and 17 deletions

View File

@ -641,9 +641,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
break;
}
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isFeaturedInCommunity() || post.isFeaturedOnInstance()) {
((PostBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostBaseViewHolder) holder).stickiedPostImageView);
if (post.isFeaturedOnInstance()) {
((PostBaseViewHolder) holder).stickiedPostImageView.setColorFilter(mModeratorColor, android.graphics.PorterDuff.Mode.SRC_IN);
}
}
if (post.isArchived()) {
@ -1210,7 +1213,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
}
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isFeaturedInCommunity()) {
((PostCompactBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostCompactBaseViewHolder) holder).stickiedPostImageView);
}

View File

@ -99,7 +99,6 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import eu.toldi.infinityforlemmy.videoautoplay.CacheManager;
@ -586,7 +585,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthor());
}
if (mPost.isModerator()) {
if (mPost.isModerator() || mPost.isAdmin()) {
((PostDetailBaseViewHolder) holder).mUserTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((PostDetailBaseViewHolder) holder).mUserTextView.setCompoundDrawablesWithIntrinsicBounds(

View File

@ -541,7 +541,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
((PostBaseViewHolder) holder).userTextView.setTextColor(
post.isModerator() ? mModeratorColor : mUsernameColor);
post.isModerator() || post.isAdmin() ? mModeratorColor : mUsernameColor);
if (mDisplaySubredditName) {
if (authorPrefixed.equals(post.getSubredditNamePrefixed())) {
@ -700,9 +700,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostBaseViewHolder) holder).downvoteTextView.setTextColor(mPostIconAndInfoColor);
}
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isFeaturedInCommunity() || post.isFeaturedOnInstance()) {
((PostBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostBaseViewHolder) holder).stickiedPostImageView);
if (post.isFeaturedOnInstance()) {
((PostBaseViewHolder) holder).stickiedPostImageView.setColorFilter(mModeratorColor, android.graphics.PorterDuff.Mode.SRC_IN);
}
}
if (post.isArchived()) {
@ -1239,7 +1242,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
((PostCompactBaseViewHolder) holder).nameTextView.setTextColor(
post.isModerator() ? mModeratorColor : mUsernameColor);
post.isModerator() || post.isAdmin() ? mModeratorColor : mUsernameColor);
if (mHideSubredditAndUserPrefix) {
((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getAuthor());
@ -1333,7 +1336,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isFeaturedInCommunity()) {
((PostCompactBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostCompactBaseViewHolder) holder).stickiedPostImageView);
}

View File

@ -186,7 +186,7 @@ public class ParsePost {
boolean nsfw = post.getBoolean("nsfw");
boolean locked = post.getBoolean("locked");
boolean saved = data.getBoolean("saved");
String distinguished = "";
String distinguished = (creator.getBoolean("admin") ? "admin" : "");
String suggestedSort = "";
ArrayList <Post.Preview> previews = new ArrayList<>();
if(!post.isNull("thumbnail_url")) {
@ -659,7 +659,7 @@ public class ParsePost {
post.setVoteType(data.getInt("my_vote"));
if(post.getVoteType() == 1)
post.setUpvotes(post.getUpvotes() - 1);
else if(post.getVoteType() == -1)
else if (post.getVoteType() == -1)
post.setDownvotes(post.getDownvotes() - 1);
}
if (!data.getJSONObject("post").isNull("body")) {
@ -668,7 +668,13 @@ public class ParsePost {
post.setSelfTextPlain(body);
post.setSelfTextPlainTrimmed(body.trim());
}
if (data.getJSONObject("post").getBoolean("featured_community")) {
post.setFeaturedInCommunity(true);
}
if (data.getJSONObject("post").getBoolean("featured_local")) {
post.setFeaturedOnInstance(true);
}
post.setAuthorIconUrl(authorAvatar);
post.setSubredditIconUrl(communityURL);
return post;

View File

@ -66,7 +66,9 @@ public class Post implements Parcelable {
private int upvoteRatio;
private boolean hidden;
private boolean nsfw;
private boolean stickied;
private boolean featuredInCommunity;
private boolean featuredOnInstance;
private boolean archived;
private boolean locked;
private boolean saved;
@ -101,7 +103,6 @@ public class Post implements Parcelable {
this.upvoteRatio = upvoteRatio;
this.hidden = hidden;
this.nsfw = nsfw;
this.stickied = stickied;
this.archived = archived;
this.locked = locked;
this.saved = saved;
@ -134,7 +135,6 @@ public class Post implements Parcelable {
this.upvoteRatio = upvoteRatio;
this.hidden = hidden;
this.nsfw = nsfw;
this.stickied = stickied;
this.archived = archived;
this.locked = locked;
this.saved = saved;
@ -177,7 +177,7 @@ public class Post implements Parcelable {
upvoteRatio = in.readInt();
hidden = in.readByte() != 0;
nsfw = in.readByte() != 0;
stickied = in.readByte() != 0;
featuredInCommunity = in.readByte() != 0;
archived = in.readByte() != 0;
locked = in.readByte() != 0;
saved = in.readByte() != 0;
@ -444,8 +444,20 @@ public class Post implements Parcelable {
return 0;
}
public boolean isStickied() {
return stickied;
public boolean isFeaturedInCommunity() {
return featuredInCommunity;
}
public void setFeaturedInCommunity(boolean featuredInCommunity) {
this.featuredInCommunity = featuredInCommunity;
}
public boolean isFeaturedOnInstance() {
return featuredOnInstance;
}
public void setFeaturedOnInstance(boolean featuredOnInstance) {
this.featuredOnInstance = featuredOnInstance;
}
public boolean isArchived() {
@ -534,7 +546,7 @@ public class Post implements Parcelable {
parcel.writeInt(upvoteRatio);
parcel.writeByte((byte) (hidden ? 1 : 0));
parcel.writeByte((byte) (nsfw ? 1 : 0));
parcel.writeByte((byte) (stickied ? 1 : 0));
parcel.writeByte((byte) (featuredInCommunity ? 1 : 0));
parcel.writeByte((byte) (archived ? 1 : 0));
parcel.writeByte((byte) (locked ? 1 : 0));
parcel.writeByte((byte) (saved ? 1 : 0));