Search in sources :

Example 1 with GirlAdapter

use of com.codeest.geeknews.ui.gank.adapter.GirlAdapter in project GeekNews by codeestX.

the class GirlFragment method initEventAndData.

@Override
protected void initEventAndData() {
    mList = new ArrayList<>();
    mAdapter = new GirlAdapter(mContext, mList);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL);
    mStaggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
    //fix issue #52 https://github.com/codeestX/GeekNews/issues/52
    mStaggeredGridLayoutManager.setItemPrefetchEnabled(false);
    rvGirlContent.setLayoutManager(mStaggeredGridLayoutManager);
    rvGirlContent.setAdapter(mAdapter);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            mPresenter.getGirlData();
        }
    });
    rvGirlContent.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int[] visibleItems = mStaggeredGridLayoutManager.findLastVisibleItemPositions(null);
            int lastItem = Math.max(visibleItems[0], visibleItems[1]);
            if (lastItem > mAdapter.getItemCount() - 5 && !isLoadingMore && dy > 0) {
                isLoadingMore = true;
                mPresenter.getMoreGirlData();
            }
        }
    });
    mAdapter.setOnItemClickListener(new GirlAdapter.OnItemClickListener() {

        @Override
        public void onItemClickListener(int position, View shareView) {
            Intent intent = new Intent();
            intent.setClass(mContext, GirlDetailActivity.class);
            intent.putExtra("url", mList.get(position).getUrl());
            intent.putExtra("id", mList.get(position).get_id());
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(mActivity, shareView, "shareView");
            mContext.startActivity(intent, options.toBundle());
        }
    });
    ivProgress.start();
    mPresenter.getGirlData();
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ProgressImageView(com.codeest.geeknews.widget.ProgressImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) GirlDetailActivity(com.codeest.geeknews.ui.gank.activity.GirlDetailActivity) GirlAdapter(com.codeest.geeknews.ui.gank.adapter.GirlAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ActivityOptions(android.app.ActivityOptions)

Aggregations

ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)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 GirlDetailActivity (com.codeest.geeknews.ui.gank.activity.GirlDetailActivity)1 GirlAdapter (com.codeest.geeknews.ui.gank.adapter.GirlAdapter)1 ProgressImageView (com.codeest.geeknews.widget.ProgressImageView)1