From f14ebe9a0d24af3e9ae597f4a80d0a352b0f6082 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Tue, 22 Aug 2023 22:10:39 +0200 Subject: [PATCH] Added option to show displayname and hide the instance for comment author names --- .../CommentsListingRecyclerViewAdapter.java | 2 +- .../adapters/CommentsRecyclerViewAdapter.java | 35 ++++++++++------- .../adapters/MessageRecyclerViewAdapter.java | 2 +- .../infinityforlemmy/comment/Comment.java | 38 +++++++++---------- .../comment/FetchRemovedComment.java | 2 +- .../comment/FetchRemovedCommentReveddit.java | 2 +- .../comment/ParseComment.java | 7 ++-- .../fragments/ViewPostDetailFragment.java | 4 +- .../utils/SharedPreferencesUtils.java | 3 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/comment_preferences.xml | 10 +++++ 11 files changed, 62 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java index d3b1d996..0dd8492e 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java @@ -450,7 +450,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getComment().getAuthor()); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getComment().getAuthorName()); intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, message.getComment().getAuthorQualifiedName()); mActivity.startActivity(intent); }); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/comment/Comment.java b/app/src/main/java/eu/toldi/infinityforlemmy/comment/Comment.java index 48c9dbbe..a67241ed 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/comment/Comment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/comment/Comment.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.List; import eu.toldi.infinityforlemmy.BuildConfig; +import eu.toldi.infinityforlemmy.user.BasicUserInfo; public class Comment implements Parcelable { public static final int VOTE_TYPE_NO_VOTE = 0; @@ -29,9 +30,7 @@ public class Comment implements Parcelable { }; private int id; private String fullName; - private String author; - private String authorQualifiedName; - private String authorIconUrl; + private BasicUserInfo author; private String linkAuthor; private long commentTimeMillis; private String commentMarkdown; @@ -66,16 +65,14 @@ public class Comment implements Parcelable { private List path; private int postId; - public Comment(int id, int postId, String fullName, String author, String authorQualifiedName, String linkAuthor, + public Comment(int id, int postId, BasicUserInfo author, String linkAuthor, 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 depth, boolean collapsed, boolean hasReply, boolean saved, boolean deleted, long edited, String[] path) { this.id = id; this.postId = postId; - this.fullName = fullName; this.author = author; - this.authorQualifiedName = authorQualifiedName; this.linkAuthor = linkAuthor; this.commentTimeMillis = commentTimeMillis; this.commentMarkdown = commentMarkdown; @@ -122,10 +119,7 @@ public class Comment implements Parcelable { protected Comment(Parcel in) { id = in.readInt(); postId = in.readInt(); - fullName = in.readString(); - author = in.readString(); - authorQualifiedName = in.readString(); - authorIconUrl = in.readString(); + author = in.readParcelable(BasicUserInfo.class.getClassLoader()); linkAuthor = in.readString(); commentTimeMillis = in.readLong(); commentMarkdown = in.readString(); @@ -169,8 +163,8 @@ public class Comment implements Parcelable { return fullName; } - public String getAuthor() { - return author; + public String getAuthorName() { + return author.getDisplayName(); } public boolean isAuthorDeleted() { @@ -178,16 +172,17 @@ public class Comment implements Parcelable { } public void setAuthor(String author) { - this.author = author; + //this.author = author; } public String getAuthorIconUrl() { - return authorIconUrl; + return author.getAvatar(); } public void setAuthorIconUrl(String authorIconUrl) { - this.authorIconUrl = authorIconUrl; + + //this.authorIconUrl = authorIconUrl; } public String getLinkAuthor() { @@ -435,10 +430,7 @@ public class Comment implements Parcelable { public void writeToParcel(Parcel parcel, int i) { parcel.writeInt(id); parcel.writeInt(postId); - parcel.writeString(fullName); - parcel.writeString(author); - parcel.writeString(authorQualifiedName); - parcel.writeString(authorIconUrl); + parcel.writeParcelable(author, i); parcel.writeString(linkAuthor); parcel.writeLong(commentTimeMillis); parcel.writeString(commentMarkdown); @@ -486,7 +478,7 @@ public class Comment implements Parcelable { } public String getAuthorQualifiedName() { - return authorQualifiedName; + return author.getQualifiedName(); } public String getCommunityQualifiedName() { @@ -496,4 +488,8 @@ public class Comment implements Parcelable { public int getPostId() { return postId; } + + public BasicUserInfo getAuthor() { + return author; + } } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedComment.java b/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedComment.java index 50b4723b..cadf89de 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedComment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedComment.java @@ -110,7 +110,7 @@ public class FetchRemovedComment { boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY); if (id.equals(comment.getId()) && - (!author.equals(comment.getAuthor()) || + (!author.equals(comment.getAuthorName()) || !body.equals(comment.getCommentRawText())) ) { comment.setAuthor(author); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedCommentReveddit.java b/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedCommentReveddit.java index 7d1c6ba6..8387863b 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedCommentReveddit.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/comment/FetchRemovedCommentReveddit.java @@ -56,7 +56,7 @@ public class FetchRemovedCommentReveddit { String author = result.getString(JSONUtils.AUTHOR_KEY); String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.optString(JSONUtils.BODY_KEY))); - if (id.equals(comment.getId()) && (!author.equals(comment.getAuthor()) || !body.equals(comment.getCommentRawText()))) { + if (id.equals(comment.getId()) && (!author.equals(comment.getAuthorName()) || !body.equals(comment.getCommentRawText()))) { comment.setAuthor(author); comment.setCommentMarkdown(body); comment.setCommentRawText(body); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/comment/ParseComment.java b/app/src/main/java/eu/toldi/infinityforlemmy/comment/ParseComment.java index 878b643b..bc913de1 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/comment/ParseComment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/comment/ParseComment.java @@ -24,6 +24,7 @@ import java.util.TimeZone; import java.util.concurrent.Executor; import java.util.regex.Pattern; +import eu.toldi.infinityforlemmy.user.BasicUserInfo; import eu.toldi.infinityforlemmy.utils.JSONUtils; import eu.toldi.infinityforlemmy.utils.LemmyUtils; @@ -340,10 +341,10 @@ public class ParseComment { boolean saved = jsonObject.getBoolean("saved"); boolean deleted = commentObj.getBoolean("deleted"); long edited = 0; - - Comment comment = new Comment(id, postID, fullName, author, authorQualifiedName, linkAuthor, commentTimeMillis, + 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, commentMarkdown, commentRawText, linkId, communityName, communityQualifiedName, parentId, - downvotes,upvotes, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, deleted, edited, path); + downvotes, upvotes, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, deleted, edited, path); int child_count = countsObj.getInt("child_count"); comment.setChildCount(child_count); comment.setAuthorIconUrl(authorAvatar); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java index ad517519..86f73810 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/ViewPostDetailFragment.java @@ -620,7 +620,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, - this, mCustomThemeWrapper, mExecutor, mRetrofit.getRetrofit(), + this, mCustomThemeWrapper, mExecutor, mRetrofit, mAccessToken, mAccountQualifiedName, mPost, mLocale, mSingleCommentId , isSingleCommentThreadMode, mSharedPreferences, mCurrentAccountSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @@ -1351,7 +1351,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic pages_loaded++; mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, ViewPostDetailFragment.this, mCustomThemeWrapper, mExecutor, - mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, mPost, mLocale, + mRetrofit, mAccessToken, mAccountQualifiedName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mCurrentAccountSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java index c7ae08a6..7a729a42 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java @@ -56,6 +56,9 @@ public class SharedPreferencesUtils { public static final String POST_DISPLAY_NAME_INSTEAD_OF_USERNAME = "post_display_name_instead_of_user_name"; + public static final String COMMENT_DISPLAY_NAME_INSTEAD_OF_USERNAME = "comment_display_name_instead_of_user_name"; + public static final String COMMENT_HIDE_USER_INSTANCE = "comment_hide_user_instance"; + public static final String POST_DETAIL_DISPLAY_NAME_INSTEAD_OF_USERNAME = "post_detail_display_name_instead_of_user_name"; public static final String SORT_TYPE_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.sort_type"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 790e93d3..5deeb4d3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1382,4 +1382,5 @@ Show post and comment scores Moderators Admins + Hide user instance diff --git a/app/src/main/res/xml/comment_preferences.xml b/app/src/main/res/xml/comment_preferences.xml index c5efa19c..d4ffceab 100644 --- a/app/src/main/res/xml/comment_preferences.xml +++ b/app/src/main/res/xml/comment_preferences.xml @@ -61,6 +61,16 @@ app:key="comment_separate_down_and_up_votes" app:title="@string/separate_down_and_up_votes" /> + + + +