diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-06-18 09:41:45 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-06-18 09:41:45 +0000 |
commit | 8092c07ea01597bb6eb17e344cf3c7cbfc74768d (patch) | |
tree | 7d572b34d9f175a2ce26aec908d0951e1bfb5619 /app/src/main | |
parent | 70f4a7fc4c82e97b5b9a9b7682d6e8c3fade631e (diff) | |
download | infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar.gz infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar.bz2 infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar.lz infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar.xz infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.tar.zst infinity-for-reddit-8092c07ea01597bb6eb17e344cf3c7cbfc74768d.zip |
Fixed sending child comments.
Diffstat (limited to 'app/src/main')
4 files changed, 28 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java index eef1d810..e05d4d17 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java @@ -98,6 +98,7 @@ public class CommentActivity extends AppCompatActivity { public void sendCommentSuccess(CommentData commentData) { Intent returnIntent = new Intent(); returnIntent.putExtra(EXTRA_COMMENT_DATA_KEY, commentData); + returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname); if(isReplying) { returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index 6ade3dd8..ac4b5823 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -171,6 +171,13 @@ class CommentData implements Parcelable { } } + public void addChild(CommentData comment) { + if(children == null) { + children = new ArrayList<>(); + } + children.add(0, comment); + } + public ArrayList<String> getMoreChildrenIds() { return moreChildrenIds; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java index 260bb5bf..dc2e49f0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java @@ -334,16 +334,25 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH notifyItemInserted(0); } - //Need proper implementation - void addChildComment(CommentData comment, int parentPosition) { - ArrayList<CommentData> childComments = mCommentData.get(parentPosition).getChildren(); - if(childComments == null) { - childComments = new ArrayList<>(); + void addChildComment(CommentData comment, String parentFullname, int parentPosition) { + if(parentFullname.equals(mVisibleComments.get(parentPosition).getFullName())) { + for(int i = 0; i < mVisibleComments.size(); i++) { + if(parentFullname.equals(mVisibleComments.get(i).getFullName())) { + parentPosition = i; + break; + } + } + } + + mVisibleComments.get(parentPosition).addChild(comment); + mVisibleComments.get(parentPosition).setHasReply(true); + if(!mVisibleComments.get(parentPosition).isExpanded()) { + expandChildren(parentPosition); + notifyItemChanged(parentPosition); + } else { + mVisibleComments.add(parentPosition + 1, comment); + notifyItemInserted(parentPosition + 1); } - childComments.add(0, comment); - mCommentData.get(parentPosition).addChildren(childComments); - mCommentData.get(parentPosition).setHasReply(true); - notifyItemChanged(parentPosition); } void clearData() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 95a9ba0e..58c4d571 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -694,8 +694,9 @@ public class ViewPostDetailActivity extends AppCompatActivity { if(comment.getDepth() == 0) { mAdapter.addComment(comment); } else { + String parentFullname = data.getExtras().getString(CommentActivity.EXTRA_PARENT_FULLNAME_KEY); int parentPosition = data.getExtras().getInt(CommentActivity.EXTRA_PARENT_POSITION_KEY); - mAdapter.addChildComment(comment, parentPosition); + mAdapter.addChildComment(comment, parentFullname, parentPosition); } } else { Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show(); |