Пример #1
0
  public void setAll(String json) {
    albums = new HashMap<String, JSONObject>();
    images = new HashMap<String, Map<String, JSONObject>>();

    try {
      JSONArray jAlbums = new JSONArray(json);

      String albumId;
      JSONObject jo;

      for (int i = 0; i < jAlbums.length(); i++) {
        jo = jAlbums.getJSONObject(i);

        if (!jo.has("id")) {
          error.fire(new ErrorEvent("Error, object does not contain albums"));
        }

        albumId = jo.getString("id");

        images.put(albumId, new HashMap<String, JSONObject>());
        if (jo.getInt("size") > 0) {
          storeImagesToAlbum(albumId, jo.getJSONArray("images"));
          jo.remove("images");
        }
        albums.put(albumId, jo);
      }
      loaded = true;
      emptyCache = jAlbums.length() == 0;
    } catch (JSONException e) {
      error.fire(new ErrorEvent("Error: ", e.getMessage()));
    }
  }
Пример #2
0
  public void storeImagesToAlbum(String albumId, JSONArray ja) {
    String imageId = "";
    JSONObject jo;
    Map<String, JSONObject> album = images.get(albumId);

    try {
      for (int i = 0; i < ja.length(); i++) {
        jo = ja.getJSONObject(i);

        if (!jo.has("id")) {
          error.fire(new ErrorEvent("Error, object does not contain images"));
        }

        imageId = jo.getString("id");

        album.put(imageId, jo);
      }
    } catch (JSONException je) {
      error.fire(new ErrorEvent("Error", je.getMessage()));
    }
  }