Search in sources :

Example 1 with MediaType

use of org.thoughtcrime.securesms.mms.SlideFactory.MediaType in project Signal-Android by signalapp.

the class ConversationParentFragment method initializeDraft.

// /// Initializers
private ListenableFuture<Boolean> initializeDraft(@NonNull ConversationIntents.Args args) {
    final SettableFuture<Boolean> result = new SettableFuture<>();
    final CharSequence draftText = args.getDraftText();
    final Uri draftMedia = requireActivity().getIntent().getData();
    final String draftContentType = requireActivity().getIntent().getType();
    final MediaType draftMediaType = MediaType.from(draftContentType);
    final List<Media> mediaList = args.getMedia();
    final StickerLocator stickerLocator = args.getStickerLocator();
    final boolean borderless = args.isBorderless();
    if (stickerLocator != null && draftMedia != null) {
        Log.d(TAG, "Handling shared sticker.");
        sendSticker(stickerLocator, Objects.requireNonNull(draftContentType), draftMedia, 0, true);
        return new SettableFuture<>(false);
    }
    if (draftMedia != null && draftContentType != null && borderless) {
        SimpleTask.run(getLifecycle(), () -> getKeyboardImageDetails(draftMedia), details -> sendKeyboardImage(draftMedia, draftContentType, details));
        return new SettableFuture<>(false);
    }
    if (!Util.isEmpty(mediaList)) {
        Log.d(TAG, "Handling shared Media.");
        Intent sendIntent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), mediaList, recipient.getId(), draftText);
        startActivityForResult(sendIntent, MEDIA_SENDER);
        return new SettableFuture<>(false);
    }
    if (draftText != null) {
        composeText.setText("");
        composeText.append(draftText);
        result.set(true);
    }
    if (draftMedia != null && draftMediaType != null) {
        Log.d(TAG, "Handling shared Data.");
        return setMedia(draftMedia, draftMediaType);
    }
    if (draftText == null && draftMedia == null && draftMediaType == null) {
        return initializeDraftFromDatabase();
    } else {
        updateToggleButtonState();
        result.set(false);
    }
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Media(org.thoughtcrime.securesms.mediasend.Media) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) MediaType(org.thoughtcrime.securesms.mms.SlideFactory.MediaType) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Uri(android.net.Uri)

Example 2 with MediaType

use of org.thoughtcrime.securesms.mms.SlideFactory.MediaType in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeDraft.

// /// Initializers
private ListenableFuture<Boolean> initializeDraft(@NonNull ConversationIntents.Args args) {
    final SettableFuture<Boolean> result = new SettableFuture<>();
    final CharSequence draftText = args.getDraftText();
    final Uri draftMedia = requireActivity().getIntent().getData();
    final String draftContentType = requireActivity().getIntent().getType();
    final MediaType draftMediaType = MediaType.from(draftContentType);
    final List<Media> mediaList = args.getMedia();
    final StickerLocator stickerLocator = args.getStickerLocator();
    final boolean borderless = args.isBorderless();
    if (stickerLocator != null && draftMedia != null) {
        Log.d(TAG, "Handling shared sticker.");
        sendSticker(stickerLocator, Objects.requireNonNull(draftContentType), draftMedia, 0, true);
        return new SettableFuture<>(false);
    }
    if (draftMedia != null && draftContentType != null && borderless) {
        SimpleTask.run(getLifecycle(), () -> getKeyboardImageDetails(draftMedia), details -> sendKeyboardImage(draftMedia, draftContentType, details));
        return new SettableFuture<>(false);
    }
    if (!Util.isEmpty(mediaList)) {
        Log.d(TAG, "Handling shared Media.");
        Intent sendIntent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), mediaList, recipient.getId(), draftText);
        startActivityForResult(sendIntent, MEDIA_SENDER);
        return new SettableFuture<>(false);
    }
    if (draftText != null) {
        composeText.setText("");
        composeText.append(draftText);
        result.set(true);
    }
    if (draftMedia != null && draftMediaType != null) {
        Log.d(TAG, "Handling shared Data.");
        return setMedia(draftMedia, draftMediaType);
    }
    if (draftText == null && draftMedia == null && draftMediaType == null) {
        return initializeDraftFromDatabase();
    } else {
        updateToggleButtonState();
        result.set(false);
    }
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Media(org.thoughtcrime.securesms.mediasend.Media) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) MediaType(org.thoughtcrime.securesms.mms.SlideFactory.MediaType) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Uri(android.net.Uri)

Aggregations

PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 SpannableString (android.text.SpannableString)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Media (org.thoughtcrime.securesms.mediasend.Media)2 MediaType (org.thoughtcrime.securesms.mms.SlideFactory.MediaType)2 StickerLocator (org.thoughtcrime.securesms.stickers.StickerLocator)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2