use of com.uwetrottmann.tmdb2.entities.DiscoverFilter in project SeriesGuide by UweTrottmann.
the class TmdbMoviesLoader method loadInBackground.
@Override
public Result loadInBackground() {
String languageCode = DisplaySettings.getMoviesLanguage(getContext());
String regionCode = DisplaySettings.getMoviesRegion(getContext());
List<Movie> results = null;
String action = null;
try {
Response<MovieResultsPage> response;
if (TextUtils.isEmpty(query)) {
MoviesService moviesService = this.moviesService.get();
Call<MovieResultsPage> call;
switch(link) {
case POPULAR:
action = "get popular movies";
call = moviesService.popular(null, languageCode);
break;
case DIGITAL:
action = "get movie digital releases";
call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.AND, ReleaseType.DIGITAL)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
break;
case DISC:
action = "get movie disc releases";
call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.AND, ReleaseType.PHYSICAL)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
break;
case IN_THEATERS:
default:
action = "get now playing movies";
call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.OR, ReleaseType.THEATRICAL, ReleaseType.THEATRICAL_LIMITED)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
break;
}
response = call.execute();
} else {
action = "search for movies";
response = searchService.get().movie(query, null, languageCode, false, null, null, null).execute();
}
if (response.isSuccessful()) {
MovieResultsPage page = response.body();
if (page != null) {
results = page.results;
}
} else {
SgTmdb.trackFailedRequest(getContext(), action, response);
return buildErrorResult();
}
} catch (IOException e) {
SgTmdb.trackFailedRequest(getContext(), action, e);
// only check for connection here to allow hitting the response cache
return AndroidUtils.isNetworkConnected(getContext()) ? buildErrorResult() : new Result(null, getContext().getString(R.string.offline));
}
return new Result(results, getContext().getString(R.string.no_results));
}
Aggregations