コード例 #1
0
 public void loadMessages() {
   ArrayList<Message> messages =
       DatabaseHelper.getInstance(mContext)
           .getMessage(
               true,
               DatabaseHelper.ROOM_ID
                   + "='"
                   + mTalkee.getRoomId()
                   + "' or ("
                   + DatabaseHelper.SENDER_ROOM_ID
                   + "='"
                   + mTalkee.getRoomId()
                   + "' and "
                   + DatabaseHelper.ROOM_ID
                   + "='"
                   + mMe.getRoomId()
                   + "')");
   mMessages.addAll(messages);
   mAdapter.notifyDataSetChanged();
   mMessageInput.setText("");
   try {
     seenMessagesOnServer(messages, true);
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
  public void seenMessagesOnServer(final ArrayList<Message> messages, final boolean retry)
      throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status", "seen");
    JSONArray messageIdArray = new JSONArray();
    for (Message message : messages) {
      if (message.getSender().getId() != mMe.getId()) {
        messageIdArray.put(message.getId());
      }
    }
    jsonObject.put("messages", messageIdArray);
    if (messageIdArray.length() == 0) {
      return;
    }
    NetworkManager.sendRequest(
        MethodsName.bULK_CHANGE_MESSAGE_STATUS_GOT,
        jsonObject,
        new NetworkReceiver() {
          @Override
          public void onResponse(Object response) {
            // message seen in server side
          }

          @Override
          public void onErrorResponse(BerimNetworkException error) {
            if (retry) {
              try {
                seenMessagesOnServer(messages, false);
              } catch (JSONException e) {

              }
            }
          }
        });
  }
コード例 #3
0
 public void addMessage(Message message) {
   // add message to list
   mMessages.add(message);
   mAdapter.notifyDataSetChanged();
   mMessageInput.setText("");
   if (message.getSender().getId().equals(mMe.getId())) {
     DatabaseHelper.getInstance(mContext).InsertMessageNoUpdate(message);
   }
 }
コード例 #4
0
 @Override
 protected void onResume() {
   super.onResume();
   mBerimHeader.setTitle(mTalkee.getValidUserName());
   mChatNetworkListner.register();
 }