mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
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:
parent
fe9e0bd5d7
commit
9b4ee0018e
@ -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()) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user