Exemple #1
0
 private void requestCheckSocket() {
   CallServicePOST cs =
       new CallServicePOST(
           "checkSocket",
           new CallServicePOST.JsonCallback() {
             @Override
             public void handleData(String mCmd, JSONObject json) throws JSONException {
               if (json != null) {
                 Log.d(TAG, "socket:\n" + json.toString());
               }
             }
           });
   cs.execute(RemoteMethods.startLiefChatSocket);
 }
Exemple #2
0
  private void requestGetListChat() {
    CallServicePOST cs =
        new CallServicePOST(
            "getListChat",
            new CallServicePOST.JsonCallback() {
              @Override
              public void handleData(String mCmd, JSONObject json) throws JSONException {
                if (json != null) {
                  int status = json.getInt("status");
                  if (status == 1) {
                    JSONArray jArray = json.getJSONArray("data");

                    for (int i = 0; i < jArray.length(); i++) {
                      JSONObject info = jArray.getJSONObject(i);
                      Message message = Message.parseMassge(info);
                      message.setSendout(message.getSenderId().equals(userID));
                      Log.d(TAG + ":check", "message send out: " + message.isSendout());
                      appendMessageToTop(message);
                      lastMessageTime = message.getUnix_timestamp();
                    }
                    if (mAdapter != null) {
                      mAdapter.notifyDataSetChanged();
                      lvMessages.setSelection(mAdapter.getCount() - 1);
                    }
                    if (mItem.isNewChat()) {
                      sendBroadcastReadChat();
                      mItem.setNewChat(false);
                    }

                    //						if (isSendSMS && mAdapter.getCount() > 0) {
                    //							findViewById(R.id.layoutCall).setVisibility(View.VISIBLE);
                    //						}

                    //						if (jArray != null) {
                    //							enableGetMore = (jArray.length() < Values.LIMIT_GET_LIST_TRAVELERS) ?
                    // false : true;
                    //						}
                    hideLayoutNote();
                  } else {
                    try {
                      String errorCode = json.get("errorCode").toString();
                      if (errorCode.equals(CallServicePOST.ErrorCode.CONNECT_SERVER_FAIL)) {
                        UIUtils.alert(
                            ChatScreen.this,
                            R.string.connect_to_server_failed_plz_wait_a_moment_and_try_again);
                      } else {
                        if (listMessages != null && listMessages.size() > 0) {
                          Log.d(TAG + ":handleData", "ERROR " + errorCode + " !!");
                        } else {
                          UIUtils.alert(ChatScreen.this, "ERROR " + errorCode + " !!");
                        }
                      }
                    } catch (Exception e) {
                      Log.d(TAG + ":handleData", e.getMessage());
                    }
                  }
                }
                hideLoading();
                stopSwipeRefresh();
              }
            });

    try {
      String url =
          RemoteMethods.get(
              RemoteMethods.getChatConversation,
              URLEncoder.encode(userID, "UTF-8"),
              URLEncoder.encode(
                  TextUtil.isEmpty(mItem.getChatGroupID()) ? mItem.getID() : mItem.getChatGroupID(),
                  "UTF-8"),
              Values.LIMIT_GET_LIST_CHAT);
      if (lastMessageTime != null) {
        url += "&currentTime=" + lastMessageTime;
      }
      cs.execute(url);
    } catch (Exception e) {
      hideLoading();
    }
  }