Fix not showing all comments in single comment thread mode in CommentsRecyclerViewAdapter.

This commit is contained in:
Alex Ning 2021-06-27 22:01:06 +08:00
parent 7b1221bfc9
commit d5c65ff492

View File

@ -13,6 +13,7 @@ import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -773,6 +774,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
private void collapseChildren(int position) {
Log.i("asdfasdf", "s " + position);
mVisibleComments.get(position).setExpanded(false);
int depth = mVisibleComments.get(position).getDepth();
int allChildrenSize = 0;
@ -788,15 +790,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mVisibleComments.subList(position + 1, position + 1 + allChildrenSize).clear();
}
if (mIsSingleCommentThreadMode) {
Log.i("asdfasdf", "s1 " + getItemCount());
notifyItemRangeRemoved(position + 2, allChildrenSize);
if (mFullyCollapseComment) {
notifyItemChanged(position + 1);
}
notifyItemRangeRemoved(position + 2, allChildrenSize);
} else {
notifyItemRangeRemoved(position + 1, allChildrenSize);
if (mFullyCollapseComment) {
notifyItemChanged(position);
}
notifyItemRangeRemoved(position + 1, allChildrenSize);
}
}
@ -814,7 +817,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int sizeBefore = mVisibleComments.size();
mVisibleComments.addAll(comments);
if (mIsSingleCommentThreadMode) {
notifyItemRangeInserted(sizeBefore + 1, comments.size());
notifyItemRangeInserted(sizeBefore, comments.size() + 1);
} else {
notifyItemRangeInserted(sizeBefore, comments.size());
}
@ -1069,6 +1072,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (mIsSingleCommentThreadMode) {
Log.i("asdfasdf", "now " + (mVisibleComments.size() + 1));
return mVisibleComments.size() + 1;
} else {
return mVisibleComments.size();
@ -1438,11 +1442,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
expandButton.setOnClickListener(view -> {
if (expandButton.getVisibility() == View.VISIBLE) {
int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 1 : getBindingAdapterPosition();
if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) {
Comment comment = getCurrentComment(this);
if (comment != null) {
if (mVisibleComments.get(commentPosition).isExpanded()) {
collapseChildren(commentPosition);
Log.i("asdfasdf", "ssf");
expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp);
} else {
comment.setExpanded(true);
@ -1459,7 +1463,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
expandButton.setImageResource(R.drawable.ic_expand_less_grey_24dp);
}
}
}
} else if (mFullyCollapseComment) {
int commentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 1 : getBindingAdapterPosition();
if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) {