Beispiel #1
0
 private void sendMessage() {
   String message = etMessage.getText().toString();
   if (message.trim().isEmpty()) {
     UIUtils.alert(this, R.string.message_is_empty);
     return;
   }
   if (isSendSMS) {
     sendMessageToServer(
         Prefs.getSendSmsJSON(
             userID,
             mItem.getChatGroupID() != null ? mItem.getChatGroupID() : "",
             mItem.getMemberID() != null ? mItem.getMemberID() : "",
             mItem.getID(),
             Message.Type.CHAT_TYPE_SEND_SMS,
             message,
             DateUtils.nowTime(),
             token));
   } else {
     sendMessageToServer(
         Prefs.getSendMessageJSON(
             userID,
             mItem.getChatGroupID(),
             mItem.getMemberID(),
             Message.Type.CHAT_TYPE_MESSAGE,
             message,
             DateUtils.nowTime(),
             token));
   }
   etMessage.setText("");
 }
Beispiel #2
0
 private void sendMessageLocation(Location location) {
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID,
           mItem.getChatGroupID(),
           mItem.getMemberID(),
           Message.Type.CHAT_TYPE_LOCATION,
           location.getLatitude() + "," + location.getLongitude(),
           DateUtils.nowTime(),
           token));
 }
Beispiel #3
0
 private void sendMessageImage(String urlImage) {
   if (TextUtil.isEmpty(urlImage)) {
     UIUtils.alert(this, R.string.url_image_is_null);
     return;
   }
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID,
           mItem.getChatGroupID(),
           mItem.getMemberID(),
           Message.Type.CHAT_TYPE_IMAGE,
           urlImage,
           DateUtils.nowTime(),
           token));
   etMessage.setText("");
 }
Beispiel #4
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();
    }
  }