I am trying to learn RxJava with Retrofit. So this may be a simple question.
I want to write a wrapper method on Retrofit api calls. This method will show and hide progress view and do some other things before starting the call and post completion of call.
This is my service method
@GET("/books")
Observable<List<Book>> getBooks();
Now, before actually making the call, I want to show the progress view.
public <T> void execute(Observable<T> observable, final RequestHandler<T> callback) {
observable = observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
progressDialog = new TransparentProgressDialog(context, progressViewColor);
progressDialog.setCancelable(false);
dismissProgressDialog();
progressDialog.show();
observable.subscribe(new Observer<T>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable t) {
///Handle error
}
@Override
public void onNext(T t) {
/// Call the callback
}
});
}
As can be seen in the code I am passing an interface (RequestHandler) which I call on error and onNext. I am able to get this working. But this is not different than having a normal callback implementation. As per my understanding observable should be chainable. But I am not sure how to get that implemented so that observable can be chained.
Can anybody help me in this?
Thanks