Search in sources :

Example 1 with SubredditAdapter

use of me.ccrama.redditslide.Adapters.SubredditAdapter in project Slide by ccrama.

the class SubredditListView method doAdapter.

public void doAdapter() {
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditNames(where, getContext(), SubredditListView.this);
    adapter = new SubredditAdapter(getActivity(), posts, rv, where, this);
    rv.setAdapter(adapter);
    posts.loadMore(mSwipeRefreshLayout.getContext(), true, where);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });
    rv.addOnScrollListener(new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, getActivity().findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (!posts.loading && !posts.nomore) {
                visibleItemCount = rv.getLayoutManager().getChildCount();
                totalItemCount = rv.getLayoutManager().getItemCount();
                pastVisiblesItems = ((LinearLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    posts.loading = true;
                    LogUtil.v("Loading more");
                    posts.loadMore(mSwipeRefreshLayout.getContext(), false, where);
                }
            }
        }
    });
}
Also used : BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) SubredditAdapter(me.ccrama.redditslide.Adapters.SubredditAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SubredditNames(me.ccrama.redditslide.Adapters.SubredditNames) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 BaseActivity (me.ccrama.redditslide.Activities.BaseActivity)1 SubredditAdapter (me.ccrama.redditslide.Adapters.SubredditAdapter)1 SubredditNames (me.ccrama.redditslide.Adapters.SubredditNames)1 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)1