diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-10-23 09:53:30 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-10-23 09:53:30 +0000 |
commit | ddebd6086d11df4dce3d340c8df0e37efc230949 (patch) | |
tree | a168e8049b6bf3e1e1483e0ec9e574071b672517 /app/src/main | |
parent | 01f15625a315c5839e0fcc3a9e794e24a996f2ce (diff) | |
download | infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar.gz infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar.bz2 infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar.lz infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar.xz infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.tar.zst infinity-for-reddit-ddebd6086d11df4dce3d340c8df0e37efc230949.zip |
Fix an issue in respect subreddit recommended comment sort type. Dirty workaround for sensitive swipe sensitivity in ViewPager2 in MainActivity.
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java | 14 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java | 100 |
2 files changed, 66 insertions, 48 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 452016ee..e02c3bc3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -55,6 +55,7 @@ import com.google.android.material.tabs.TabLayoutMediator; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -814,6 +815,19 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } }); + try { + Field recyclerViewField = ViewPager2.class.getDeclaredField("mRecyclerView"); + recyclerViewField.setAccessible(true); + + RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(viewPager2); + + Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop"); + touchSlopField.setAccessible(true); + + int touchSlop = (int) touchSlopField.get(recyclerView); + touchSlopField.set(recyclerView, touchSlop * 4); + } catch (NoSuchFieldException | IllegalAccessException ignore) {} + loadSubscriptions(); subscribedSubredditViewModel = new ViewModelProvider(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index daf0cbb7..1e233c35 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -832,67 +832,71 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS }); mRecyclerView.setAdapter(mAdapter); - ParseComment.parseComment(response.body(), new ArrayList<>(), mLocale, - mExpandChildren, new ParseComment.ParseCommentListener() { - @Override - public void onParseCommentSuccess(ArrayList<Comment> expandedComments, String parentId, ArrayList<String> moreChildrenFullnames) { - ViewPostDetailActivity.this.children = moreChildrenFullnames; - - hasMoreChildren = children.size() != 0; - mAdapter.addComments(expandedComments, hasMoreChildren); - - if (children.size() > 0) { - mRecyclerView.clearOnScrollListeners(); - mRecyclerView.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)) { - fab.hide(); - } else { - if (dy > 0) { - if (mSwipeUpToHideFab) { - fab.show(); - } else { - fab.hide(); - } + if (mRespectSubredditRecommendedSortType) { + fetchCommentsRespectRecommendedSort(false); + } else { + ParseComment.parseComment(response.body(), new ArrayList<>(), mLocale, + mExpandChildren, new ParseComment.ParseCommentListener() { + @Override + public void onParseCommentSuccess(ArrayList<Comment> expandedComments, String parentId, ArrayList<String> moreChildrenFullnames) { + ViewPostDetailActivity.this.children = moreChildrenFullnames; + + hasMoreChildren = children.size() != 0; + mAdapter.addComments(expandedComments, hasMoreChildren); + + if (children.size() > 0) { + mRecyclerView.clearOnScrollListeners(); + mRecyclerView.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)) { + fab.hide(); } else { - if (mSwipeUpToHideFab) { - fab.hide(); + if (dy > 0) { + if (mSwipeUpToHideFab) { + fab.show(); + } else { + fab.hide(); + } } else { - fab.show(); + if (mSwipeUpToHideFab) { + fab.hide(); + } else { + fab.show(); + } } } } - } - if (!isLoadingMoreChildren && loadMoreChildrenSuccess) { - int visibleItemCount = mLinearLayoutManager.getChildCount(); - int totalItemCount = mLinearLayoutManager.getItemCount(); - int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition(); + if (!isLoadingMoreChildren && loadMoreChildrenSuccess) { + int visibleItemCount = mLinearLayoutManager.getChildCount(); + int totalItemCount = mLinearLayoutManager.getItemCount(); + int firstVisibleItemPosition = mLinearLayoutManager.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() { - mAdapter.initiallyLoadCommentsFailed(); - } - }); + @Override + public void onParseCommentFailed() { + mAdapter.initiallyLoadCommentsFailed(); + } + }); + } } @Override |