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);
}
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);
}
}
}));
}
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);
}
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();
}
}
});
}
}
Aggregations