aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java125
1 files changed, 67 insertions, 58 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 36fecec9..1e372602 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -1357,71 +1357,80 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mRecyclerView.setAdapter(mConcatAdapter);
}
- if (mRespectSubredditRecommendedSortType) {
- fetchCommentsRespectRecommendedSort(false);
- } else {
- ParseComment.parseComment(mExecutor, new Handler(), response.body(),
- mExpandChildren, mCommentFilter, new ParseComment.ParseCommentListener() {
- @Override
- public void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, String parentId, ArrayList<String> moreChildrenIds) {
- ViewPostDetailFragment.this.children = moreChildrenIds;
-
- hasMoreChildren = children.size() != 0;
- mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
-
- if (children.size() > 0) {
- (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).clearOnScrollListeners();
- (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- super.onScrolled(recyclerView, dx, dy);
- if (!mIsSmoothScrolling && !mLockFab) {
- if (!recyclerView.canScrollVertically(1)) {
- activity.hideFab();
- } else {
- if (dy > 0) {
- if (mSwipeUpToHideFab) {
- activity.showFab();
- } else {
- activity.hideFab();
- }
- } else {
- if (mSwipeUpToHideFab) {
- activity.hideFab();
- } else {
- activity.showFab();
- }
- }
- }
- }
+ FetchCommentFilter.fetchCommentFilter(mExecutor, new Handler(Looper.getMainLooper()), mRedditDataRoomDatabase,
+ mPost.getSubredditName(), new FetchCommentFilter.FetchCommentFilterListener() {
+ @Override
+ public void success(CommentFilter commentFilter) {
+ mCommentFilter = commentFilter;
+ commentFilterFetched = true;
- if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
- int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
- int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
- int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
+ if (mRespectSubredditRecommendedSortType) {
+ fetchCommentsRespectRecommendedSort(false);
+ } else {
+ ParseComment.parseComment(mExecutor, new Handler(), response.body(),
+ mExpandChildren, mCommentFilter, new ParseComment.ParseCommentListener() {
+ @Override
+ public void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, String parentId, ArrayList<String> moreChildrenIds) {
+ ViewPostDetailFragment.this.children = moreChildrenIds;
+
+ hasMoreChildren = children.size() != 0;
+ mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
+
+ if (children.size() > 0) {
+ (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).clearOnScrollListeners();
+ (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ if (!mIsSmoothScrolling && !mLockFab) {
+ if (!recyclerView.canScrollVertically(1)) {
+ activity.hideFab();
+ } else {
+ if (dy > 0) {
+ if (mSwipeUpToHideFab) {
+ activity.showFab();
+ } else {
+ activity.hideFab();
+ }
+ } else {
+ if (mSwipeUpToHideFab) {
+ activity.hideFab();
+ } else {
+ activity.showFab();
+ }
+ }
+ }
+ }
+
+ if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
+ int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
+ int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
+ int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
+
+ if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
+ fetchMoreComments();
+ }
+ }
+ }
- if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
- fetchMoreComments();
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ mIsSmoothScrolling = false;
+ }
+ }
+ });
}
}
- }
- @Override
- public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
- if (newState == RecyclerView.SCROLL_STATE_IDLE) {
- mIsSmoothScrolling = false;
+ @Override
+ public void onParseCommentFailed() {
+ mCommentsAdapter.initiallyLoadCommentsFailed();
}
- }
- });
- }
- }
-
- @Override
- public void onParseCommentFailed() {
- mCommentsAdapter.initiallyLoadCommentsFailed();
+ });
}
- });
- }
+ }
+ });
}
@Override