public void updateMessages() {
   synchronized (this.messageList) {
     if (getView() == null) {
       return;
     }
     final ConversationActivity activity = (ConversationActivity) getActivity();
     if (this.conversation != null) {
       updateSnackBar(this.conversation);
       conversation.populateWithMessages(ConversationFragment.this.messageList);
       for (final Message message : this.messageList) {
         if (message.getEncryption() == Message.ENCRYPTION_PGP
             && (message.getStatus() == Message.STATUS_RECEIVED
                 || message.getStatus() >= Message.STATUS_SEND)
             && message.getTransferable() == null) {
           if (!mEncryptedMessages.contains(message)) {
             mEncryptedMessages.add(message);
           }
         }
       }
       decryptNext();
       updateStatusMessages();
       this.messageListAdapter.notifyDataSetChanged();
       updateChatMsgHint();
       if (!activity.isConversationsOverviewVisable()
           || !activity.isConversationsOverviewHideable()) {
         activity.sendReadMarkerIfNecessary(conversation);
       }
       this.updateSendButton();
     }
   }
 }
 private void populateContextMenu(ContextMenu menu) {
   final Message m = this.selectedMessage;
   if (m.getType() != Message.TYPE_STATUS) {
     activity.getMenuInflater().inflate(R.menu.message_context, menu);
     menu.setHeaderTitle(R.string.message_options);
     MenuItem copyText = menu.findItem(R.id.copy_text);
     MenuItem shareWith = menu.findItem(R.id.share_with);
     MenuItem sendAgain = menu.findItem(R.id.send_again);
     MenuItem copyUrl = menu.findItem(R.id.copy_url);
     MenuItem downloadFile = menu.findItem(R.id.download_file);
     MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
     if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
         && m.getTransferable() == null
         && !GeoHelper.isGeoUri(m.getBody())
         && m.treatAsDownloadable() != Message.Decision.MUST) {
       copyText.setVisible(true);
     }
     if ((m.getType() != Message.TYPE_TEXT
             && m.getType() != Message.TYPE_PRIVATE
             && m.getTransferable() == null)
         || (GeoHelper.isGeoUri(m.getBody()))) {
       shareWith.setVisible(true);
     }
     if (m.getStatus() == Message.STATUS_SEND_FAILED) {
       sendAgain.setVisible(true);
     }
     if (m.hasFileOnRemoteHost()
         || GeoHelper.isGeoUri(m.getBody())
         || m.treatAsDownloadable() == Message.Decision.MUST) {
       copyUrl.setVisible(true);
     }
     if (m.getType() == Message.TYPE_TEXT
         && m.getTransferable() == null
         && m.treatAsDownloadable() != Message.Decision.NEVER) {
       downloadFile.setVisible(true);
       downloadFile.setTitle(
           activity.getString(
               R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
     }
     if ((m.getTransferable() != null && !(m.getTransferable() instanceof TransferablePlaceholder))
         || (m.isFileOrImage()
             && (m.getStatus() == Message.STATUS_WAITING
                 || m.getStatus() == Message.STATUS_OFFERED))) {
       cancelTransmission.setVisible(true);
     }
   }
 }
 private void cancelTransmission(Message message) {
   Transferable transferable = message.getTransferable();
   if (transferable != null) {
     transferable.cancel();
   } else {
     activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
   }
 }
Exemplo n.º 4
0
 public static Pair<String, Boolean> getMessagePreview(
     final Context context, final Message message) {
   final Transferable d = message.getTransferable();
   if (d != null) {
     switch (d.getStatus()) {
       case Transferable.STATUS_CHECKING:
         return new Pair<>(
             context.getString(R.string.checking_x, getFileDescriptionString(context, message)),
             true);
       case Transferable.STATUS_DOWNLOADING:
         return new Pair<>(
             context.getString(
                 R.string.receiving_x_file,
                 getFileDescriptionString(context, message),
                 d.getProgress()),
             true);
       case Transferable.STATUS_OFFER:
       case Transferable.STATUS_OFFER_CHECK_FILESIZE:
         return new Pair<>(
             context.getString(
                 R.string.x_file_offered_for_download, getFileDescriptionString(context, message)),
             true);
       case Transferable.STATUS_DELETED:
         return new Pair<>(context.getString(R.string.file_deleted), true);
       case Transferable.STATUS_FAILED:
         return new Pair<>(context.getString(R.string.file_transmission_failed), true);
       case Transferable.STATUS_UPLOADING:
         if (message.getStatus() == Message.STATUS_OFFERED) {
           return new Pair<>(
               context.getString(
                   R.string.offering_x_file, getFileDescriptionString(context, message)),
               true);
         } else {
           return new Pair<>(
               context.getString(
                   R.string.sending_x_file, getFileDescriptionString(context, message)),
               true);
         }
       default:
         return new Pair<>("", false);
     }
   } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
     return new Pair<>(context.getString(R.string.encrypted_message_received), true);
   } else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
     if (message.getStatus() == Message.STATUS_RECEIVED) {
       return new Pair<>(
           context.getString(R.string.received_x_file, getFileDescriptionString(context, message)),
           true);
     } else {
       return new Pair<>(getFileDescriptionString(context, message), true);
     }
   } else {
     if (message.getBody().startsWith(Message.ME_COMMAND)) {
       return new Pair<>(
           message
               .getBody()
               .replaceAll(
                   "^" + Message.ME_COMMAND, UIHelper.getMessageDisplayName(message) + " "),
           false);
     } else if (GeoHelper.isGeoUri(message.getBody())) {
       if (message.getStatus() == Message.STATUS_RECEIVED) {
         return new Pair<>(context.getString(R.string.received_location), true);
       } else {
         return new Pair<>(context.getString(R.string.location), true);
       }
     } else {
       return new Pair<>(message.getBody().trim(), false);
     }
   }
 }