예제 #1
0
 private void removeUser() {
   showLoading();
   CallServiceCustomPOST csPost =
       new CallServiceCustomPOST(
           "removeUser",
           userID,
           token,
           deviceId,
           version,
           locale,
           new JsonCallback() {
             @Override
             public void handleData(String mCmd, JSONObject json) throws JSONException {
               if (json != null) {
                 int status = json.getInt("status");
                 if (status == 1) {
                   sendBroadcastUpdateLovedOneAfterRemoved(mItem);
                   finish();
                 } else {
                   try {
                     String errorCode = json.get("errorCode").toString();
                     if (errorCode.equals(CallServiceCustomPOST.ErrorCode.CONNECT_SERVER_FAIL)) {
                       UIUtils.alert(
                           ChatScreen.this,
                           R.string.connect_to_server_failed_plz_wait_a_moment_and_try_again);
                     } else {
                       UIUtils.alert(ChatScreen.this, "Error " + errorCode);
                     }
                   } catch (Exception e) {
                     UIUtils.alert(ChatScreen.this, e.getMessage());
                     Log.d(TAG, json.toString());
                   }
                 }
               }
               hideLoading();
             }
           });
   try {
     String url =
         RemoteMethods.get(
             RemoteMethods.removeUser,
             URLEncoder.encode(userID, "UTF-8"),
             URLEncoder.encode(mItem.getID(), "UTF-8"));
     csPost.execute(url);
   } catch (Exception e) {
     e.printStackTrace();
     hideLoading();
   }
 }
예제 #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();
    }
  }