Search in sources :

Example 1 with ThemeChildAdapter

use of com.codeest.geeknews.ui.zhihu.adapter.ThemeChildAdapter in project GeekNews by codeestX.

the class ThemeActivity method initEventAndData.

@Override
protected void initEventAndData() {
    Intent intent = getIntent();
    id = intent.getExtras().getInt("id");
    ivProgress.start();
    mList = new ArrayList<>();
    mAdapter = new ThemeChildAdapter(mContext, mList);
    rvThemeChildList.setLayoutManager(new LinearLayoutManager(mContext));
    rvThemeChildList.setAdapter(mAdapter);
    mPresenter.getThemeChildData(id);
    mAdapter.setOnItemClickListener(new ThemeChildAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View shareView) {
            mPresenter.insertReadToDB(mList.get(position).getId());
            mAdapter.setReadState(position, true);
            mAdapter.notifyItemChanged(position);
            Intent intent = new Intent();
            intent.setClass(mContext, ZhihuDetailActivity.class);
            intent.putExtra("id", mList.get(position).getId());
            if (shareView != null) {
                mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext, shareView, "shareView").toBundle());
            } else {
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext).toBundle());
            }
        }
    });
    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.getThemeChildData(id);
        }
    });
}
Also used : Intent(android.content.Intent) ThemeChildAdapter(com.codeest.geeknews.ui.zhihu.adapter.ThemeChildAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) ProgressImageView(com.codeest.geeknews.widget.ProgressImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AppBarLayout(android.support.design.widget.AppBarLayout)

Aggregations

Intent (android.content.Intent)1 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 ThemeChildAdapter (com.codeest.geeknews.ui.zhihu.adapter.ThemeChildAdapter)1 ProgressImageView (com.codeest.geeknews.widget.ProgressImageView)1