Пример #1
0
  static Comment parseCommentReplyResponse(String json) throws JSONException {
    // {"result":{"1":{"1":"REPLY","3":"TIME_STAMP"},"2":true},"xsrf":"XSRF_TOKEN"}
    // or
    // {"error":{"data":{"1":ERROR_CODE},"code":ERROR_CODE}}
    JSONObject jsonObj = new JSONObject(json);
    if (jsonObj.has("error")) {
      throw parseError(jsonObj, "replying to comments");
    }
    JSONObject replyObj = jsonObj.getJSONObject("result").getJSONObject("1");

    Comment result = new Comment(true);
    result.setText(replyObj.getString("1"));
    result.setDate(parseDate(Long.parseLong(replyObj.getString("3"))));

    return result;
  }
Пример #2
0
  public void showReplyDialog(Comment comment) {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(REPLY_DIALOG_FRAGMENT);
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);

    ReplyDialog replyDialog = new ReplyDialog();

    Bundle args = new Bundle();
    args.putString(ReplyDialog.ARG_UNIQUE_ID, comment.getUniqueId());
    args.putString(
        ReplyDialog.ARG_REPLY, comment.getReply() == null ? "" : comment.getReply().getText());

    replyDialog.setArguments(args);

    replyDialog.show(ft, REPLY_DIALOG_FRAGMENT);
  }
Пример #3
0
  /**
   * Parses the supplied JSON string and returns a list of comments.
   *
   * @param json
   * @return
   * @throws JSONException
   */
  static List<Comment> parseComments(String json) throws JSONException {
    List<Comment> comments = new ArrayList<Comment>();
    /*
     * null
     * Array containing arrays of comments
     * numberOfComments
     */
    JSONArray jsonComments = new JSONObject(json).getJSONObject("result").getJSONArray("1");
    int count = jsonComments.length();
    for (int i = 0; i < count; i++) {
      Comment comment = new Comment();
      JSONObject jsonComment = jsonComments.getJSONObject(i);
      // TODO These examples are out of date and need updating
      /*
       * null
       * "gaia:17919762185957048423:1:vm:11887109942373535891", -- ID?
       * "REVIEWERS_NAME",
       * "1343652956570", -- DATE?
       * RATING,
       * null
       * "COMMENT",
       * null,
       * "VERSION_NAME",
       * [ null,
       * "DEVICE_CODE_NAME",
       * "DEVICE_MANFACTURER",
       * "DEVICE_MODEL"
       * ],
       * "LOCALE",
       * null,
       * 0
       */
      // Example with developer reply
      /*
       * [
       * null,
       * "gaia:12824185113034449316:1:vm:18363775304595766012",
       * "Micka�l",
       * "1350333837326",
       * 1,
       * "",
       * "Nul\tNul!! N'arrive pas a scanner le moindre code barre!",
       * 73,
       * "3.2.5",
       * [
       * null,
       * "X10i",
       * "SEMC",
       * "Xperia X10"
       * ],
       * "fr_FR",
       * [
       * null,
       * "Prixing fonctionne pourtant bien sur Xperia X10. Essayez de prendre un minimum de recul, au moins 20 � 30cm, �vitez les ombres et les reflets. N'h�sitez pas � nous �crire sur [email protected] pour une assistance personnalis�e."
       * ,
       * null,
       * "1350393460968"
       * ],
       * 1
       * ]
       */
      String uniqueId = jsonComment.getString("1");
      comment.setUniqueId(uniqueId);
      String user = jsonComment.optString("2");
      if (user != null && !"".equals(user) && !"null".equals(user)) {
        comment.setUser(user);
      }
      comment.setDate(parseDate(jsonComment.getLong("3")));
      comment.setRating(jsonComment.getInt("4"));
      String version = jsonComment.optString("7");
      if (version != null && !"".equals(version) && !version.equals("null")) {
        comment.setAppVersion(version);
      }

      JSONObject jsonCommentReview = jsonComment.optJSONObject("5");
      String commentLang = jsonCommentReview.getString("1");
      String commentText = jsonCommentReview.getString("3");
      String commentTitle = jsonCommentReview.getString("2");

      if (commentTitle.length() == 0) {
        // Title field is empty, see if the title is part of the comment text
        String originalTitleAndComment[] = commentText.split("\\t");
        if (originalTitleAndComment.length == 2) {
          commentTitle = originalTitleAndComment[0];
          commentText = originalTitleAndComment[1];
        }
      }

      comment.setLanguage(commentLang);
      comment.setOriginalText(commentText);
      // overwritten if translation is available
      comment.setText(commentText);
      comment.setOriginalTitle(commentTitle);
      comment.setTitle(commentTitle);

      JSONObject translation = jsonComment.optJSONObject("11");
      if (translation != null) {
        String displayLanguage = Locale.getDefault().getLanguage();
        String translationLang = translation.getString("1");

        if (translation.has("2")) {
          String translationTitle = translation.getString("2");
          if (translationLang.contains(displayLanguage)) {
            comment.setTitle(translationTitle);
          }
        }
        // Apparently, a translation body is not always provided
        // Possibly happens if the translation fails or equals the original
        if (translation.has("3")) {
          String translationText = translation.getString("3");
          if (translationLang.contains(displayLanguage)) {
            comment.setText(translationText);
          }
        }
      }

      JSONObject jsonDevice = jsonComment.optJSONObject("8");
      if (jsonDevice != null) {
        String device = jsonDevice.optString("3");
        JSONArray extraInfo = jsonDevice.optJSONArray("2");
        if (extraInfo != null) {
          device += " " + extraInfo.optString(0);
        }
        comment.setDevice(device.trim());
      }

      JSONObject jsonReply = jsonComment.optJSONObject("9");
      if (jsonReply != null) {
        Comment reply = new Comment(true);
        reply.setText(jsonReply.getString("1"));
        reply.setDate(parseDate(jsonReply.getLong("3")));
        reply.setOriginalCommentDate(comment.getDate());
        comment.setReply(reply);
      }

      comments.add(comment);
    }

    return comments;
  }
