use of com.battlelancer.seriesguide.dataliberation.model.List in project SeriesGuide by UweTrottmann.
the class JsonExportTask method writeJsonStreamLists.
private void writeJsonStreamLists(OutputStream out, Cursor lists) throws IOException {
int numTotal = lists.getCount();
int numExported = 0;
Gson gson = new Gson();
JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
writer.beginArray();
while (lists.moveToNext()) {
if (isCancelled()) {
break;
}
List list = new List();
list.listId = lists.getString(ListsQuery.ID);
list.name = lists.getString(ListsQuery.NAME);
list.order = lists.getInt(ListsQuery.ORDER);
addListItems(list);
gson.toJson(list, List.class, writer);
publishProgress(numTotal, ++numExported);
}
writer.endArray();
writer.close();
}
use of com.battlelancer.seriesguide.dataliberation.model.List 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