Exemplo n.º 1
0
  @Override
  public void restore(final JSONObject backup) {
    try {
      final List<BookSettings> list = new ArrayList<BookSettings>();
      final JSONArray books = backup.getJSONArray("books");
      if (LengthUtils.isNotEmpty(books)) {
        for (int i = 0, n = books.length(); i < n; i++) {
          final JSONObject obj = books.getJSONObject(i);
          list.add(new BookSettings(obj));
        }
      }

      if (deleteAll()) {
        restoreBookSettings(list);
      }
      SettingsManager.onRecentBooksChanged();
    } catch (final JSONException ex) {
      SettingsManager.LCTX.e("Error on recent book restoring: " + ex.getMessage());
    }
  }
Exemplo n.º 2
0
 @Override
 public JSONObject backup() {
   final BookBackupType backupType = BackupSettings.current().bookBackup;
   final JSONObject root = new JSONObject();
   if (backupType == BookBackupType.NONE) {
     return root;
   }
   try {
     final JSONArray books = new JSONArray();
     root.put("books", books);
     final Map<String, BookSettings> m =
         backupType == BookBackupType.RECENT ? getRecentBooks(true) : getAllBooks();
     for (final BookSettings bs : m.values()) {
       final JSONObject obj = bs.toJSON();
       books.put(obj);
     }
   } catch (final JSONException ex) {
     SettingsManager.LCTX.e("Error on recent book backup: " + ex.getMessage());
   }
   return root;
 }