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();
}
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();
}
Aggregations