Ejemplo n.º 1
0
 private Subscription fetchAndSave() {
   return client
       .getSessions(LocaleUtil.getCurrentLanguageId(getActivity()))
       .subscribeOn(Schedulers.io())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           dao::updateAllAsync, throwable -> Log.e(TAG, "Failed to fetchAndSave.", throwable));
 }
Ejemplo n.º 2
0
 protected Subscription loadData() {
   Observable<List<Session>> cachedSessions = dao.findAll();
   return cachedSessions
       .flatMap(
           sessions -> {
             if (shouldRefresh || sessions.isEmpty()) {
               return client
                   .getSessions(LocaleUtil.getCurrentLanguageId(getActivity()))
                   .doOnNext(dao::updateAllAsync);
             } else {
               return Observable.just(sessions);
             }
           })
       .subscribeOn(Schedulers.io())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(this::onLoadDataSuccess, this::onLoadDataFailure);
 }