Search in sources :

Example 71 with ContentValues

use of android.content.ContentValues in project SeriesGuide by UweTrottmann.

the class JsonImportTask method addShowToDatabase.

private void addShowToDatabase(Show show) {
    if (show.tvdb_id <= 0) {
        // valid id required
        return;
    }
    // Insert the show
    ContentValues showValues = new ContentValues();
    showValues.put(Shows._ID, show.tvdb_id);
    showValues.put(Shows.TITLE, show.title == null ? "" : show.title);
    showValues.put(Shows.TITLE_NOARTICLE, DBUtils.trimLeadingArticle(show.title));
    showValues.put(Shows.FAVORITE, show.favorite);
    showValues.put(Shows.HIDDEN, show.hidden);
    // only add the language, if we support it
    for (int i = 0, size = languageCodes.length; i < size; i++) {
        if (languageCodes[i].equals(show.language)) {
            showValues.put(Shows.LANGUAGE, show.language);
            break;
        }
    }
    showValues.put(Shows.RELEASE_TIME, show.release_time);
    if (show.release_weekday < -1 || show.release_weekday > 7) {
        show.release_weekday = -1;
    }
    showValues.put(Shows.RELEASE_WEEKDAY, show.release_weekday);
    showValues.put(Shows.RELEASE_TIMEZONE, show.release_timezone);
    showValues.put(Shows.RELEASE_COUNTRY, show.country);
    showValues.put(Shows.LASTWATCHEDID, show.last_watched_episode);
    showValues.put(Shows.LASTWATCHED_MS, show.last_watched_ms);
    showValues.put(Shows.POSTER, show.poster);
    showValues.put(Shows.CONTENTRATING, show.content_rating);
    if (show.runtime < 0) {
        show.runtime = 0;
    }
    showValues.put(Shows.RUNTIME, show.runtime);
    showValues.put(Shows.NETWORK, show.network);
    showValues.put(Shows.IMDBID, show.imdb_id);
    if (show.trakt_id != null && show.trakt_id > 0) {
        showValues.put(Shows.TRAKT_ID, show.trakt_id);
    }
    showValues.put(Shows.FIRST_RELEASE, show.first_aired);
    if (show.rating_user < 0 || show.rating_user > 10) {
        show.rating_user = 0;
    }
    showValues.put(Shows.RATING_USER, show.rating_user);
    showValues.put(Shows.STATUS, DataLiberationTools.encodeShowStatus(show.status));
    // Full dump values
    showValues.put(Shows.OVERVIEW, show.overview);
    if (show.rating < 0 || show.rating > 10) {
        show.rating = 0;
    }
    showValues.put(Shows.RATING_GLOBAL, show.rating);
    if (show.rating_votes < 0) {
        show.rating_votes = 0;
    }
    showValues.put(Shows.RATING_VOTES, show.rating_votes);
    showValues.put(Shows.GENRES, show.genres);
    if (show.last_updated > System.currentTimeMillis()) {
        show.last_updated = 0;
    }
    showValues.put(Shows.LASTUPDATED, show.last_updated);
    showValues.put(Shows.LASTEDIT, show.last_edited);
    context.getContentResolver().insert(Shows.CONTENT_URI, showValues);
    if (show.seasons == null || show.seasons.isEmpty()) {
        // no seasons (or episodes)
        return;
    }
    ContentValues[][] seasonsAndEpisodes = buildSeasonAndEpisodeBatches(show);
    if (seasonsAndEpisodes[0] != null && seasonsAndEpisodes[1] != null) {
        // Insert all seasons
        context.getContentResolver().bulkInsert(Seasons.CONTENT_URI, seasonsAndEpisodes[0]);
        // Insert all episodes
        context.getContentResolver().bulkInsert(Episodes.CONTENT_URI, seasonsAndEpisodes[1]);
    }
}
Also used : ContentValues(android.content.ContentValues)

Example 72 with ContentValues

use of android.content.ContentValues in project SeriesGuide by UweTrottmann.

the class MovieLoader method updateLocalMovie.

private static void updateLocalMovie(Context context, MovieDetails details, int tmdbId) {
    ContentValues values = MovieTools.buildBasicMovieContentValues(details);
    if (values.size() == 0) {
        // nothing to update, downloading probably failed :(
        return;
    }
    // if movie does not exist in database, will do nothing
    context.getContentResolver().update(Movies.buildMovieUri(tmdbId), values, null, null);
}
Also used : ContentValues(android.content.ContentValues)

