aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java3
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();