Search in sources :

Example 1 with Movie

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

the class JsonExportTask method writeJsonStreamMovies.

private void writeJsonStreamMovies(OutputStream out, Cursor movies) throws IOException {
    int numTotal = movies.getCount();
    int numExported = 0;
    Gson gson = new Gson();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.beginArray();
    while (movies.moveToNext()) {
        if (isCancelled()) {
            break;
        }
        Movie movie = new Movie();
        movie.tmdbId = movies.getInt(MoviesQuery.TMDB_ID);
        movie.imdbId = movies.getString(MoviesQuery.IMDB_ID);
        movie.title = movies.getString(MoviesQuery.TITLE);
        movie.releasedUtcMs = movies.getLong(MoviesQuery.RELEASED_UTC_MS);
        movie.runtimeMin = movies.getInt(MoviesQuery.RUNTIME_MIN);
        movie.poster = movies.getString(MoviesQuery.POSTER);
        movie.inCollection = movies.getInt(MoviesQuery.IN_COLLECTION) == 1;
        movie.inWatchlist = movies.getInt(MoviesQuery.IN_WATCHLIST) == 1;
        movie.watched = movies.getInt(MoviesQuery.WATCHED) == 1;
        if (isFullDump) {
            movie.overview = movies.getString(MoviesQuery.OVERVIEW);
        }
        gson.toJson(movie, Movie.class, writer);
        publishProgress(numTotal, ++numExported);
    }
    writer.endArray();
    writer.close();
}
Also used : Movie(com.battlelancer.seriesguide.dataliberation.model.Movie) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Example 2 with Movie

use of com.battlelancer.seriesguide.dataliberation.model.Movie 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

Movie (com.battlelancer.seriesguide.dataliberation.model.Movie)2 Gson (com.google.gson.Gson)2 SuppressLint (android.annotation.SuppressLint)1 List (com.battlelancer.seriesguide.dataliberation.model.List)1 Show (com.battlelancer.seriesguide.dataliberation.model.Show)1 JsonReader (com.google.gson.stream.JsonReader)1 JsonWriter (com.google.gson.stream.JsonWriter)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1