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();
}
Aggregations