use of com.uwetrottmann.trakt5.entities.TrendingShow in project SeriesGuide by UweTrottmann.
the class TvdbAddLoader method loadInBackground.
@Override
public Result loadInBackground() {
List<SearchResult> results;
if (TextUtils.isEmpty(query)) {
// no query? load a list of trending shows from trakt
List<TrendingShow> trendingShows = SgTrakt.executeCall(app, traktShows.get().trending(1, 35, Extended.FULL), "get trending shows");
if (trendingShows != null) {
List<Show> shows = new LinkedList<>();
for (TrendingShow show : trendingShows) {
if (show.show == null || show.show.ids == null || show.show.ids.tvdb == null) {
// skip if required values are missing
continue;
}
shows.add(show.show);
}
// manually set the language to the current search language
results = TraktAddLoader.parseTraktShowsToSearchResults(getContext(), shows, language);
return buildResultSuccess(results, R.string.add_empty);
} else {
return buildResultFailure(R.string.trakt);
}
} else {
// use TheTVDB search for all other (or any) languages
if (DisplaySettings.LANGUAGE_EN.equals(language)) {
List<com.uwetrottmann.trakt5.entities.SearchResult> searchResults = SgTrakt.executeCall(app, traktSearch.get().textQueryShow(query, null, null, null, null, null, null, null, null, null, Extended.FULL, 1, 30), "search shows");
if (searchResults != null) {
List<Show> shows = new LinkedList<>();
for (com.uwetrottmann.trakt5.entities.SearchResult result : searchResults) {
if (result.show == null || result.show.ids == null || result.show.ids.tvdb == null) {
// skip, TVDB id required
continue;
}
shows.add(result.show);
}
// manually set the language to English
results = TraktAddLoader.parseTraktShowsToSearchResults(getContext(), shows, DisplaySettings.LANGUAGE_EN);
return buildResultSuccess(results, R.string.no_results);
} else {
return buildResultFailure(R.string.trakt);
}
} else {
try {
if (TextUtils.isEmpty(language)) {
// use the v1 API to do an any language search not supported by v2
results = TvdbTools.getInstance(app).searchShow(query, null);
} else {
results = TvdbTools.getInstance(app).searchSeries(query, language);
}
markLocalShows(results);
return buildResultSuccess(results, R.string.no_results);
} catch (TvdbException e) {
Timber.e(e, "Searching show failed");
}
return buildResultFailure(R.string.tvdb);
}
}
}
Aggregations