Search in sources :

Example 1 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class JsonExportTask method writeJsonStreamShows.

private void writeJsonStreamShows(OutputStream out, Cursor shows) throws IOException {
    int numTotal = shows.getCount();
    int numExported = 0;
    Gson gson = new Gson();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.beginArray();
    while (shows.moveToNext()) {
        if (isCancelled()) {
            break;
        }
        Show show = new Show();
        show.tvdb_id = shows.getInt(ShowsQuery.ID);
        show.title = shows.getString(ShowsQuery.TITLE);
        show.favorite = shows.getInt(ShowsQuery.FAVORITE) == 1;
        show.hidden = shows.getInt(ShowsQuery.HIDDEN) == 1;
        show.language = shows.getString(ShowsQuery.LANGUAGE);
        show.release_time = shows.getInt(ShowsQuery.RELEASE_TIME);
        show.release_weekday = shows.getInt(ShowsQuery.RELEASE_WEEKDAY);
        show.release_timezone = shows.getString(ShowsQuery.RELEASE_TIMEZONE);
        show.country = shows.getString(ShowsQuery.RELEASE_COUNTRY);
        show.last_watched_episode = shows.getInt(ShowsQuery.LASTWATCHEDID);
        show.last_watched_ms = shows.getLong(ShowsQuery.LASTWATCHED_MS);
        show.poster = shows.getString(ShowsQuery.POSTER);
        show.content_rating = shows.getString(ShowsQuery.CONTENTRATING);
        show.status = DataLiberationTools.decodeShowStatus(shows.getInt(ShowsQuery.STATUS));
        show.runtime = shows.getInt(ShowsQuery.RUNTIME);
        show.network = shows.getString(ShowsQuery.NETWORK);
        show.imdb_id = shows.getString(ShowsQuery.IMDBID);
        show.trakt_id = shows.getInt(ShowsQuery.TRAKT_ID);
        show.first_aired = shows.getString(ShowsQuery.FIRSTAIRED);
        show.rating_user = shows.getInt(ShowsQuery.RATING_USER);
        if (isFullDump) {
            show.overview = shows.getString(ShowsQuery.OVERVIEW);
            show.rating = shows.getDouble(ShowsQuery.RATING_GLOBAL);
            show.rating_votes = shows.getInt(ShowsQuery.RATING_VOTES);
            show.genres = shows.getString(ShowsQuery.GENRES);
            show.last_updated = shows.getLong(ShowsQuery.LAST_UPDATED);
            show.last_edited = shows.getLong(ShowsQuery.LAST_EDITED);
        }
        addSeasons(show);
        gson.toJson(show, Show.class, writer);
        publishProgress(numTotal, ++numExported);
    }
    writer.endArray();
    writer.close();
}
Also used : Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) Show(com.battlelancer.seriesguide.dataliberation.model.Show) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Example 2 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class OverviewActivity method launchSearch.

private void launchSearch() {
    // refine search with the show's title
    Show show = DBUtils.getShow(this, showTvdbId);
    if (show != null) {
        Bundle appSearchData = new Bundle();
        appSearchData.putString(EpisodeSearchFragment.InitBundle.SHOW_TITLE, show.title);
        Intent intent = new Intent(this, SearchActivity.class);
        intent.putExtra(SearchManager.APP_DATA, appSearchData);
        intent.setAction(Intent.ACTION_SEARCH);
        startActivity(intent);
    }
}
Also used : Bundle(android.os.Bundle) Show(com.battlelancer.seriesguide.dataliberation.model.Show) Intent(android.content.Intent)

Example 3 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class TvdbTools method addShow.

/**
     * Adds a show and its episodes to the database. If the show already exists, does nothing.
     *
     * <p> If signed in to Hexagon, gets show properties and episode flags.
     *
     * <p> If connected to trakt, but not signed in to Hexagon, gets episode flags from trakt
     * instead.
     *
     * @return True, if the show and its episodes were added to the database.
     */
