Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. private void addLocations(final List<UserLocation> locations) {
  2.         service.addLocation(RequestBodies.createJson(new Locations(locations)))
  3.                 .subscribeWith(new GenericObserver<AddLocationResponse>() {
  4.  
  5.                     @Override
  6.                     public void onError(Throwable e) {
  7.                         super.onError(e);
  8.                     }
  9.  
  10.                     @Override
  11.                     public void on200(AddLocationResponse body) {
  12.                         super.on200(body);
  13.                         try {
  14.                             db.getLocationsDAO().delete(locations);
  15.                             Timber.d("locations clear");
  16.                         } catch (SQLException e) {
  17.                             e.printStackTrace();
  18.                         }
  19.  
  20.                         db.getLocationsDAO().getItems().debounce(30, TimeUnit.SECONDS)
  21.                                 .doOnNext(new Consumer<List<UserLocation>>() {
  22.                                     @Override
  23.                                     public void accept(List<UserLocation> locations) throws Exception {
  24.                                         if (locations != null && locations.isEmpty()) {
  25.                                             addLocations(locations);
  26.                                         }
  27.                                     }
  28.                                 }).doOnError(new Consumer<Throwable>() {
  29.                             @Override
  30.                             public void accept(Throwable throwable) throws Exception {
  31.                                 throwable.printStackTrace();
  32.                             }
  33.                         });
  34.                     }
  35.  
  36.                     @Override
  37.                     public void errorIfHttpCodeSuccess(AddLocationResponse body) {
  38.                         super.errorIfHttpCodeSuccess(body);
  39.                     }
  40.                 });
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement