Browse Source

instagram mess

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
cf97b29995
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 12
      app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java
  2. 5
      app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java

12
app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java

@ -171,6 +171,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
final JSONObject pageInfo = parentComments.getJSONObject("page_info");
final String foundEndCursor = pageInfo.optString("end_cursor");
final boolean hasNextPage = pageInfo.optBoolean("has_next_page", !TextUtils.isEmpty(foundEndCursor));
// final boolean containsToken = endCursor.contains("bifilter_token");
// if (!Utils.isEmpty(endCursor) && (containsToken || endCursor.contains("cached_comments_cursor"))) {
@ -219,7 +220,8 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
likedBy != null ? likedBy.optLong("count", 0) : 0,
comment.getBoolean("viewer_has_liked"),
profileModel);
commentModel.setPageCursor(!TextUtils.isEmpty(foundEndCursor), TextUtils.isEmpty(foundEndCursor) ? null : foundEndCursor);
if (i == 0 && !foundEndCursor.contains("tao_cursor"))
commentModel.setPageCursor(hasNextPage, TextUtils.isEmpty(foundEndCursor) ? null : foundEndCursor);
JSONObject tempJsonObject;
final JSONArray childCommentsArray;
final int childCommentsLen;
@ -228,13 +230,13 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
&& (childCommentsLen = childCommentsArray.length()) > 0) {
final String childEndCursor;
final boolean hasNextPage;
final boolean childHasNextPage;
if ((tempJsonObject = tempJsonObject.optJSONObject("page_info")) != null) {
childEndCursor = tempJsonObject.optString("end_cursor");
hasNextPage = tempJsonObject.optBoolean("has_next_page", !TextUtils.isEmpty(childEndCursor));
childHasNextPage = tempJsonObject.optBoolean("has_next_page", !TextUtils.isEmpty(childEndCursor));
} else {
childEndCursor = null;
hasNextPage = false;
childHasNextPage = false;
}
final List<CommentModel> childCommentModels = new ArrayList<>();
@ -269,7 +271,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
childComment.getBoolean("viewer_has_liked"),
childProfileModel));
}
childCommentModels.get(childCommentsLen - 1).setPageCursor(hasNextPage, childEndCursor);
childCommentModels.get(childCommentsLen - 1).setPageCursor(childHasNextPage, childEndCursor);
commentModel.setChildCommentModels(childCommentModels);
}
commentModels.add(commentModel);

5
app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java

@ -71,7 +71,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
private InputMethodManager imm;
private AppCompatActivity fragmentActivity;
private LinearLayoutCompat root;
private boolean shouldRefresh = true;
private boolean shouldRefresh = true, hasNextPage = false;
private MediaService mediaService;
private String postId;
private AsyncTask<Void, Void, List<CommentModel>> currentlyRunning;
@ -87,6 +87,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
public void onResult(final List<CommentModel> commentModels) {
if (commentModels != null && commentModels.size() > 0) {
endCursor = commentModels.get(0).getEndCursor();
hasNextPage = commentModels.get(0).hasNextPage();
List<CommentModel> list = commentsViewModel.getList().getValue();
list = list != null ? new LinkedList<>(list) : new LinkedList<>();
// final int oldSize = list != null ? list.size() : 0;
@ -259,7 +260,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
binding.commentField.setEndIconOnClickListener(newCommentListener);
}
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor))
if (hasNextPage && !TextUtils.isEmpty(endCursor))
currentlyRunning = new CommentsFetcher(shortCode, endCursor, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
endCursor = null;
});

Loading…
Cancel
Save