The following Subscription doesn't work at all, When Click a refresh Button. There is no printed Logs indicate that is there any API called.
-Notes: All Dependencies done using dagger2, and Retrofit instance created like this:
@AppScope
@Provides
public Retrofit retrofit(OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://~~~~~~~~~~")
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
}
[-]In the Presenter..
private final CompositeSubscription compositeSubscription = new CompositeSubscription();
...
//inside onCreate{}
compositeSubscription.add(observeRefresh());
//inside onDestroy{}
compositeSubscription.clear();
// *Here is the part I think that the problem in.
private Subscription observeRefresh() {
return view.observeBtnRefresh()
.doOnNext(__ -> view.showLoading())
.observeOn(Schedulers.io())
.switchMap(__ -> model.getFoodsResponse())// [-] In model below...
.observeOn(AndroidSchedulers.mainThread())
// .doOnNext(model::saveFoodsState)
.doOnEach(__ -> view.hideLoading())
.retry()
.subscribe();
}
[-] In the view ...
@BindView(R.id.btnRefresh)
ImageButton btnRefresh;// ButterKnife.bind(this); is Done.
..
public Observable<Void> observeBtnRefresh() {
return RxView.clicks(btnRefresh);
}
[-] In the model
@Inject
FoodsNetwork foodsNetwork;
public Observable<Response<ResponseBody>> getFoodsResponse() {
return foodsNetwork.getFoodsResponse();
}
[-] foodsNetwork ...
public interface FoodsNetwork {
@GET()
Observable<Response<ResponseBody>> getFoodsResponse();
}
Thanks for reading any way!
I found what's wrong, and I decided to keep this question because could make other developers to take care of little things. There was a small thing missed in the API method(path and some @Query) and this was make it not working
@GET(".")
Observable<Response<ResponseBody>> getFoodsResponse(@Query String query);