Created
February 15, 2018 07:49
-
-
Save Sinarahimi/bead7b93cf3f68ce54a1418079f74e42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MovieRepository extends BaseRepository { | |
private MovieApi movieApi; | |
private MovieDatabaseHelper movieDatabaseHelper; | |
public MovieRepository(Context context) { | |
movieApi = getRetrofitHelper().getService(MovieApi.class); | |
movieDatabaseHelper = new MovieDatabaseHelper(context); | |
} | |
public LiveData<List<Movie>> getMovies() { | |
Single<Response<SearchResult>> resultObservable = movieApi.getMovieList(); | |
resultObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(searchResult -> { | |
if (!searchResult.isSuccessful()) { | |
Log.i("Repository", "not respond"); | |
} else { | |
movieDatabaseHelper.save(searchResult.body().getSearch()); | |
} | |
}, throwable -> Log.i("Repository", throwable.getMessage())); | |
return movieDatabaseHelper.getAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment