tmdb-java icon indicating copy to clipboard operation
tmdb-java copied to clipboard

RxJava support

Open NathHorrigan opened this issue 9 years ago • 8 comments

Any plans for adding support for RxJava by making service methods return observables?

NathHorrigan avatar Jan 13 '17 18:01 NathHorrigan

No need since Retrofit2 already supports RxJava. Indeed, it supports every interface through call adapters

Add this library:

compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

And extend the Tmdb class to add the support.

class RxTmdb extends Tmdb {
      protected Retrofit.Builder retrofitBuilder() {
        return super.retrofitBuilder().
                         .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
     }
}

urizev avatar Jan 13 '17 19:01 urizev

@urizev But you still would have to change all the service method return types, no? Like:

@GET("search/movie")
Call<MovieResultsPage> movie(...);

has to be changed to:

@GET("search/movie")
Observable<MovieResultsPage> movie(...);

@NathHorrigan In any case, you should create a fork of this library and make the necessary adjustments (find/replace return types, add call adapter). Adding any possible RxJava method seems not useful.

UweTrottmann avatar Jan 14 '17 06:01 UweTrottmann

Having separate RxMoviesService, etc, classes and an optional dependency on RxJava would probably not cause any issues for existing users tho

SimonVT avatar Jan 14 '17 09:01 SimonVT

@UweTrottmann Yes, you're right. I didn't realize. 😞

urizev avatar Jan 14 '17 12:01 urizev

I'll create a fork and let you know how it goes :)

NathHorrigan avatar Jan 14 '17 13:01 NathHorrigan

I derived my local RxJava1 tmdb service and just using the entities. I guess we need 1 main (entities + Call) and 2 additional optional artifacts - RxJava and RxJava2. Don't know this packaging stuff well but you could check out how it is done in RxBinding for example.

sevar83 avatar Feb 15 '17 15:02 sevar83

I've pushed a fork with support for Kotlin and RxJava2. But it's built as an Android Gradle library not a pure Java artifact. https://github.com/sevar83/tmdb-rxjava2-kotlin

sevar83 avatar Sep 29 '17 09:09 sevar83

I created a fork, and relative pull request, in wich i duplcated all the services that return Observables. All the new Services can be found into the class Tmdb.rx

https://github.com/serafo27/tmdb-rxjava

serafo27 avatar Sep 04 '18 11:09 serafo27