Search in sources :

Example 1 with OnVerticalScrollWithPagingTouchSlopListener

use of me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener in project Douya by DreaminginCodeZH.

the class BaseBroadcastListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    CustomTabsHelperFragment.attachTo(this);
    mBroadcastListResource = onAttachBroadcastListResource();
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            onSwipeRefresh();
        }
    });
    mBroadcastList.setHasFixedSize(true);
    mBroadcastList.setItemAnimator(new NoChangeAnimationItemAnimator());
    // Always use StaggeredGridLayoutManager so that instance state can be saved.
    Activity activity = getActivity();
    int columnCount = CardUtils.getColumnCount(activity);
    mBroadcastList.setLayoutManager(new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL));
    mBroadcastAdapter = new BroadcastAdapter(mBroadcastListResource.get(), this);
    mAdapter = new LoadMoreAdapter(R.layout.load_more_card_item, mBroadcastAdapter);
    mBroadcastList.setAdapter(mAdapter);
    final AppBarHost appBarHost = (AppBarHost) getParentFragment();
    mBroadcastList.addOnScrollListener(new OnVerticalScrollWithPagingTouchSlopListener(activity) {

        @Override
        public void onScrolled(int dy) {
            if (!RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                onShow();
            }
        }

        @Override
        public void onScrolledUp() {
            onShow();
        }

        private void onShow() {
            appBarHost.showAppBar();
            mSendFab.show();
        }

        @Override
        public void onScrolledDown() {
            if (RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
                appBarHost.hideAppBar();
                mSendFab.hide();
            }
        }

        @Override
        public void onScrolledToBottom() {
            mBroadcastListResource.load(true);
        }
    });
    updateRefreshing();
    CheatSheetUtils.setup(mSendFab);
    mSendFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onSendBroadcast();
        }
    });
}
Also used : Activity(android.app.Activity) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FriendlySwipeRefreshLayout(me.zhanghai.android.douya.ui.FriendlySwipeRefreshLayout) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) OnVerticalScrollWithPagingTouchSlopListener(me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener) LoadMoreAdapter(me.zhanghai.android.douya.ui.LoadMoreAdapter) NoChangeAnimationItemAnimator(me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator) AppBarHost(me.zhanghai.android.douya.ui.AppBarHost)

Aggregations

Activity (android.app.Activity)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 View (android.view.View)1 BindView (butterknife.BindView)1 AppBarHost (me.zhanghai.android.douya.ui.AppBarHost)1 FriendlySwipeRefreshLayout (me.zhanghai.android.douya.ui.FriendlySwipeRefreshLayout)1 LoadMoreAdapter (me.zhanghai.android.douya.ui.LoadMoreAdapter)1 NoChangeAnimationItemAnimator (me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator)1 OnVerticalScrollWithPagingTouchSlopListener (me.zhanghai.android.douya.ui.OnVerticalScrollWithPagingTouchSlopListener)1