From 544d9f87bcff2c897bb31a9b3cdb17e10ac84c86 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 7 Jun 2021 18:10:48 -0400 Subject: [PATCH] fix various comments bugs 1. redo ChildCommentsFetchResponse structure, stress-tested 2. navigation on more graph again 3. proper "next page" handling --- .../responses/ChildCommentsFetchResponse.java | 24 ++++++++------- .../responses/CommentsFetchResponse.java | 14 +++++---- .../repositories/responses/User.kt | 2 +- .../viewmodels/CommentsViewerViewModel.java | 10 +++---- .../main/res/navigation/more_nav_graph.xml | 29 +++++++++++++++++++ 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java index 32a6134c..e3f0e8fc 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java @@ -8,27 +8,30 @@ import awais.instagrabber.models.Comment; public class ChildCommentsFetchResponse { private final int childCommentCount; - private final String nextMinId; + private final String nextMaxChildCursor; private final List childComments; + private final boolean hasMoreTailChildComments; public ChildCommentsFetchResponse(final int childCommentCount, - final String nextMinId, // unconfirmed - final List childComments) { + final String nextMaxChildCursor, + final List childComments, + final boolean hasMoreTailChildComments) { this.childCommentCount = childCommentCount; - this.nextMinId = nextMinId; + this.nextMaxChildCursor = nextMaxChildCursor; this.childComments = childComments; + this.hasMoreTailChildComments = hasMoreTailChildComments; } public int getChildCommentCount() { return childCommentCount; } - public String getNextMinId() { - return nextMinId; + public String getNextMaxChildCursor() { + return nextMaxChildCursor; } - public boolean hasNext() { - return nextMinId != null; + public boolean getHasMoreTailChildComments() { + return hasMoreTailChildComments; } public List getChildComments() { @@ -38,10 +41,11 @@ public class ChildCommentsFetchResponse { @NonNull @Override public String toString() { - return "CommentsFetchResponse{" + + return "ChildCommentsFetchResponse{" + "childCommentCount=" + childCommentCount + - ", nextMinId='" + nextMinId + '\'' + + ", nextMaxChildCursor='" + nextMaxChildCursor + '\'' + ", childComments=" + childComments + + ", hasMoreTailChildComments=" + hasMoreTailChildComments + '}'; } } diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java b/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java index d2834e45..5e0a4cb7 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java @@ -10,13 +10,16 @@ public class CommentsFetchResponse { private final int commentCount; private final String nextMinId; private final List comments; + private final boolean hasMoreComments; public CommentsFetchResponse(final int commentCount, final String nextMinId, - final List comments) { + final List comments, + final boolean hasMoreComments) { this.commentCount = commentCount; this.nextMinId = nextMinId; this.comments = comments; + this.hasMoreComments = hasMoreComments; } public int getCommentCount() { @@ -27,14 +30,14 @@ public class CommentsFetchResponse { return nextMinId; } - public boolean hasNext() { - return nextMinId != null; - } - public List getComments() { return comments; } + public boolean getHasMoreComments() { + return hasMoreComments; + } + @NonNull @Override public String toString() { @@ -42,6 +45,7 @@ public class CommentsFetchResponse { "commentCount=" + commentCount + ", nextMinId='" + nextMinId + '\'' + ", comments=" + comments + + ", hasMoreComments=" + hasMoreComments + '}'; } } diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/User.kt b/app/src/main/java/awais/instagrabber/repositories/responses/User.kt index 6b82b1df..b46e3dab 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/User.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/User.kt @@ -6,7 +6,7 @@ import java.io.Serializable data class User @JvmOverloads constructor( val pk: Long = 0, val username: String = "", - val fullName: String = "", + val fullName: String? = "", val isPrivate: Boolean = false, val profilePicUrl: String? = null, val isVerified: Boolean = false, diff --git a/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java index d8e0481e..a4c09f8c 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java @@ -74,7 +74,7 @@ public class CommentsViewerViewModel extends ViewModel { comments = mergeList(rootList, comments); } rootCursor = result.getNextMinId(); - rootHasNext = result.hasNext(); + rootHasNext = result.getHasMoreComments(); rootList.postValue(Resource.success(comments)); } @@ -100,8 +100,8 @@ public class CommentsViewerViewModel extends ViewModel { if (repliesCursor != null) { comments = mergeList(replyList, comments); } - repliesCursor = result.getNextMinId(); - repliesHasNext = result.hasNext(); + repliesCursor = result.getNextMaxChildCursor(); + repliesHasNext = result.getHasMoreTailChildComments(); replyList.postValue(Resource.success(comments)); } @@ -228,8 +228,8 @@ public class CommentsViewerViewModel extends ViewModel { final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root); builder.add(commentModel); } - final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build()) - : new ChildCommentsFetchResponse(count, endCursor, builder.build()); + final Object result = root ? new CommentsFetchResponse(count, endCursor, builder.build(), hasNextPage) + : new ChildCommentsFetchResponse(count, endCursor, builder.build(), hasNextPage); //noinspection unchecked callback.onSuccess(result); } catch (Exception e) { diff --git a/app/src/main/res/navigation/more_nav_graph.xml b/app/src/main/res/navigation/more_nav_graph.xml index 6e29723c..f4e99e1e 100644 --- a/app/src/main/res/navigation/more_nav_graph.xml +++ b/app/src/main/res/navigation/more_nav_graph.xml @@ -13,6 +13,35 @@ + + + + + + + + + + +