Ejemplo n.º 1
0
  private void sendMessage() {
    // do not submit blank lines
    String messageBody = messageBox.getText().toString().trim();
    if (messageBody.isEmpty()) {
      return;
    }

    // send the message to server and clear message box
    worker.sendMessages(chatId, messageBody);
    messageBox.setText("");
  }
Ejemplo n.º 2
0
  /** ************************ ListFragment Overrides * ************************ */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle arguments = getArguments();
    if (arguments.containsKey(ARG_ITEM_ID)) {
      chatId = (String) arguments.get(ARG_ITEM_ID);
      Optional<Chat> chat = userProfile.getChat(chatId);
      if (chat.isPresent() && !chat.get().messages.isEmpty()) {
        messageAdapter =
            new MessageListArrayAdapter(getActivity(), new ArrayList<>(chat.get().messages));
      } else {
        messageAdapter = new MessageListArrayAdapter(getActivity());
        worker.getChatMessages(chatId);
      }
      setListAdapter(messageAdapter);
    }
  }