Show if comments are edited (#1388)

This commit is contained in:
Thomas 2023-04-24 16:14:27 +02:00 committed by GitHub
parent abb9acb4d8
commit 44a553efac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 2 deletions

View File

@ -460,6 +460,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); ((CommentViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
} }
if(comment.isEdited()){
((CommentViewHolder) holder).editedView.setText(R.string.edited);
((CommentViewHolder) holder).editedView.setOnClickListener(view -> {
Toast.makeText(view.getContext(), view.getContext().getString(R.string.edited_time, mShowElapsedTime ?
Utils.getElapsedTime(mActivity, comment.getEditedTimeMillis()) :
Utils.getFormattedTime(mLocale, comment.getEditedTimeMillis(), mTimeFormatPattern)
), Toast.LENGTH_SHORT).show();
});
}
((CommentViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator); ((CommentViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors); ((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
if (comment.getDepth() >= mDepthThreshold) { if (comment.getDepth() >= mDepthThreshold) {
@ -1181,6 +1191,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
TextView awardsTextView; TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment) @BindView(R.id.comment_markdown_view_item_post_comment)
RecyclerView commentMarkdownView; RecyclerView commentMarkdownView;
@BindView(R.id.edited_text_view_item_post_comment)
TextView editedView;
@BindView(R.id.bottom_constraint_layout_item_post_comment) @BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout; ConstraintLayout bottomConstraintLayout;
@BindView(R.id.up_vote_button_item_post_comment) @BindView(R.id.up_vote_button_item_post_comment)

View File

@ -58,6 +58,7 @@ public class Comment implements Parcelable {
private int placeholderType; private int placeholderType;
private boolean isLoadingMoreChildren; private boolean isLoadingMoreChildren;
private boolean loadMoreChildrenFailed; private boolean loadMoreChildrenFailed;
private long editedTimeMillis;
public Comment(String id, String fullName, String author, String authorFlair, public Comment(String id, String fullName, String author, String authorFlair,
String authorFlairHTML, String linkAuthor, String authorFlairHTML, String linkAuthor,
@ -65,7 +66,7 @@ public class Comment implements Parcelable {
String linkId, String subredditName, String parentId, int score, String linkId, String subredditName, String parentId, int score,
int voteType, boolean isSubmitter, String distinguished, String permalink, int voteType, boolean isSubmitter, String distinguished, String permalink,
String awards, int depth, boolean collapsed, boolean hasReply, String awards, int depth, boolean collapsed, boolean hasReply,
boolean scoreHidden, boolean saved) { boolean scoreHidden, boolean saved, long edited) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.author = author; this.author = author;
@ -91,6 +92,7 @@ public class Comment implements Parcelable {
this.saved = saved; this.saved = saved;
this.isExpanded = false; this.isExpanded = false;
this.hasExpandedBefore = false; this.hasExpandedBefore = false;
this.editedTimeMillis = edited;
placeholderType = NOT_PLACEHOLDER; placeholderType = NOT_PLACEHOLDER;
} }
@ -435,4 +437,11 @@ public class Comment implements Parcelable {
parcel.writeByte((byte) (isLoadingMoreChildren ? 1 : 0)); parcel.writeByte((byte) (isLoadingMoreChildren ? 1 : 0));
parcel.writeByte((byte) (loadMoreChildrenFailed ? 1 : 0)); parcel.writeByte((byte) (loadMoreChildrenFailed ? 1 : 0));
} }
public boolean isEdited() {
return editedTimeMillis != 0;
}
public long getEditedTimeMillis() {
return editedTimeMillis;
}
} }

View File

@ -305,10 +305,13 @@ public class ParseComment {
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY); boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
// this key can either be a bool (false) or a long (edited timestamp)
long edited = singleCommentData.optLong(JSONUtils.EDITED_KEY) * 1000;
return new Comment(id, fullName, author, authorFlair, authorFlairHTMLBuilder.toString(), return new Comment(id, fullName, author, authorFlair, authorFlairHTMLBuilder.toString(),
linkAuthor, submitTime, commentMarkdown, commentRawText, linkAuthor, submitTime, commentMarkdown, commentRawText,
linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished, linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished,
permalink, awardingsBuilder.toString(), depth, collapsed, hasReply, scoreHidden, saved); permalink, awardingsBuilder.toString(), depth, collapsed, hasReply, scoreHidden, saved, edited);
} }
@Nullable @Nullable

View File

@ -92,6 +92,7 @@ public class JSONUtils {
public static final String TEXT_EDITABLE_KEY = "text_editable"; public static final String TEXT_EDITABLE_KEY = "text_editable";
public static final String SUBJECT_KEY = "subject"; public static final String SUBJECT_KEY = "subject";
public static final String CONTEXT_KEY = "context"; public static final String CONTEXT_KEY = "context";
public static final String EDITED_KEY = "edited";
public static final String DISTINGUISHED_KEY = "distinguished"; public static final String DISTINGUISHED_KEY = "distinguished";
public static final String WAS_COMMENT_KEY = "was_comment"; public static final String WAS_COMMENT_KEY = "was_comment";
public static final String NEW_KEY = "new"; public static final String NEW_KEY = "new";

View File

@ -68,6 +68,18 @@
app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment"
tools:visibility="visible" /> tools:visibility="visible" />
<TextView
android:id="@+id/edited_text_view_item_post_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:fontFamily="?attr/font_family"
android:gravity="end"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/top_score_text_view_item_post_comment"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/top_score_text_view_item_post_comment" android:id="@+id/top_score_text_view_item_post_comment"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -1084,6 +1084,9 @@
<string name="give_award_success">Award given</string> <string name="give_award_success">Award given</string>
<string name="give_award_failed">Failed</string> <string name="give_award_failed">Failed</string>
<string name="edited">Edited</string>
<string name="edited_time">Edited on %s</string>
<string name="warning">Warning</string> <string name="warning">Warning</string>
<string name="this_is_a_nsfw_subreddit">This is a NSFW subreddit.</string> <string name="this_is_a_nsfw_subreddit">This is a NSFW subreddit.</string>
<string name="this_user_has_nsfw_content">This user has NSFW content</string> <string name="this_user_has_nsfw_content">This user has NSFW content</string>