Search in sources :

Example 1 with DailyAdapter

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

the class DailyFragment method initEventAndData.

@Override
protected void initEventAndData() {
    super.initEventAndData();
    currentDate = DateUtil.getTomorrowDate();
    mAdapter = new DailyAdapter(mContext, mList);
    mAdapter.setOnItemClickListener(new DailyAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View shareView) {
            mPresenter.insertReadToDB(mList.get(position).getId());
            mAdapter.setReadState(position, true);
            if (mAdapter.getIsBefore()) {
                mAdapter.notifyItemChanged(position + 1);
            } else {
                mAdapter.notifyItemChanged(position + 2);
            }
            Intent intent = new Intent();
            intent.setClass(mContext, ZhihuDetailActivity.class);
            intent.putExtra(Constants.IT_ZHIHU_DETAIL_ID, mList.get(position).getId());
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(mActivity, shareView, "shareView");
            mContext.startActivity(intent, options.toBundle());
        }
    });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (currentDate.equals(DateUtil.getTomorrowDate())) {
                mPresenter.getDailyData();
            } else {
                int year = Integer.valueOf(currentDate.substring(0, 4));
                int month = Integer.valueOf(currentDate.substring(4, 6));
                int day = Integer.valueOf(currentDate.substring(6, 8));
                CalendarDay date = CalendarDay.from(year, month - 1, day);
                RxBus.getDefault().post(date);
            }
        }
    });
    rvDailyList.setLayoutManager(new LinearLayoutManager(mContext));
    rvDailyList.setAdapter(mAdapter);
    stateLoading();
    mPresenter.getDailyData();
}
Also used : Intent(android.content.Intent) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ZhihuDetailActivity(com.codeest.geeknews.ui.zhihu.activity.ZhihuDetailActivity) DailyAdapter(com.codeest.geeknews.ui.zhihu.adapter.DailyAdapter) ActivityOptions(android.app.ActivityOptions)

Aggregations

ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)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 BindView (butterknife.BindView)1 ZhihuDetailActivity (com.codeest.geeknews.ui.zhihu.activity.ZhihuDetailActivity)1 DailyAdapter (com.codeest.geeknews.ui.zhihu.adapter.DailyAdapter)1 CalendarDay (com.prolificinteractive.materialcalendarview.CalendarDay)1