Пример #4
0
  /**
   * Parses the supplied JSON string and returns a list of comments.
   *
   * @param json
   * @return
   * @throws JSONException
   */
  static List<Comment> parseComments(String json) throws JSONException {
    List<Comment> comments = new ArrayList<Comment>();
    /*
     * null
     * Array containing arrays of comments
     * numberOfComments
     */
    JSONArray jsonComments = new JSONObject(json).getJSONObject("result").getJSONArray("1");
    int count = jsonComments.length();
    for (int i = 0; i < count; i++) {
      Comment comment = new Comment();
      JSONObject jsonComment = jsonComments.getJSONObject(i);
      // TODO These examples are out of date and need updating
      /*
       * null
       * "gaia:17919762185957048423:1:vm:11887109942373535891", -- ID?
       * "REVIEWERS_NAME",
       * "1343652956570", -- DATE?
       * RATING,
       * null
       * "COMMENT",
       * null,
       * "VERSION_NAME",
       * [ null,
       * "DEVICE_CODE_NAME",
       * "DEVICE_MANFACTURER",
       * "DEVICE_MODEL"
       * ],
       * "LOCALE",
       * null,
       * 0
       */
      // Example with developer reply
      /*
       * [
       * null,
       * "gaia:12824185113034449316:1:vm:18363775304595766012",
       * "Micka�l",
       * "1350333837326",
       * 1,
       * "",
       * "Nul\tNul!! N'arrive pas a scanner le moindre code barre!",
       * 73,
       * "3.2.5",
       * [
       * null,
       * "X10i",
       * "SEMC",
       * "Xperia X10"
       * ],
       * "fr_FR",
       * [
       * null,
       * "Prixing fonctionne pourtant bien sur Xperia X10. Essayez de prendre un minimum de recul, au moins 20 � 30cm, �vitez les ombres et les reflets. N'h�sitez pas � nous �crire sur [email protected] pour une assistance personnalis�e."
       * ,
       * null,
       * "1350393460968"
       * ],
       * 1
       * ]
       */
      String user = jsonComment.optString("2");
      if (user != null && !"".equals(user) && !"null".equals(user)) {
        comment.setUser(user);
      }
      comment.setDate(parseDate(jsonComment.getLong("3")));
      comment.setRating(jsonComment.getInt("4"));
      String version = jsonComment.optString("7");
      if (version != null && !"".equals(version) && !version.equals("null")) {
        comment.setAppVersion(version);
      }
      comment.setText(jsonComment.optJSONObject("5").getString("3"));
      JSONObject jsonDevice = jsonComment.optJSONObject("8");
      if (jsonDevice != null) {
        String device = jsonDevice.optString("3");
        JSONArray extraInfo = jsonDevice.optJSONArray("2");
        if (extraInfo != null) {
          device += " " + extraInfo.optString(0);
        }
        comment.setDevice(device.trim());
      }

      JSONArray jsonReply = jsonComment.optJSONArray("11");
      if (jsonReply != null) {
        Comment reply = new Comment(true);
        reply.setText(jsonReply.getString(1));
        reply.setReplyDate(parseDate(jsonReply.getLong(3)));
        reply.setDate(comment.getDate());
        comment.setReply(reply);
      }

      comments.add(comment);
    }

    return comments;
  }