Skip to content

Instantly share code, notes, and snippets.

@shakil807g
Last active October 1, 2017 18:27
Show Gist options
  • Save shakil807g/280771f93502c802a6e1cd80255966bd to your computer and use it in GitHub Desktop.
Save shakil807g/280771f93502c802a6e1cd80255966bd to your computer and use it in GitHub Desktop.
showProgress("Loading..");
ApiClient.getInstance().login(email,pass) /// api call
.retryWhen(new RetryWithDelay(5,1000))
.doAfterNext(userResponse -> {
if(userResponse.isStatus()){
if(userResponse.getBody() != null){
User user = userResponse.getBody();
setUser(user);
}
}
})
.flatMap(userResponse -> {
return AppDatabase.getInstance(LoginActivity.this)
.bootMeDoa().getAll().defaultIfEmpty(new ArrayList<>()).toFlowable() /// database call
.flatMap(list -> {
if(!list.isEmpty()) {
BootMe bootMe = new BootMe();
bootMe.message_timeout = list.get(0).message_timeout;
bootMe.profession = list.get(0).profession;
setBootMe(bootMe);
return Flowable.empty();
}else {
return ApiClient.getInstance().boot_me() /// api call
.retryWhen(new RetryWithDelay(5,1000))
.doAfterNext(bootMeResponse -> {
if(bootMeResponse != null && bootMeResponse.getBody() != null) {
setBootMe(bootMeResponse.getBody());
BootMeItem bootMeItem = new BootMeItem();
bootMeItem.profession = bootMeResponse.getBody().profession;
bootMeItem.message_timeout = bootMeResponse.getBody().message_timeout;
AppDatabase.getInstance(LoginActivity.this)
.bootMeDoa().insertItem(bootMeItem);
}
});
}
});
})
.compose(RxUtil.applySchedulers())
.compose(bindUntilEvent(ActivityEvent.STOP))
.subscribe(userResponse -> {
hideProgress();
launchHomeActivity();
},t->showError(t.getMessage()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment