Fixed a bug when expanding comments. Expand all children of the comment when a new reply is sent.

This commit is contained in:
Alex Ning 2019-12-29 00:17:32 +08:00
parent 4521d3b0ce
commit 6ef39a3821

View File

@ -10,7 +10,6 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.style.SuperscriptSpan; import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -957,16 +956,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
collapseChildren(commentPosition); collapseChildren(commentPosition);
((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); ((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp);
} else { } else {
//expandChildren(commentPosition); comment.setExpanded(true);
ArrayList<CommentData> newList = new ArrayList<>(); ArrayList<CommentData> newList = new ArrayList<>();
eC(mVisibleComments.get(commentPosition).getChildren(), newList, 0); expandChildren(mVisibleComments.get(commentPosition).getChildren(), newList, 0);
mVisibleComments.get(commentPosition).setExpanded(true); mVisibleComments.get(commentPosition).setExpanded(true);
mVisibleComments.addAll(commentPosition + 1, newList); mVisibleComments.addAll(commentPosition + 1, newList);
Log.i("adfasdf", "s " + newList.size());
for (CommentData c : newList) {
Log.i("adfasdf", "s " + c.getAuthor());
}
Log.i("adfasdf", "s " + commentPosition);
if (mIsSingleCommentThreadMode) { if (mIsSingleCommentThreadMode) {
notifyItemRangeInserted(commentPosition + 3, newList.size()); notifyItemRangeInserted(commentPosition + 3, newList.size());
} else { } else {
@ -1269,33 +1264,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
return -1; return -1;
} }
private void expandChildren(int position) { private void expandChildren(ArrayList<CommentData> comments, ArrayList<CommentData> newList, int position) {
CommentData comment = mVisibleComments.get(position);
if (!comment.isExpanded()) {
comment.setExpanded(true);
ArrayList<CommentData> children = comment.getChildren();
if (children != null && children.size() > 0) {
for (int i = 0; i < children.size(); i++) {
children.get(i).setExpanded(false);
}
mVisibleComments.addAll(position + 1, children);
if (mIsSingleCommentThreadMode) {
notifyItemRangeInserted(position + 3, children.size());
} else {
notifyItemRangeInserted(position + 2, children.size());
}
}
}
}
private void eC(ArrayList<CommentData> comments, ArrayList<CommentData> newList, int position) {
if (comments != null && comments.size() > 0) { if (comments != null && comments.size() > 0) {
newList.addAll(position, comments); newList.addAll(position, comments);
int newPosition = position + 1;
for (int i = 0; i < comments.size(); i++) { for (int i = 0; i < comments.size(); i++) {
position++;
if (comments.get(i).getChildren() != null && comments.get(i).getChildren().size() > 0) { if (comments.get(i).getChildren() != null && comments.get(i).getChildren().size() > 0) {
eC(comments.get(i).getChildren(), newList, newPosition); expandChildren(comments.get(i).getChildren(), newList, position);
newPosition += comments.get(i).getChildren().size(); position = position + comments.get(i).getChildren().size();
} }
comments.get(i).setExpanded(true); comments.get(i).setExpanded(true);
} }
@ -1386,11 +1362,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mVisibleComments.get(parentPosition).addChild(comment); mVisibleComments.get(parentPosition).addChild(comment);
mVisibleComments.get(parentPosition).setHasReply(true); mVisibleComments.get(parentPosition).setHasReply(true);
if (!mVisibleComments.get(parentPosition).isExpanded()) { if (!mVisibleComments.get(parentPosition).isExpanded()) {
expandChildren(parentPosition); ArrayList<CommentData> newList = new ArrayList<>();
expandChildren(mVisibleComments.get(parentPosition).getChildren(), newList, 0);
mVisibleComments.get(parentPosition).setExpanded(true);
mVisibleComments.addAll(parentPosition + 1, newList);
if (mIsSingleCommentThreadMode) { if (mIsSingleCommentThreadMode) {
notifyItemChanged(parentPosition + 2); notifyItemChanged(parentPosition + 2);
notifyItemRangeInserted(parentPosition + 3, newList.size());
} else { } else {
notifyItemChanged(parentPosition + 1); notifyItemChanged(parentPosition + 1);
notifyItemRangeInserted(parentPosition + 2, newList.size());
} }
} else { } else {
mVisibleComments.add(parentPosition + 1, comment); mVisibleComments.add(parentPosition + 1, comment);