Ejemplo n.º 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();
   }
 }
Ejemplo n.º 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) {

              }
            }
          }
        });
  }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 4
0
 @Override
 protected void onResume() {
   super.onResume();
   mBerimHeader.setTitle(mTalkee.getValidUserName());
   mChatNetworkListner.register();
 }