use of com.codeest.geeknews.model.bean.DailyBeforeListBean in project GeekNews by codeestX.
the class DailyPresenter method getBeforeData.
@Override
public void getBeforeData(String date) {
Subscription rxSubscription = mRetrofitHelper.fetchDailyBeforeListInfo(date).compose(RxUtil.<DailyBeforeListBean>rxSchedulerHelper()).map(new Func1<DailyBeforeListBean, DailyBeforeListBean>() {
@Override
public DailyBeforeListBean call(DailyBeforeListBean dailyBeforeListBean) {
List<DailyListBean.StoriesBean> list = dailyBeforeListBean.getStories();
for (DailyListBean.StoriesBean item : list) {
item.setReadState(mRealmHelper.queryNewsId(item.getId()));
}
return dailyBeforeListBean;
}
}).subscribe(new CommonSubscriber<DailyBeforeListBean>(mView) {
@Override
public void onNext(DailyBeforeListBean dailyBeforeListBean) {
int year = Integer.valueOf(dailyBeforeListBean.getDate().substring(0, 4));
int month = Integer.valueOf(dailyBeforeListBean.getDate().substring(4, 6));
int day = Integer.valueOf(dailyBeforeListBean.getDate().substring(6, 8));
mView.showMoreContent(String.format("%d年%d月%d日", year, month, day), dailyBeforeListBean);
}
});
addSubscrebe(rxSubscription);
}
use of com.codeest.geeknews.model.bean.DailyBeforeListBean in project GeekNews by codeestX.
the class DailyPresenter method registerEvent.
private void registerEvent() {
Subscription rxSubscription = RxBus.getDefault().toObservable(CalendarDay.class).subscribeOn(Schedulers.io()).map(new Func1<CalendarDay, String>() {
@Override
public String call(CalendarDay calendarDay) {
StringBuilder date = new StringBuilder();
String year = String.valueOf(calendarDay.getYear());
String month = String.valueOf(calendarDay.getMonth() + 1);
String day = String.valueOf(calendarDay.getDay() + 1);
if (month.length() < 2) {
month = "0" + month;
}
if (day.length() < 2) {
day = "0" + day;
}
return date.append(year).append(month).append(day).toString();
}
}).filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
if (s.equals(DateUtil.getTomorrowDate())) {
getDailyData();
return false;
}
return true;
}
}).observeOn(//为了网络请求切到io线程
Schedulers.io()).flatMap(new Func1<String, Observable<DailyBeforeListBean>>() {
@Override
public Observable<DailyBeforeListBean> call(String date) {
return mRetrofitHelper.fetchDailyBeforeListInfo(date);
}
}).observeOn(//为了使用Realm和显示结果切到主线程
AndroidSchedulers.mainThread()).map(new Func1<DailyBeforeListBean, DailyBeforeListBean>() {
@Override
public DailyBeforeListBean call(DailyBeforeListBean dailyBeforeListBean) {
List<DailyListBean.StoriesBean> list = dailyBeforeListBean.getStories();
for (DailyListBean.StoriesBean item : list) {
item.setReadState(mRealmHelper.queryNewsId(item.getId()));
}
return dailyBeforeListBean;
}
}).subscribe(new CommonSubscriber<DailyBeforeListBean>(mView) {
@Override
public void onNext(DailyBeforeListBean dailyBeforeListBean) {
int year = Integer.valueOf(dailyBeforeListBean.getDate().substring(0, 4));
int month = Integer.valueOf(dailyBeforeListBean.getDate().substring(4, 6));
int day = Integer.valueOf(dailyBeforeListBean.getDate().substring(6, 8));
mView.showMoreContent(String.format("%d年%d月%d日", year, month, day), dailyBeforeListBean);
}
});
addSubscrebe(rxSubscription);
}
Aggregations