Search in sources :

Example 1 with List

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();
}
Also used : Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(com.battlelancer.seriesguide.dataliberation.model.List) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Example 2 with List

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

List (com.battlelancer.seriesguide.dataliberation.model.List)2 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Movie (com.battlelancer.seriesguide.dataliberation.model.Movie)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