Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void addLocations(final List<UserLocation> locations) {
- service.addLocation(RequestBodies.createJson(new Locations(locations)))
- .subscribeWith(new GenericObserver<AddLocationResponse>() {
- @Override
- public void onError(Throwable e) {
- super.onError(e);
- }
- @Override
- public void on200(AddLocationResponse body) {
- super.on200(body);
- try {
- db.getLocationsDAO().delete(locations);
- Timber.d("locations clear");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- db.getLocationsDAO().getItems().debounce(30, TimeUnit.SECONDS)
- .doOnNext(new Consumer<List<UserLocation>>() {
- @Override
- public void accept(List<UserLocation> locations) throws Exception {
- if (locations != null && locations.isEmpty()) {
- addLocations(locations);
- }
- }
- }).doOnError(new Consumer<Throwable>() {
- @Override
- public void accept(Throwable throwable) throws Exception {
- throwable.printStackTrace();
- }
- });
- }
- @Override
- public void errorIfHttpCodeSuccess(AddLocationResponse body) {
- super.errorIfHttpCodeSuccess(body);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement