use of com.codeest.geeknews.ui.gank.adapter.TechAdapter in project GeekNews by codeestX.
the class TechFragment method initEventAndData.
@Override
protected void initEventAndData() {
mPresenter.getGirlImage();
mList = new ArrayList<>();
tech = getArguments().getString(Constants.IT_GANK_TYPE);
type = getArguments().getInt(Constants.IT_GANK_TYPE_CODE);
mAdapter = new TechAdapter(mContext, mList, tech);
rvTechContent.setLayoutManager(new LinearLayoutManager(mContext));
rvTechContent.setAdapter(mAdapter);
ivProgress.start();
mPresenter.getGankData(tech, type);
mAdapter.setOnItemClickListener(new TechAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position, View shareView) {
TechDetailActivity.launch(new TechDetailActivity.Builder().setContext(mContext).setId(mList.get(position).get_id()).setTitle(mList.get(position).getDesc()).setUrl(mList.get(position).getUrl()).setType(type).setAnimConfig(mActivity, shareView));
}
});
rvTechContent.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastVisibleItem = ((LinearLayoutManager) rvTechContent.getLayoutManager()).findLastVisibleItemPosition();
int totalItemCount = rvTechContent.getLayoutManager().getItemCount();
if (lastVisibleItem >= totalItemCount - 2 && dy > 0) {
//还剩2个Item时加载更多
if (!isLoadingMore) {
isLoadingMore = true;
mPresenter.getMoreGankData(tech);
}
}
}
});
appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset >= 0) {
swipeRefresh.setEnabled(true);
} else {
swipeRefresh.setEnabled(false);
float rate = (float) (SystemUtil.dp2px(mContext, 256) + verticalOffset * 2) / SystemUtil.dp2px(mContext, 256);
if (rate >= 0)
ivOrigin.setAlpha(rate);
}
}
});
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mPresenter.getGankData(tech, type);
}
});
}
Aggregations