Search in sources :

Example 1 with GoldListBean

use of com.codeest.geeknews.model.bean.GoldListBean in project GeekNews by codeestX.

the class GoldPresenter method getGoldData.

@Override
public void getGoldData(String type) {
    mType = type;
    currentPage = 0;
    totalList.clear();
    Observable<List<GoldListBean>> list = mRetrofitHelper.fetchGoldList(type, NUM_EACH_PAGE, currentPage++).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    Observable<List<GoldListBean>> hotList = mRetrofitHelper.fetchGoldHotList(type, new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()), NUM_HOT_LIMIT).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    Subscription rxSubscription = Observable.concat(hotList, list).subscribe(new CommonSubscriber<List<GoldListBean>>(mView) {

        @Override
        public void onNext(List<GoldListBean> goldListBean) {
            if (isHotList) {
                isHotList = false;
                totalList.addAll(goldListBean);
            } else {
                isHotList = true;
                totalList.addAll(goldListBean);
                mView.showContent(totalList);
            }
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : GoldHttpResponse(com.codeest.geeknews.model.http.response.GoldHttpResponse) GoldListBean(com.codeest.geeknews.model.bean.GoldListBean) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(rx.Subscription) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with GoldListBean

use of com.codeest.geeknews.model.bean.GoldListBean in project GeekNews by codeestX.

the class GoldPresenter method getGoldData.

@Override
public void getGoldData(String type) {
    mType = type;
    currentPage = 0;
    totalList.clear();
    Flowable<List<GoldListBean>> list = mDataManager.fetchGoldList(type, NUM_EACH_PAGE, currentPage++).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    Flowable<List<GoldListBean>> hotList = mDataManager.fetchGoldHotList(type, new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()), NUM_HOT_LIMIT).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult());
    addSubscribe(Flowable.concat(hotList, list).subscribeWith(new CommonSubscriber<List<GoldListBean>>(mView) {

        @Override
        public void onNext(List<GoldListBean> goldListBean) {
            if (isHotList) {
                isHotList = false;
                totalList.addAll(goldListBean);
            } else {
                isHotList = true;
                totalList.addAll(goldListBean);
                mView.showContent(totalList);
            }
        }
    }));
}
Also used : GoldHttpResponse(com.codeest.geeknews.model.http.response.GoldHttpResponse) GoldListBean(com.codeest.geeknews.model.bean.GoldListBean) CommonSubscriber(com.codeest.geeknews.widget.CommonSubscriber) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with GoldListBean

use of com.codeest.geeknews.model.bean.GoldListBean in project GeekNews by codeestX.

the class GoldPresenter method getMoreGoldData.

@Override
public void getMoreGoldData() {
    Subscription rxSubscription = mRetrofitHelper.fetchGoldList(mType, NUM_EACH_PAGE, currentPage++).compose(RxUtil.<GoldHttpResponse<List<GoldListBean>>>rxSchedulerHelper()).compose(RxUtil.<List<GoldListBean>>handleGoldResult()).subscribe(new CommonSubscriber<List<GoldListBean>>(mView) {

        @Override
        public void onNext(List<GoldListBean> goldListBeen) {
            totalList.addAll(goldListBeen);
            mView.showMoreContent(totalList, totalList.size(), totalList.size() + NUM_EACH_PAGE);
        }
    });
    addSubscrebe(rxSubscription);
}
Also used : GoldListBean(com.codeest.geeknews.model.bean.GoldListBean) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(rx.Subscription)

Example 4 with GoldListBean

use of com.codeest.geeknews.model.bean.GoldListBean in project GeekNews by codeestX.

the class GoldListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    GoldListBean bean = mList.get(0);
    if (position > 0) {
        bean = mList.get(position - 1);
    }
    if (holder instanceof ContentViewHolder) {
        if (bean.getScreenshot() != null && bean.getScreenshot().getUrl() != null) {
            ImageLoader.load(mContext, bean.getScreenshot().getUrl(), ((ContentViewHolder) holder).ivImg);
        } else {
            ((ContentViewHolder) holder).ivImg.setImageResource(R.mipmap.ic_launcher);
        }
        ((ContentViewHolder) holder).tvTitle.setText(bean.getTitle());
        ((ContentViewHolder) holder).tvInfo.setText(getItemInfoStr(bean.getCollectionCount(), bean.getCommentsCount(), bean.getUser().getUsername(), DateUtil.formatDate2String(DateUtil.subStandardTime(bean.getCreatedAt()))));
        holder.itemView.setOnClickListener(new MyOnClickListener(--position));
    } else if (holder instanceof HotViewHolder) {
        if (bean.getScreenshot() != null && bean.getScreenshot().getUrl() != null) {
            ImageLoader.load(mContext, bean.getScreenshot().getUrl(), ((HotViewHolder) holder).ivImg);
        } else {
            ((HotViewHolder) holder).ivImg.setImageResource(R.mipmap.ic_launcher);
        }
        ((HotViewHolder) holder).tvTitle.setText(bean.getTitle());
        ((HotViewHolder) holder).tvLike.setText(String.valueOf(bean.getCollectionCount()));
        ((HotViewHolder) holder).tvAuthor.setText(String.valueOf(bean.getUser().getUsername()));
        ((HotViewHolder) holder).tvTime.setText(DateUtil.formatDate2String(DateUtil.subStandardTime(bean.getCreatedAt())));
        holder.itemView.setOnClickListener(new MyOnClickListener(--position));
    } else {
        ((TitleViewHolder) holder).tvTitle.setText(String.format("%s 热门", mType));
        ((TitleViewHolder) holder).btnClose.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mHotFlag = false;
                for (int i = 0; i < 4; i++) {
                    mList.remove(0);
                }
                notifyItemRangeRemoved(0, 4);
                if (onHotCloseListener != null) {
                    onHotCloseListener.onClose();
                }
            }
        });
    }
}
Also used : GoldListBean(com.codeest.geeknews.model.bean.GoldListBean) SquareImageView(com.codeest.geeknews.widget.SquareImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

GoldListBean (com.codeest.geeknews.model.bean.GoldListBean)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GoldHttpResponse (com.codeest.geeknews.model.http.response.GoldHttpResponse)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Subscription (rx.Subscription)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 CommonSubscriber (com.codeest.geeknews.widget.CommonSubscriber)1 SquareImageView (com.codeest.geeknews.widget.SquareImageView)1