Skip to content

Commit

Permalink
Merge pull request #3826 from wordpress-mobile/issue/3825-reader-hide…
Browse files Browse the repository at this point in the history
…-new-posts-bully

Hide the "new posts" message when the reader list is scrolled
  • Loading branch information
roundhill committed Mar 7, 2016
2 parents 0bc0d8c + 5d516a4 commit 695a4d4
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.ListPopupWindow;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -973,6 +974,18 @@ private boolean isNewPostsBarShowing() {
return (mNewPostsBar != null && mNewPostsBar.getVisibility() == View.VISIBLE);
}

/*
* scroll listener assigned to the recycler when the "new posts" bar is shown to hide
* it upon scrolling
*/
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
hideNewPostsBar();
}
};

private void showNewPostsBar() {
if (!isAdded() || isNewPostsBarShowing()) {
return;
Expand All @@ -981,6 +994,18 @@ private void showNewPostsBar() {
AniUtils.startAnimation(mNewPostsBar, R.anim.reader_top_bar_in);
mNewPostsBar.setVisibility(View.VISIBLE);

// assign the scroll listener to hide the bar when the recycler is scrolled, but don't assign
// it right away since the user may be scrolling when the bar appears (which would cause it
// to disappear as soon as it's displayed)
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if (isAdded() && isNewPostsBarShowing()) {
mRecyclerView.addOnScrollListener(mOnScrollListener);
}
}
}, 1000L);

// remove the gap marker if it's showing, since it's no longer valid
getPostAdapter().removeGapMarker();
}
Expand All @@ -992,6 +1017,9 @@ private void hideNewPostsBar() {

mIsAnimatingOutNewPostsBar = true;

// remove the onScrollListener assigned in showNewPostsBar()
mRecyclerView.removeOnScrollListener(mOnScrollListener);

Animation.AnimationListener listener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
Expand Down

0 comments on commit 695a4d4

Please sign in to comment.