private void cancelTransmission(Message message) {
   Transferable transferable = message.getTransferable();
   if (transferable != null) {
     transferable.cancel();
   } else {
     activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
   }
 }
Пример #2
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);
     }
   }
 }