Added option to show displayname and hide the instance for comment author names

This commit is contained in:
Balazs Toldi 2023-08-22 22:10:39 +02:00
parent 4010e02438
commit f14ebe9a0d
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
11 changed files with 62 additions and 44 deletions

View File

@ -450,7 +450,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
Comment comment = getItem(getBindingAdapterPosition());
if (comment != null) {
Bundle bundle = new Bundle();
if (comment.getAuthor().equals(mAccountName)) {
if (comment.getAuthorName().equals(mAccountName)) {
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_EDIT_AND_DELETE_AVAILABLE, true);
}
bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);

View File

@ -39,10 +39,12 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SaveComment;
import eu.toldi.infinityforlemmy.SaveThing;
import eu.toldi.infinityforlemmy.SortType;
@ -95,7 +97,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private BaseActivity mActivity;
private ViewPostDetailFragment mFragment;
private Executor mExecutor;
private Retrofit mRetrofit;
private RetrofitHolder mRetrofit;
private Retrofit mOauthRetrofit;
private Markwon mCommentMarkwon;
private String mAccessToken;
@ -134,6 +136,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private boolean isInitiallyLoadingFailed;
private boolean mHasMoreComments;
private boolean loadMoreCommentsFailed;
private boolean mHideUserInstance;
private boolean mShowUserDisplayName;
private Drawable expandDrawable;
private Drawable collapseDrawable;
@ -165,7 +170,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public CommentsRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment,
CustomThemeWrapper customThemeWrapper,
Executor executor, Retrofit retrofit,
Executor executor, RetrofitHolder retrofit,
String accessToken, String accountName,
Post post, Locale locale, Integer singleCommentId,
boolean isSingleCommentThreadMode,
@ -242,6 +247,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mShowAuthorAvatar = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AUTHOR_AVATAR, false);
mAlwaysShowChildCommentCount = sharedPreferences.getBoolean(SharedPreferencesUtils.ALWAYS_SHOW_CHILD_COMMENT_COUNT, false);
mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES_IN_COMMENTS, false);
mHideUserInstance = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_HIDE_USER_INSTANCE, false);
mShowUserDisplayName = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_DISPLAY_NAME_INSTEAD_OF_USERNAME, true);
mHideDownvotes = !currentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true);
mSeperateUpandDownvote = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_SEPARATE_UP_AND_DOWN_VOTES, true) && !mHideDownvotes;
mDepthThreshold = sharedPreferences.getInt(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD, 5);
@ -375,9 +382,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (mIsSingleCommentThreadMode && comment.getId() == mSingleCommentId) {
holder.itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor);
}
String authorPrefixed = comment.getAuthorQualifiedName();
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
String authorDisplayName = (mShowUserDisplayName) ? comment.getAuthorName() : comment.getAuthor().getUsername();
String authorInstance = (mHideUserInstance) ? "" : "@" + comment.getAuthor().getQualifiedName().split(Pattern.quote("@"))[1];
((CommentViewHolder) holder).authorTextView.setText(authorDisplayName + authorInstance);
if (comment.isSubmitter()) {
@ -565,7 +572,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
Comment comment = getCurrentComment(position);
if (comment != null) {
String authorWithPrefix = "u/" + comment.getAuthor();
String authorWithPrefix = "u/" + comment.getAuthorName();
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
if (comment.getAuthorIconUrl() == null) {
@ -648,7 +655,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.get(commentPosition).setLoadMoreChildrenFailed(false);
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
Retrofit retrofit = mRetrofit;
Retrofit retrofit = mRetrofit.getRetrofit();
SortType.Type sortType = mCommentRecyclerViewAdapterCallback.getSortType();
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken,
mPost.getId(), parentComment.getId(), sortType,
@ -1479,7 +1486,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
comment.getScore() + comment.getVoteType())));
}
VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, mRetrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
int currentPosition = getBindingAdapterPosition();
@ -1586,7 +1593,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
int position = getBindingAdapterPosition();
VoteThing.voteComment(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, mRetrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -1594,9 +1601,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
if (currentPosition == position) {
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpandDownvote){
if (mSeperateUpandDownvote) {
downvoteTextView.setTextColor(mDownvotedColor);
}else {
} else {
scoreTextView.setTextColor(mDownvotedColor);
}
topScoreTextView.setTextColor(mDownvotedColor);
@ -1646,7 +1653,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
SaveComment saveComment = new SaveComment();
if (comment.isSaved()) {
comment.setSaved(false);
saveComment.unsaveThing(mRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
saveComment.unsaveThing(mRetrofit.getRetrofit(), mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
@Override
public void success() {
comment.setSaved(false);
@ -1667,7 +1674,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
});
} else {
comment.setSaved(true);
saveComment.saveThing(mRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
saveComment.saveThing(mRetrofit.getRetrofit(), mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
@Override
public void success() {
comment.setSaved(true);
@ -1696,7 +1703,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return;
}
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthorName());
intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, comment.getAuthorQualifiedName());
mActivity.startActivity(intent);
});

View File

@ -217,7 +217,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<CommentInteract
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
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);
});

View File

@ -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<String> 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;
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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";

View File

@ -1382,4 +1382,5 @@
<string name="settings_show_post_and_comment_score">Show post and comment scores</string>
<string name="moderators">Moderators</string>
<string name="admins">Admins</string>
<string name="settings_hide_user_instance">Hide user instance</string>
</resources>

View File

@ -61,6 +61,16 @@
app:key="comment_separate_down_and_up_votes"
app:title="@string/separate_down_and_up_votes" />
<eu.toldi.infinityforlemmy.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="comment_hide_user_instance"
app:title="@string/settings_hide_user_instance" />
<eu.toldi.infinityforlemmy.customviews.CustomFontSwitchPreference
app:defaultValue="true"
app:key="comment_display_name_instead_of_user_name"
app:title="@string/settings_show_display_name_instead_of_user_name" />
<eu.toldi.infinityforlemmy.customviews.CustomFontSeekBarPreference
app:defaultValue="5"
android:max="10"