aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-11-18 06:33:35 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-11-18 06:33:35 +0000
commit5f3a7fd74ae0d1851f5bf8d8de56452e277a8643 (patch)
treef904cbc4c5b2c4a47d4a06fa1e126407d3eab7e9 /app
parentd4bf238345ab73a91d47960de68a41811c753228 (diff)
downloadinfinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar.gz
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar.bz2
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar.lz
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar.xz
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.tar.zst
infinity-for-reddit-5f3a7fd74ae0d1851f5bf8d8de56452e277a8643.zip
Hide the FloatingActionButton in ViewPostDetailActivity when scrolling down but not when scroll down comments by clicking the volume down key or the fab. Fixed more comments cannot be fetched after orientation change in ViewPostDetailActivity.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java88
1 files changed, 88 insertions, 0 deletions
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 11b99830..691eef31 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -170,6 +170,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private boolean showToast = false;
private boolean isSortingComments = false;
private boolean mVolumeKeysNavigateComments;
+ private boolean mIsSmoothScrolling = false;
private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller mSmoothScroller;
@@ -255,6 +256,61 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mLinearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
+
+ if (children != null && children.size() > 0) {
+ mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ if (!mIsSmoothScrolling) {
+ if (dy > 0) {
+ fab.hide();
+ } else {
+ fab.show();
+ }
+ }
+
+ if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
+ int visibleItemCount = mLinearLayoutManager.getChildCount();
+ int totalItemCount = mLinearLayoutManager.getItemCount();
+ int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+
+ if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
+ fetchMoreComments();
+ }
+ }
+ }
+
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ mIsSmoothScrolling = false;
+ }
+ }
+ });
+ } else {
+ mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ if (!mIsSmoothScrolling) {
+ if (dy > 0) {
+ fab.hide();
+ } else {
+ fab.show();
+ }
+ }
+ }
+
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ mIsSmoothScrolling = false;
+ }
+ }
+ });
+ }
+
mSmoothScroller = new LinearSmoothScroller(this) {
@Override
protected int getVerticalSnapPreference() {
@@ -563,10 +619,18 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
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) {
+ if (dy > 0) {
+ fab.hide();
+ } else {
+ fab.show();
+ }
+ }
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
int visibleItemCount = mLinearLayoutManager.getChildCount();
@@ -578,6 +642,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
}
}
+
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ mIsSmoothScrolling = false;
+ }
+ }
});
}
}
@@ -636,10 +707,18 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
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) {
+ if (dy > 0) {
+ fab.hide();
+ } else {
+ fab.show();
+ }
+ }
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
int visibleItemCount = mLinearLayoutManager.getChildCount();
@@ -651,6 +730,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
}
}
+
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ mIsSmoothScrolling = false;
+ }
+ }
});
}
if (changeRefreshState) {
@@ -991,6 +1077,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
mSmoothScroller.setTargetPosition(nextParentPosition);
if (mLinearLayoutManager != null) {
+ mIsSmoothScrolling = true;
mLinearLayoutManager.startSmoothScroll(mSmoothScroller);
}
}
@@ -1007,6 +1094,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
mSmoothScroller.setTargetPosition(nextParentPosition);
if (mLinearLayoutManager != null) {
+ mIsSmoothScrolling = true;
mLinearLayoutManager.startSmoothScroll(mSmoothScroller);
}
}