As long as you are sequencing just the API calls, you can employ Retrofit's RxJava support by using Observables instead of callbacks and tying them together with the Rx stream support. I mostly use .flatmap() function to convert result of one API call to another. In your case, it would like something like this:
First I will be using the Observable version of the calls instead of the ones with callbacks, which will be:
Observable<LoginResponse> login(loginRequest);
Observable<RoutesResponse> getRoutes(routesRequest);
After we have these two functions in our API, we can tie them together with RxJava streams. Here is one without error checking, I am writing this on the go to show as a quick example:
public Observable<RoutesResponse> rxGetRoutes(loginRequest, routesRequest) {
final YourAPI mAPI = YourApiProvider.getInstance();
return mAPI.login(loginRequest)
//using flatmap to convert one answer to another answer
.flatmap( (Func1) LoginResponse -> {
return mAPI.getRoutes(routesRequest);
});
}
You can now observe and subscribe to the returned Observable of this function as normal, after learning RxJava a bit:
rxGetRoutes(loginReq, routesReq)
.observeOn(//the thread you want to observe on)
.subscribe( new Subscriber<RoutesResult>() {
@Override
//the functions of Subscriber you need to override
//where you can also check for errors
//Check RxJava documentation after your IDE completes this area.
});