Exemplo n.º 1
0
  public void populateModule(JSONObject jsonObject) {

    try {
      if (jsonObject != null) {

        String id = jsonObject.getString("id");
        this.setId(Integer.valueOf(id));
        String url = jsonObject.optString("url");
        if (url != null && url.trim().length() > 0) this.setUrl(url);
        String name = jsonObject.optString("name");
        if (name != null && name.trim().length() > 0) this.setName(name);
        String description = jsonObject.optString("description");
        if (description != null && description.trim().length() > 0)
          this.setDescription(description);
        String visible = jsonObject.optString("visible");
        if (visible != null && visible.trim().length() > 0)
          this.setVisible(Integer.valueOf(visible));
        String modicon = jsonObject.optString("modicon");
        if (modicon != null && modicon.trim().length() > 0) this.setModIcon(modicon);
        String modname = jsonObject.optString("modname");
        if (modname != null && modname.trim().length() > 0) this.setModName(modname);
        String modplural = jsonObject.optString("modplural");
        if (modplural != null && modplural.trim().length() > 0) this.setModPlural(modplural);
        String availablefrom = jsonObject.optString("availablefrom");
        if (availablefrom != null && availablefrom.trim().length() > 0)
          this.setAvailableFrom(Integer.valueOf(availablefrom));
        String availableuntil = jsonObject.optString("availableuntil");
        if (availableuntil != null && availableuntil.trim().length() > 0)
          this.setAvailableUntil(Integer.valueOf(availableuntil));
        String indent = jsonObject.optString("indent");
        if (indent != null && indent.trim().length() > 0) this.setIndent(Integer.valueOf(indent));

        JSONArray contents = jsonObject.getJSONArray("contents");
        ArrayList<Content> contentsArray = new ArrayList<Content>();
        // looping through all Contents
        for (int i = 0; i < contents.length(); i++) {
          JSONObject c = contents.getJSONObject(i);
          Content content = new Content();
          content.populateContent(c);
          // Toast.makeText(context.getApplicationContext(), course.getShortName(),
          // Toast.LENGTH_LONG).show();
          // Storing each json item in variable
          contentsArray.add(content);
        }

        if (contentsArray.size() > 0) {
          this.setContents(contentsArray);
        }
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }