Search in sources :

Example 1 with WechatAdapter

use of com.codeest.geeknews.ui.wechat.adapter.WechatAdapter in project GeekNews by codeestX.

the class WechatMainFragment method initEventAndData.

@Override
protected void initEventAndData() {
    mList = new ArrayList<>();
    mAdapter = new WechatAdapter(mContext, mList);
    rvWechatList.setLayoutManager(new LinearLayoutManager(mContext));
    rvWechatList.setAdapter(mAdapter);
    rvWechatList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int lastVisibleItem = ((LinearLayoutManager) rvWechatList.getLayoutManager()).findLastVisibleItemPosition();
            int totalItemCount = rvWechatList.getLayoutManager().getItemCount();
            if (lastVisibleItem >= totalItemCount - 2 && dy > 0) {
                //还剩2个Item时加载更多
                if (!isLoadingMore) {
                    isLoadingMore = true;
                    mPresenter.getMoreWechatData();
                }
            }
        }
    });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mPresenter.getWechatData();
        }
    });
    ivProgress.start();
    mPresenter.getWechatData();
}
Also used : WechatAdapter(com.codeest.geeknews.ui.wechat.adapter.WechatAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 WechatAdapter (com.codeest.geeknews.ui.wechat.adapter.WechatAdapter)1