From af04240dfa014b5d61ac0c83ea57b7983e086dd4 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:27:30 -0400 Subject: Continue applying comment filter. --- .../fragments/ViewPostDetailFragment.java | 125 +++++++++++---------- 1 file changed, 67 insertions(+), 58 deletions(-) (limited to 'app/src') 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 topLevelComments, ArrayList expandedComments, String parentId, ArrayList 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 topLevelComments, ArrayList expandedComments, String parentId, ArrayList 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 -- cgit v1.2.3