use of com.battlelancer.seriesguide.items.SearchResult in project SeriesGuide by UweTrottmann.
the class TaskManager method performAddTask.
/**
* Schedule shows to be added to the database.
*
* @param isSilentMode Whether to display status toasts if a show could not be added.
* @param isMergingShows Whether to set the Hexagon show merged flag to true if all shows were
*/
public synchronized void performAddTask(final SgApp app, final List<SearchResult> shows, final boolean isSilentMode, final boolean isMergingShows) {
if (!isSilentMode) {
// notify user here already
if (shows.size() == 1) {
// say title of show
SearchResult show = shows.get(0);
Toast.makeText(mContext, mContext.getString(R.string.add_started, show.title), Toast.LENGTH_SHORT).show();
} else {
// generic adding multiple message
Toast.makeText(mContext, R.string.add_multiple, Toast.LENGTH_SHORT).show();
}
}
// add the show(s) to a running add task or create a new one
if (!isAddTaskRunning() || !mAddTask.addShows(shows, isSilentMode, isMergingShows)) {
// ensure this is called on our main thread (AsyncTask needs access to it)
mHandler.post(new Runnable() {
@Override
public void run() {
mAddTask = (AddShowTask) Utils.executeInOrder(new AddShowTask(app, shows, isSilentMode, isMergingShows));
}
});
}
}
use of com.battlelancer.seriesguide.items.SearchResult in project SeriesGuide by UweTrottmann.
the class TraktAddLoader method parseTraktShowsToSearchResults.
/**
* Transforms a list of trakt shows to a list of {@link SearchResult}, marks shows already in
* the local database as added.
*/
public static List<SearchResult> parseTraktShowsToSearchResults(Context context, @NonNull List<Show> traktShows, @Nullable String overrideLanguage) {
List<SearchResult> results = new ArrayList<>();
// build list
SparseArrayCompat<String> existingPosterPaths = ShowTools.getShowTvdbIdsAndPosters(context);
for (Show show : traktShows) {
if (show.ids == null || show.ids.tvdb == null) {
// has no TheTVDB id
continue;
}
SearchResult result = new SearchResult();
result.tvdbid = show.ids.tvdb;
result.title = show.title;
// search results return an overview, while trending and other lists do not
result.overview = !TextUtils.isEmpty(show.overview) ? show.overview : show.year != null ? String.valueOf(show.year) : "";
if (existingPosterPaths != null && existingPosterPaths.indexOfKey(show.ids.tvdb) >= 0) {
// is already in local database
result.state = SearchResult.STATE_ADDED;
// use the poster we fetched for it (or null if there is none)
result.posterPath = existingPosterPaths.get(show.ids.tvdb);
}
if (overrideLanguage != null) {
result.language = overrideLanguage;
}
results.add(result);
}
return results;
}
use of com.battlelancer.seriesguide.items.SearchResult in project SeriesGuide by UweTrottmann.
the class TvdbAddLoader method markLocalShows.
private void markLocalShows(@Nullable List<SearchResult> results) {
SparseArrayCompat<String> existingPosterPaths = ShowTools.getShowTvdbIdsAndPosters(getContext());
if (existingPosterPaths == null || results == null) {
return;
}
for (SearchResult result : results) {
result.overview = String.format("(%s) %s", result.language, result.overview);
if (existingPosterPaths.indexOfKey(result.tvdbid) >= 0) {
// is already in local database
result.state = SearchResult.STATE_ADDED;
// use the poster we fetched for it (or null if there is none)
result.posterPath = existingPosterPaths.get(result.tvdbid);
}
}
}
use of com.battlelancer.seriesguide.items.SearchResult in project SeriesGuide by UweTrottmann.
the class AddFragment method setSearchResults.
public void setSearchResults(List<SearchResult> searchResults) {
this.searchResults = searchResults;
adapter.clear();
if (AndroidUtils.isHoneycombOrHigher()) {
adapter.addAll(searchResults);
} else {
for (SearchResult searchResult : searchResults) {
adapter.add(searchResult);
}
}
resultsGridView.setAdapter(adapter);
}
use of com.battlelancer.seriesguide.items.SearchResult in project SeriesGuide by UweTrottmann.
the class TvdbTools method searchShow.
/**
* Search TheTVDB for shows which include a certain keyword in their title.
*
* @param language If not provided, will query for results in all languages.
* @return At most 100 results (limited by TheTVDB API).
*/
@Nonnull
public List<SearchResult> searchShow(@NonNull String query, @Nullable final String language) throws TvdbException {
final List<SearchResult> series = new ArrayList<>();
final SearchResult currentShow = new SearchResult();
RootElement root = new RootElement("Data");
Element item = root.getChild("Series");
// set handlers for elements we want to react to
item.setEndElementListener(new EndElementListener() {
public void end() {
// only take results in the selected language
if (language == null || language.equals(currentShow.language)) {
series.add(currentShow.copy());
}
}
});
item.getChild("id").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentShow.tvdbid = Integer.valueOf(body);
}
});
item.getChild("language").setEndTextElementListener(new EndTextElementListener() {
@Override
public void end(String body) {
currentShow.language = body.trim();
}
});
item.getChild("SeriesName").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentShow.title = body.trim();
}
});
item.getChild("Overview").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentShow.overview = body.trim();
}
});
// build search URL: encode query...
String url;
try {
url = TVDB_API_GETSERIES + URLEncoder.encode(query, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new TvdbDataException("searchShow: " + e.getMessage(), e);
}
// ...and set language filter
if (language == null) {
url += TVDB_PARAM_LANGUAGE + "all";
} else {
url += TVDB_PARAM_LANGUAGE + language;
}
downloadAndParse(root.getContentHandler(), url, false, "searchShow: ");
return series;
}
Aggregations