Browse Source

fix various comments bugs

1. redo ChildCommentsFetchResponse structure, stress-tested
2. navigation on more graph again
3. proper "next page" handling
renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
544d9f87bc
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 24
      app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java
  2. 14
      app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java
  3. 2
      app/src/main/java/awais/instagrabber/repositories/responses/User.kt
  4. 10
      app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java
  5. 29
      app/src/main/res/navigation/more_nav_graph.xml

24
app/src/main/java/awais/instagrabber/repositories/responses/ChildCommentsFetchResponse.java

@ -8,27 +8,30 @@ import awais.instagrabber.models.Comment;
public class ChildCommentsFetchResponse { public class ChildCommentsFetchResponse {
private final int childCommentCount; private final int childCommentCount;
private final String nextMinId;
private final String nextMaxChildCursor;
private final List<Comment> childComments; private final List<Comment> childComments;
private final boolean hasMoreTailChildComments;
public ChildCommentsFetchResponse(final int childCommentCount, public ChildCommentsFetchResponse(final int childCommentCount,
final String nextMinId, // unconfirmed
final List<Comment> childComments) {
final String nextMaxChildCursor,
final List<Comment> childComments,
final boolean hasMoreTailChildComments) {
this.childCommentCount = childCommentCount; this.childCommentCount = childCommentCount;
this.nextMinId = nextMinId;
this.nextMaxChildCursor = nextMaxChildCursor;
this.childComments = childComments; this.childComments = childComments;
this.hasMoreTailChildComments = hasMoreTailChildComments;
} }
public int getChildCommentCount() { public int getChildCommentCount() {
return childCommentCount; 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<Comment> getChildComments() { public List<Comment> getChildComments() {
@ -38,10 +41,11 @@ public class ChildCommentsFetchResponse {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return "CommentsFetchResponse{" +
return "ChildCommentsFetchResponse{" +
"childCommentCount=" + childCommentCount + "childCommentCount=" + childCommentCount +
", nextMinId='" + nextMinId + '\'' +
", nextMaxChildCursor='" + nextMaxChildCursor + '\'' +
", childComments=" + childComments + ", childComments=" + childComments +
", hasMoreTailChildComments=" + hasMoreTailChildComments +
'}'; '}';
} }
} }

14
app/src/main/java/awais/instagrabber/repositories/responses/CommentsFetchResponse.java

@ -10,13 +10,16 @@ public class CommentsFetchResponse {
private final int commentCount; private final int commentCount;
private final String nextMinId; private final String nextMinId;
private final List<Comment> comments; private final List<Comment> comments;
private final boolean hasMoreComments;
public CommentsFetchResponse(final int commentCount, public CommentsFetchResponse(final int commentCount,
final String nextMinId, final String nextMinId,
final List<Comment> comments) {
final List<Comment> comments,
final boolean hasMoreComments) {
this.commentCount = commentCount; this.commentCount = commentCount;
this.nextMinId = nextMinId; this.nextMinId = nextMinId;
this.comments = comments; this.comments = comments;
this.hasMoreComments = hasMoreComments;
} }
public int getCommentCount() { public int getCommentCount() {
@ -27,14 +30,14 @@ public class CommentsFetchResponse {
return nextMinId; return nextMinId;
} }
public boolean hasNext() {
return nextMinId != null;
}
public List<Comment> getComments() { public List<Comment> getComments() {
return comments; return comments;
} }
public boolean getHasMoreComments() {
return hasMoreComments;
}
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
@ -42,6 +45,7 @@ public class CommentsFetchResponse {
"commentCount=" + commentCount + "commentCount=" + commentCount +
", nextMinId='" + nextMinId + '\'' + ", nextMinId='" + nextMinId + '\'' +
", comments=" + comments + ", comments=" + comments +
", hasMoreComments=" + hasMoreComments +
'}'; '}';
} }
} }

2
app/src/main/java/awais/instagrabber/repositories/responses/User.kt

@ -6,7 +6,7 @@ import java.io.Serializable
data class User @JvmOverloads constructor( data class User @JvmOverloads constructor(
val pk: Long = 0, val pk: Long = 0,
val username: String = "", val username: String = "",
val fullName: String = "",
val fullName: String? = "",
val isPrivate: Boolean = false, val isPrivate: Boolean = false,
val profilePicUrl: String? = null, val profilePicUrl: String? = null,
val isVerified: Boolean = false, val isVerified: Boolean = false,

10
app/src/main/java/awais/instagrabber/viewmodels/CommentsViewerViewModel.java

@ -74,7 +74,7 @@ public class CommentsViewerViewModel extends ViewModel {
comments = mergeList(rootList, comments); comments = mergeList(rootList, comments);
} }
rootCursor = result.getNextMinId(); rootCursor = result.getNextMinId();
rootHasNext = result.hasNext();
rootHasNext = result.getHasMoreComments();
rootList.postValue(Resource.success(comments)); rootList.postValue(Resource.success(comments));
} }
@ -100,8 +100,8 @@ public class CommentsViewerViewModel extends ViewModel {
if (repliesCursor != null) { if (repliesCursor != null) {
comments = mergeList(replyList, comments); comments = mergeList(replyList, comments);
} }
repliesCursor = result.getNextMinId();
repliesHasNext = result.hasNext();
repliesCursor = result.getNextMaxChildCursor();
repliesHasNext = result.getHasMoreTailChildComments();
replyList.postValue(Resource.success(comments)); replyList.postValue(Resource.success(comments));
} }
@ -228,8 +228,8 @@ public class CommentsViewerViewModel extends ViewModel {
final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root); final Comment commentModel = getComment(commentsJsonArray.getJSONObject(i).getJSONObject("node"), root);
builder.add(commentModel); 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 //noinspection unchecked
callback.onSuccess(result); callback.onSuccess(result);
} catch (Exception e) { } catch (Exception e) {

29
app/src/main/res/navigation/more_nav_graph.xml

@ -13,6 +13,35 @@
<include app:graph="@navigation/story_list_nav_graph" /> <include app:graph="@navigation/story_list_nav_graph" />
<include app:graph="@navigation/discover_nav_graph" /> <include app:graph="@navigation/discover_nav_graph" />
<action
android:id="@+id/action_global_commentsViewerFragment"
app:destination="@id/comments_nav_graph">
<argument
android:name="shortCode"
app:argType="string"
app:nullable="false" />
<argument
android:name="postId"
app:argType="string"
app:nullable="false" />
<argument
android:name="postUserId"
app:argType="long" />
</action>
<action
android:id="@+id/action_global_likesViewerFragment"
app:destination="@id/likes_nav_graph">
<argument
android:name="postId"
app:argType="string"
app:nullable="false" />
<argument
android:name="isComment"
app:argType="boolean"
app:nullable="false" />
</action>
<action <action
android:id="@+id/action_global_profileFragment" android:id="@+id/action_global_profileFragment"
app:destination="@id/profile_nav_graph"> app:destination="@id/profile_nav_graph">

Loading…
Cancel
Save