I'm facing the problem that I need an authentication token to create my Retrofit service. I currently use an Observable to obtain said token, causing a rather ugly Observable construct:
Observable<MyService> observable = application.getMyService();
observable.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(application.defaultSubscribeScheduler())
.subscribe(new Subscriber<MyService>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "Error creating service: ", e);
}
@Override
public void onNext(MyService myService) {
subscription = myService.searchStuff(searchFor)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(application.defaultSubscribeScheduler())
.subscribe(new Subscriber<AResponseWrapper>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "Error loading stuff: ", error);
}
@Override
public void onNext(AResponseWrapper wrapper) {
MainPresenter.this.stuff = wrapper.getStuff();
}
});
}
});
I can't help but feel that this is not how it should be done. Am I right?