Search in sources :

Example 1 with TechAdapter

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);
        }
    });
}
Also used : TechAdapter(com.codeest.geeknews.ui.gank.adapter.TechAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) ProgressImageView(com.codeest.geeknews.widget.ProgressImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 TechAdapter (com.codeest.geeknews.ui.gank.adapter.TechAdapter)1 ProgressImageView (com.codeest.geeknews.widget.ProgressImageView)1