Beispiel #1
0
 public static List<NotifyMessage> getMessageListByResult(
     NetworkClientResult res, Account account) {
   JSONObject jo = res.getResponseResult();
   List<NotifyMessage> list = new ArrayList<NotifyMessage>();
   try {
     if (jo != null) {
       JSONArray ja = jo.getJSONArray("root");
       for (int i = 0; i < ja.length(); i++) {
         JSONObject mJson = ja.getJSONObject(i);
         NotifyMessage sm = createServiceMessage(mJson);
         sm.setBelongAccount(account);
         list.add(sm);
       }
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return list;
 }
  public void deleteMessage(
      final Context context, final NotifyMessage notifyMessage, final ITaskCallback callBack) {

    if (!isControllerValid()) return;

    Log.e(getClass().getSimpleName(), ">>>#执行删除操作");
    TaskPool.doMarkNotificationProcessTask(
        context,
        getAccountAttached().getAccessToken(),
        notifyMessage.getMessageId(),
        "D",
        new TaskHost() {
          @Override
          public void onPostExecute(int requestCode, BaseResult result) {
            super.onPostExecute(requestCode, result);
            switch (result.getErrorCode()) {
              case LocalCode.CODE_SUCCESS:
                Log.e(
                    getClass().getSimpleName(),
                    ">>>#删除前:" + getCache().size() + ">删除ID:" + notifyMessage.getId());
                Log.e(getClass().getSimpleName(), ">>>#参数:" + notifyMessage.hashCode());
                for (NotifyMessage msg : getCache().snapshot()) {
                  if (msg.isSameRecord(notifyMessage)) {
                    Log.e(getClass().getSimpleName(), ">>>#该记录在缓存中存在" + msg.hashCode());
                    msg.invalidate();
                    removeItemInCache(msg);
                    break;
                  }
                }
                Log.e(getClass().getSimpleName(), ">>>#删除成功,通知界面更新");
                Log.e(getClass().getSimpleName(), ">>>#删除后:" + getCache().size());
                break;
              default:
                Log.e(getClass().getSimpleName(), ">>>#删除失败");
                if (callBack != null) {
                  callBack.onComplete(result.getErrorCode(), null);
                }
                break;
            }
          }
        });
  }
Beispiel #3
0
  private static NotifyMessage parse(JSONObject jo, NotifyMessage am) {

    try {
      if (jo.has("messageid") && !jo.isNull("messageid")) {
        am.setMessageId(jo.getInt("messageid"));
      }
      if (jo.has("type") && !jo.isNull("type")) {
        am.setMessageType(jo.getInt("type"));
      }
      if (jo.has("sender") && !jo.isNull("sender")) {
        JSONObject mo = jo.getJSONObject("sender");

        JSONObject newJson = new JSONObject();
        newJson.put("sender", mo);
        am.setSender(newJson.toString().getBytes());

        if (mo.has("imagefile") && !mo.isNull("imagefile")) {
          am.setSenderImagefile(mo.getString("imagefile"));
        }
        if (mo.has("username") && !mo.isNull("username")) {
          am.setSenderName(mo.getString("username"));
        }
        if (mo.has("nickname") && !mo.isNull("nickname")) {
          am.setSenderNickname(mo.getString("nickname"));
        }
        if (mo.has("syncid") && !mo.isNull("syncid")) {
          am.setSenderId(mo.getInt("syncid"));
        }
      }
      if (jo.has("isread") && !jo.isNull("isread")) {
        String temp = jo.getString("isread");
        if (temp != null) {
          if (temp.equals("Y")) {
            am.setIsRead(true);
          } else {
            am.setIsRead(false);
          }
        }
      }
      if (jo.has("response") && !jo.isNull("response")) {

        String temp = jo.getString("response");
        if (temp.equals("Y")) am.setAcceptInvite(true);
        if (temp.equals("N")) am.setAcceptInvite(false);

        JSONObject newJson = new JSONObject();
        newJson.put("response", temp);
        am.setMessageResponse(newJson.toString().getBytes());
      }

      if (jo.has("data") && !jo.isNull("data")) {
        JSONObject mo = jo.getJSONObject("data");
        if (mo.has("group_title") && !mo.isNull("group_title")) {
          am.setGroupName(mo.getString("group_title"));
        }
        if (mo.has("group_id") && !mo.isNull("group_id")) {
          int groupid = Integer.valueOf(mo.getString("group_id"));
          am.setGroupId(groupid);
        }
        // 为了兼容v2.0的代码增加的解析方式
        if (mo.has("groupid") && !mo.isNull("groupid")) {
          int groupid = Integer.valueOf(mo.getString("groupid"));
          am.setGroupId(groupid);
        }
        if (mo.has("group_type") && !mo.isNull("group_type")) {
          am.setGroupType(mo.getInt("group_type"));
        }
        if (mo.has("perm") && !mo.isNull("perm")) {
          am.setPermType(mo.getString("perm"));
        }
        if (mo.has("code") && !mo.isNull("code")) {
          am.setPermCode(mo.getString("code"));
        }

        JSONObject newJson = new JSONObject();
        newJson.put("data", mo);
        am.setMessageResponse(newJson.toString().getBytes());
      }
      am.setStateFlag(STATE_SYNCHRONIZED);
      am.setActionFlag(ACTION_NORMAL);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return am;
  }