dimanche 6 mars 2016

is valid Mvp pattern implementation (with rxandroid and retrofit)

I want to get data from remote server using rxandroid in mvp repository. Then,set up grid adapter with data(in Fragment), and replace another fragment for tablet ui(in Activity).

If I use callback listener I need at least 2 callbacks, which to notify async(rxjava) is done to fragment and launch fragment with first record from data set.

Is there alternative way to solve this problem other than callback ??

Actually I am not even sure if I am using rxjava properly.

For now I pass observable back to fragment in order to set adapter and launch new fragment from that returned data.

 public <T> Observable.Transformer<T, T> applySchedulers() {
    return observable -> observable
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}

@Override
public Observable<MovieDataContainer> getMovieByFilter(String sortBy, String apiKey, int number) {
    MovieApiService movieApiService= retrofit.createService(MovieApiService.class);
    return movieApiService
            .getMovieList(sortBy,apiKey,number)
            .compose(applySchedulers());
}

If I am not doing correct way please let me know. If you have sample for this case, it will be grateful

Just in case here is mygit repo

Aucun commentaire:

Enregistrer un commentaire