Search in sources :

Example 1 with RecyclerSimpleScrollListener

use of com.tevinjeffrey.rutgersct.ui.utils.RecyclerSimpleScrollListener in project Rutgers-Course-Tracker by tevjef.

the class TrackedSectionsFragment method initRecyclerView.

public void initRecyclerView() {
    LinearLayoutManager layoutManager = new LinearLayoutManager(getParentActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.setSmoothScrollbarEnabled(true);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setHasFixedSize(true);
    RecyclerSimpleScrollListener recyclerSimpleScrollListener = new RecyclerSimpleScrollListener();
    mRecyclerView.addOnScrollListener(recyclerSimpleScrollListener);
    recyclerSimpleScrollListener.getDirectionObservable().subscribe(new Action1<RecyclerSimpleScrollListener.Direction>() {

        @Override
        public void call(RecyclerSimpleScrollListener.Direction direction) {
            switch(direction) {
                case UP:
                    animateFabIn();
                    //mFab.show();
                    break;
                case DOWN:
                    animateFabOut();
                    //mFab.hide();
                    break;
                case NEUTRAL:
                    break;
            }
        }

        //The animation up and down takes into account if he snackbar is showing or not.
        private void animateFabIn() {
            ViewCompat.animate(mFab).alpha(1).setStartDelay(50).start();
            ViewCompat.animate(mFab).translationY(mViewState.snackBarShowing ? -SnackbarManager.getCurrentSnackbar().getHeight() : 0).setStartDelay(50).start();
        }

        private void animateFabOut() {
            ViewCompat.animate(mFab).alphaBy(0).setStartDelay(50).start();
            ViewCompat.animate(mFab).translationYBy(250).setStartDelay(50).start();
        }
    });
    if (mListDataset == null) {
        mListDataset = new ArrayList<>(10);
    }
    if (mRecyclerView.getAdapter() == null) {
        mRecyclerView.setAdapter(new TrackedSectionsFragmentAdapter(mListDataset, this));
    }
}
Also used : RecyclerSimpleScrollListener(com.tevinjeffrey.rutgersct.ui.utils.RecyclerSimpleScrollListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerSimpleScrollListener (com.tevinjeffrey.rutgersct.ui.utils.RecyclerSimpleScrollListener)1