diff options
author | Blahaj-Samoyed <115386715+Blahaj-Samoyed@users.noreply.github.com> | 2022-11-02 11:46:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 11:46:18 +0000 |
commit | 9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473 (patch) | |
tree | 6b99dd0e6317181910e15a6d18a604569577c093 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | fe9e0bd5d7ce8f6d544cf32755ba7aa14cae3299 (diff) | |
download | infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar.gz infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar.bz2 infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar.lz infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar.xz infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.tar.zst infinity-for-reddit-9b4ee0018e0e6cf06f9a8ed1dacef216b0ecd473.zip |
Fix see removed comment edit wrong comment (#1192)
* Fix removed comment shown in the wrong position.
* Handle index out of bounds.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
4 files changed, 28 insertions, 14 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index df2718cf..2046f5ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -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()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java index 90102d41..1c2e3199 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java @@ -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(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java index 82222caa..b7c2e30d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java @@ -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(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 0383baf0..4475e8f8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -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 |