Fix see removed comment edit wrong comment (#1192)

* Fix removed comment shown in the wrong position.

* Handle index out of bounds.
This commit is contained in:
Blahaj-Samoyed 2022-11-02 22:46:18 +11:00 committed by GitHub
parent fe9e0bd5d7
commit 9b4ee0018e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 14 deletions

View File

@ -963,15 +963,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
editComment(commentAuthor, mVisibleComments.get(position).isSubmitter(), commentContentMarkdown, position);
}
public void editComment(String commentAuthor, boolean isSubmitter, String commentContentMarkdown, int position) {
if (commentAuthor != null) {
mVisibleComments.get(position).setAuthor(commentAuthor);
}
mVisibleComments.get(position).setSubmittedByAuthor(isSubmitter);
mVisibleComments.get(position).setSubmittedByAuthor(mVisibleComments.get(position).isSubmitter());
mVisibleComments.get(position).setCommentMarkdown(commentContentMarkdown);
if (mIsSingleCommentThreadMode) {
@ -981,6 +977,24 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
public void editComment(Comment fetchedComment, Comment originalComment, int position) {
if (position >= mVisibleComments.size() || !mVisibleComments.get(position).equals(originalComment)) {
position = mVisibleComments.indexOf(originalComment);
if (position < 0) {
Toast.makeText(mActivity, R.string.show_removed_comment_failed, Toast.LENGTH_SHORT).show();
return;
}
}
mVisibleComments.get(position).setSubmittedByAuthor(originalComment.isSubmitter());
mVisibleComments.get(position).setCommentMarkdown(fetchedComment.getCommentMarkdown());
if (mIsSingleCommentThreadMode) {
notifyItemChanged(position + 1);
} else {
notifyItemChanged(position);
}
}
public void deleteComment(int position) {
if (mVisibleComments != null && position >= 0 && position < mVisibleComments.size()) {
if (mVisibleComments.get(position).hasReply()) {

View File

@ -29,7 +29,7 @@ public class FetchRemovedComment {
Comment removedComment = parseComment(response.body(), comment);
handler.post(() -> {
if (removedComment != null) {
listener.fetchSuccess(removedComment);
listener.fetchSuccess(removedComment, comment);
} else {
listener.fetchFailed();
}
@ -64,7 +64,7 @@ public class FetchRemovedComment {
Comment removedComment = parseComment(response.body(), comment);
handler.post(() -> {
if (removedComment != null) {
listener.fetchSuccess(removedComment);
listener.fetchSuccess(removedComment, comment);
} else {
listener.fetchFailed();
}
@ -124,7 +124,7 @@ public class FetchRemovedComment {
}
public interface FetchRemovedCommentListener {
void fetchSuccess(Comment comment);
void fetchSuccess(Comment fetchedComment, Comment originalComment);
void fetchFailed();
}

View File

@ -36,7 +36,7 @@ public class FetchRemovedCommentReveddit {
Comment removedComment = parseRemovedComment(new JSONObject(response.body()).getJSONObject(comment.getId()), comment);
handler.post(() -> {
if (removedComment != null) {
listener.fetchSuccess(removedComment);
listener.fetchSuccess(removedComment, comment);
} else {
listener.fetchFailed();
}
@ -69,7 +69,7 @@ public class FetchRemovedCommentReveddit {
}
public interface FetchRemovedCommentListener {
void fetchSuccess(Comment comment);
void fetchSuccess(Comment fetchedComment, Comment originalComment);
void fetchFailed();
}

View File

@ -1811,8 +1811,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mExecutor, new Handler(), pushshiftRetrofit, comment,
new FetchRemovedComment.FetchRemovedCommentListener() {
@Override
public void fetchSuccess(Comment comment) {
mCommentsAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
public void fetchSuccess(Comment fetchedComment, Comment originalComment) {
mCommentsAdapter.editComment(fetchedComment, originalComment, position);
}
@Override
@ -1822,8 +1822,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
comment, mPost.getPostTimeMillis(), mPost.getNComments(),
new FetchRemovedCommentReveddit.FetchRemovedCommentListener() {
@Override
public void fetchSuccess(Comment comment) {
mCommentsAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
public void fetchSuccess(Comment fetchedComment, Comment originalComment) {
mCommentsAdapter.editComment(fetchedComment, originalComment, position);
}
@Override