Skip to content

Instantly share code, notes, and snippets.

@kolipass
Last active August 29, 2015 14:26
Show Gist options
  • Save kolipass/d26e742f103062095f49 to your computer and use it in GitHub Desktop.
Save kolipass/d26e742f103062095f49 to your computer and use it in GitHub Desktop.
public static Subscription action() {
return Observable.create(new LoadConfig())
.subscribe(new Action1<Config>() {
@Override
public void call(Config config) {
if (config.nedToUpdate()) {
//данных нет обновляемся
update();
} else {
if (config.nedToBeSend()) {
send();
} else {
//ничего не делать
}
}
}
});
}
public static Subscription update() {
return gainingInformation()
.doOnNext(new Action1<JsonObject>() {
@Override
public void call(final JsonObject jsonObject) {
send();
}
})
.subscribe();
}
private static Observable<JsonObject> gainingInformation() {
Observable<Information> information1 = Observable.create(new Information1Loader());
Observable<Information> information2 = Observable.create(new Information2Loader());
Observable<Information> information3 = Observable.create(new Information3Loader());
Observable<Information> information4 = Observable.create(new Information4Loader());
return Observable.zip(
Arrays.asList(information1, information2, information3, information4),
joinInformationToJsonObject());
}
private static Subscription send() {
return sendDataObservable(String.valueOf(jsonObject))
.subscribeOn(Schedulers.newThread()).onErrorResumeNext(
saveFile(jsonObject))
.doOnNext(new Action1<JsonObject>() {
@Override
public void call(JsonObject s) {
if (s != null) {
jsonObject.addProperty(SENT, true);
}
saveFile(jsonObject).subscribe();
}
}).subscribe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment