Search in sources :

Example 1 with ZhihuDaily

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily in project LookLook by xinghongfei.

the class ZhihuPresenterImpl method getLastZhihuNews.

@Override
public void getLastZhihuNews() {
    mZhihuFragment.showProgressDialog();
    Subscription subscription = ApiManage.getInstence().getZhihuApiService().getLastDaily().map(new Func1<ZhihuDaily, ZhihuDaily>() {

        @Override
        public ZhihuDaily call(ZhihuDaily zhihuDaily) {
            String date = zhihuDaily.getDate();
            for (ZhihuDailyItem zhihuDailyItem : zhihuDaily.getStories()) {
                zhihuDailyItem.setDate(date);
            }
            return zhihuDaily;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuDaily>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.showError(e.getMessage());
        }

        @Override
        public void onNext(ZhihuDaily zhihuDaily) {
            mZhihuFragment.hidProgressDialog();
            mCacheUtil.put(Config.ZHIHU, gson.toJson(zhihuDaily));
            mZhihuFragment.updateList(zhihuDaily);
        }
    });
    addSubscription(subscription);
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 2 with ZhihuDaily

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily in project LookLook by xinghongfei.

the class ZhihuPresenterImpl method getTheDaily.

@Override
public void getTheDaily(String date) {
    Subscription subscription = ApiManage.getInstence().getZhihuApiService().getTheDaily(date).map(new Func1<ZhihuDaily, ZhihuDaily>() {

        @Override
        public ZhihuDaily call(ZhihuDaily zhihuDaily) {
            String date = zhihuDaily.getDate();
            for (ZhihuDailyItem zhihuDailyItem : zhihuDaily.getStories()) {
                zhihuDailyItem.setDate(date);
            }
            return zhihuDaily;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ZhihuDaily>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.showError(e.getMessage());
        }

        @Override
        public void onNext(ZhihuDaily zhihuDaily) {
            mZhihuFragment.hidProgressDialog();
            mZhihuFragment.updateList(zhihuDaily);
        }
    });
    addSubscription(subscription);
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily) ZhihuDailyItem(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 3 with ZhihuDaily

use of com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily in project LookLook by xinghongfei.

the class ZhihuPresenterImpl method getLastFromCache.

@Override
public void getLastFromCache() {
    if (mCacheUtil.getAsJSONObject(Config.ZHIHU) != null) {
        ZhihuDaily zhihuDaily = gson.fromJson(mCacheUtil.getAsJSONObject(Config.ZHIHU).toString(), ZhihuDaily.class);
        mZhihuFragment.updateList(zhihuDaily);
    }
}
Also used : ZhihuDaily(com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily)

Aggregations

ZhihuDaily (com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDaily)3 ZhihuDailyItem (com.looklook.xinghongfei.looklook.bean.zhihu.ZhihuDailyItem)2 Subscription (rx.Subscription)2 Func1 (rx.functions.Func1)2