Search in sources :

Example 6 with SearchResult

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));
            }
        });
    }
}
Also used : SearchResult(com.battlelancer.seriesguide.items.SearchResult)

Example 7 with SearchResult

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;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.battlelancer.seriesguide.items.SearchResult) Show(com.uwetrottmann.trakt5.entities.Show) BaseShow(com.uwetrottmann.trakt5.entities.BaseShow)

Example 8 with SearchResult

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);
        }
    }
}
Also used : SearchResult(com.battlelancer.seriesguide.items.SearchResult)

Example 9 with SearchResult

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);
}
Also used : SearchResult(com.battlelancer.seriesguide.items.SearchResult)

Example 10 with SearchResult

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;
}
Also used : RootElement(android.sax.RootElement) EndElementListener(android.sax.EndElementListener) Element(android.sax.Element) RootElement(android.sax.RootElement) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchResult(com.battlelancer.seriesguide.items.SearchResult) EndTextElementListener(android.sax.EndTextElementListener) Nonnull(javax.annotation.Nonnull)

Aggregations

SearchResult (com.battlelancer.seriesguide.items.SearchResult)11 TvdbException (com.battlelancer.seriesguide.thetvdbapi.TvdbException)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 BaseShow (com.uwetrottmann.trakt5.entities.BaseShow)2 Show (com.uwetrottmann.trakt5.entities.Show)2 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 Element (android.sax.Element)1 EndElementListener (android.sax.EndElementListener)1 EndTextElementListener (android.sax.EndTextElementListener)1 RootElement (android.sax.RootElement)1 Nullable (android.support.annotation.Nullable)1 Series (com.uwetrottmann.thetvdb.entities.Series)1 SeriesResultsResponse (com.uwetrottmann.thetvdb.entities.SeriesResultsResponse)1 TheTvdbSeries (com.uwetrottmann.thetvdb.services.TheTvdbSeries)1 TrendingShow (com.uwetrottmann.trakt5.entities.TrendingShow)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1