Example 73 with ContentValues

use of android.content.ContentValues 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 74 with ContentValues

use of android.content.ContentValues in project SeriesGuide by UweTrottmann.

the class ShowsActivity method onUpgrade.

/**
     * Runs any upgrades necessary if coming from earlier versions.
     */
private void onUpgrade() {
    final int lastVersion = AppSettings.getLastVersionCode(this);
    final int currentVersion = BuildConfig.VERSION_CODE;
    if (lastVersion < currentVersion) {
        // user feedback about update
        Toast.makeText(getApplicationContext(), R.string.updated, Toast.LENGTH_LONG).show();
        // NOTE: see version codes for upgrade description.
        if (lastVersion < SgApp.RELEASE_VERSION_12_BETA5) {
            // flag all episodes as outdated
            ContentValues values = new ContentValues();
            values.put(SeriesGuideContract.Episodes.LAST_EDITED, 0);
            getContentResolver().update(SeriesGuideContract.Episodes.CONTENT_URI, values, null, null);
        // sync is triggered in last condition
        // (if we are in here we will definitely hit the ones below)
        }
        if (lastVersion < SgApp.RELEASE_VERSION_16_BETA1) {
            Utils.clearLegacyExternalFileCache(this);
        }
        if (lastVersion < SgApp.RELEASE_VERSION_23_BETA4) {
            // make next trakt sync download watched movies
            TraktSettings.resetMoviesLastActivity(this);
        }
        if (lastVersion < SgApp.RELEASE_VERSION_26_BETA3) {
            // flag all shows outdated so delta sync will pick up, if full sync gets aborted
            scheduleAllShowsUpdate();
            // force a sync
            SgSyncAdapter.requestSyncImmediate(this, SgSyncAdapter.SyncType.FULL, 0, true);
        }
        if (lastVersion < SgApp.RELEASE_VERSION_34_BETA4) {
            ActivityTools.populateShowsLastWatchedTime(this);
        }
        Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
        if (lastVersion < SgApp.RELEASE_VERSION_36_BETA2) {
            // used account name to determine sign-in state before switch to Google Sign-In
            if (!TextUtils.isEmpty(HexagonSettings.getAccountName(this))) {
                // tell users to sign in again
                editor.putBoolean(HexagonSettings.KEY_SHOULD_VALIDATE_ACCOUNT, true);
            }
        }
        // set this as lastVersion
        editor.putInt(AppSettings.KEY_VERSION, currentVersion);
        editor.apply();
    }
}
Also used : ContentValues(android.content.ContentValues) Editor(android.content.SharedPreferences.Editor)

Example 75 with ContentValues

use of android.content.ContentValues in project SeriesGuide by UweTrottmann.

the class ActivityTools method addActivity.

/**
     * Adds an activity entry for the given episode with the current time as timestamp. If an entry
     * already exists it is replaced.
     *
     * <p>Also cleans up old entries.
     */
public static void addActivity(Context context, int episodeTvdbId, int showTvdbId) {
    long timeMonthAgo = System.currentTimeMillis() - HISTORY_THRESHOLD;
    // delete all entries older than 30 days
    int deleted = context.getContentResolver().delete(Activity.CONTENT_URI, Activity.TIMESTAMP_MS + "<" + timeMonthAgo, null);
    Timber.d("addActivity: removed %d outdated activities", deleted);
    // add new entry
    ContentValues values = new ContentValues();
    values.put(Activity.EPISODE_TVDB_ID, episodeTvdbId);
    values.put(Activity.SHOW_TVDB_ID, showTvdbId);
    long currentTime = System.currentTimeMillis();
    values.put(Activity.TIMESTAMP_MS, currentTime);
    context.getContentResolver().insert(Activity.CONTENT_URI, values);
    Timber.d("addActivity: episode: %d timestamp: %d", episodeTvdbId, currentTime);
}
Also used : ContentValues(android.content.ContentValues)

Aggregations

ContentValues (android.content.ContentValues)3993 Cursor (android.database.Cursor)720 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)162 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteException (android.database.sqlite.SQLiteException)53 ContentProviderOperation (android.content.ContentProviderOperation)49