public boolean addShow(int showTvdbId, @Nullable String language, @Nullable HashMap<Integer, BaseShow> traktCollection, @Nullable HashMap<Integer, BaseShow> traktWatched) throws TvdbException {
    boolean isShowExists = DBUtils.isShowExists(app, showTvdbId);
    if (isShowExists) {
        return false;
    }
    // get show and determine the language to use
    Show show = getShowDetailsWithHexagon(showTvdbId, language);
    language = show.language;
    // get episodes and store everything to the database
    final ArrayList<ContentProviderOperation> batch = new ArrayList<>();
    batch.add(DBUtils.buildShowOp(app, show, true));
    getEpisodesAndUpdateDatabase(batch, show, language);
    // restore episode flags...
    if (HexagonSettings.isEnabled(app)) {
        // ...from Hexagon
        boolean success = EpisodeTools.Download.flagsFromHexagon(app, showTvdbId);
        if (!success) {
            // failed to download episode flags
            // flag show as needing an episode merge
            ContentValues values = new ContentValues();
            values.put(Shows.HEXAGON_MERGE_COMPLETE, false);
            app.getContentResolver().update(Shows.buildShowUri(showTvdbId), values, null, null);
        }
        // flag show to be auto-added (again), send (new) language to Hexagon
        app.getShowTools().sendIsAdded(showTvdbId, language);
    } else {
        // ...from trakt
        TraktTools traktTools = app.getTraktTools();
        if (!traktTools.storeEpisodeFlags(traktWatched, showTvdbId, TraktTools.Flag.WATCHED)) {
            throw new TvdbDataException("addShow: storing trakt watched episodes failed.");
        }
        if (!traktTools.storeEpisodeFlags(traktCollection, showTvdbId, TraktTools.Flag.COLLECTED)) {
            throw new TvdbDataException("addShow: storing trakt collected episodes failed.");
        }
    }
    // calculate next episode
    DBUtils.updateLatestEpisode(app, showTvdbId);
    return true;
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) BaseShow(com.uwetrottmann.trakt5.entities.BaseShow) Show(com.battlelancer.seriesguide.dataliberation.model.Show) TraktTools(com.battlelancer.seriesguide.util.TraktTools)

Example 4 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class TvdbTools method updateShow.

/**
     * Updates a show. Adds new, updates changed and removes orphaned episodes.
     */
public void updateShow(int showTvdbId) throws TvdbException {
    // determine which translation to get
    String language = getShowLanguage(app, showTvdbId);
    if (language == null) {
        return;
    }
    final ArrayList<ContentProviderOperation> batch = new ArrayList<>();
    Show show = getShowDetails(showTvdbId, language);
    batch.add(DBUtils.buildShowOp(app, show, false));
    // get episodes in the language as returned in the TVDB show entry
    // the show might not be available in the desired language
    getEpisodesAndUpdateDatabase(batch, show, show.language);
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) BaseShow(com.uwetrottmann.trakt5.entities.BaseShow) Show(com.battlelancer.seriesguide.dataliberation.model.Show)

Example 5 with Show

use of com.battlelancer.seriesguide.dataliberation.model.Show in project SeriesGuide by UweTrottmann.

the class JsonImportTask method importFromJson.

private void importFromJson(@JsonExportTask.BackupType int type, FileInputStream in) throws JsonParseException, IOException, IllegalArgumentException {
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    reader.beginArray();
    if (type == JsonExportTask.BACKUP_SHOWS) {
        while (reader.hasNext()) {
            Show show = gson.fromJson(reader, Show.class);
            addShowToDatabase(show);
        }
    } else if (type == JsonExportTask.BACKUP_LISTS) {
        while (reader.hasNext()) {
            List list = gson.fromJson(reader, List.class);
            addListToDatabase(list);
        }
    } else if (type == JsonExportTask.BACKUP_MOVIES) {
        while (reader.hasNext()) {
            Movie movie = gson.fromJson(reader, Movie.class);
            addMovieToDatabase(movie);
        }
    }
    reader.endArray();
    reader.close();
}
Also used : Movie(com.battlelancer.seriesguide.dataliberation.model.Movie) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) JsonReader(com.google.gson.stream.JsonReader) Show(com.battlelancer.seriesguide.dataliberation.model.Show) ArrayList(java.util.ArrayList) List(com.battlelancer.seriesguide.dataliberation.model.List)

Aggregations

Show (com.battlelancer.seriesguide.dataliberation.model.Show)11 BaseShow (com.uwetrottmann.trakt5.entities.BaseShow)5 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 ContentProviderOperation (android.content.ContentProviderOperation)2 Cursor (android.database.Cursor)2 Gson (com.google.gson.Gson)2 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextAppearanceSpan (android.text.style.TextAppearanceSpan)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 List (com.battlelancer.seriesguide.dataliberation.model.List)1