Search in sources :

Example 1 with AudioSlide

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

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    vibrator.vibrate(20);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(@NonNull final Pair<Uri, Long> result) {
            boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
            int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
            long expiresIn = recipient.getExpireMessages() * 1000L;
            boolean initiating = threadId == -1;
            AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true);
            SlideDeck slideDeck = new SlideDeck();
            slideDeck.addSlide(audioSlide);
            sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() {

                @Override
                public void onSuccess(Void nothing) {
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
                            return null;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Uri(android.net.Uri) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair)

Example 2 with AudioSlide

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

the class ConversationParentFragment method sendMessage.

private void sendMessage(@Nullable String metricId) {
    if (inputPanel.isRecordingInLockedMode()) {
        inputPanel.releaseRecordingLock();
        return;
    }
    Draft voiceNote = draftViewModel.getVoiceNoteDraft();
    if (voiceNote != null) {
        AudioSlide audioSlide = AudioSlide.createFromVoiceNoteDraft(requireContext(), voiceNote);
        sendVoiceNote(Objects.requireNonNull(audioSlide.getUri()), audioSlide.getFileSize());
        draftViewModel.clearVoiceNoteDraft();
        return;
    }
    try {
        Recipient recipient = getRecipient();
        if (recipient == null) {
            throw new RecipientFormattingException("Badly formatted");
        }
        String message = getMessage();
        TransportOption transport = sendButton.getSelectedTransport();
        boolean forceSms = (recipient.isForceSmsSelection() || sendButton.isManualSelection()) && transport.isSms();
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
        boolean initiating = threadId == -1;
        boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
        boolean isMediaMessage = attachmentManager.isAttachmentPresent() || recipient.isGroup() || recipient.getEmail().isPresent() || inputPanel.getQuote().isPresent() || composeText.hasMentions() || linkPreviewViewModel.hasLinkPreview() || needsSplit;
        Log.i(TAG, "[sendMessage] recipient: " + recipient.getId() + ", threadId: " + threadId + ",  forceSms: " + forceSms + ", isManual: " + sendButton.isManualSelection());
        if ((recipient.isMmsGroup() || recipient.getEmail().isPresent()) && !isMmsEnabled) {
            handleManualMmsRequired();
        } else if (!forceSms && (identityRecords.isUnverified(true) || identityRecords.isUntrusted(true))) {
            handleRecentSafetyNumberChange();
        } else if (isMediaMessage) {
            sendMediaMessage(forceSms, expiresIn, false, subscriptionId, initiating, metricId);
        } else {
            sendTextMessage(forceSms, expiresIn, subscriptionId, initiating, metricId);
        }
    } catch (RecipientFormattingException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation, Toast.LENGTH_LONG).show();
        Log.w(TAG, ex);
    } catch (InvalidMessageException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_message_is_empty_exclamation, Toast.LENGTH_SHORT).show();
        Log.w(TAG, ex);
    }
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) SuppressLint(android.annotation.SuppressLint)

Example 3 with AudioSlide

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

the class VoiceNoteMediaItemFactory method buildMediaItem.

/**
 * Build out a MediaItem for a given voice note. Expects to be run
 * on a background thread.
 *
 * @param context       Context.
 * @param messageRecord The MessageRecord of the given voice note.
 * @return A MediaItem with all the details the service expects.
 */
@WorkerThread
@Nullable
static MediaItem buildMediaItem(@NonNull Context context, @NonNull MessageRecord messageRecord) {
    int startingPosition = SignalDatabase.mmsSms().getMessagePositionInConversation(messageRecord.getThreadId(), messageRecord.getDateReceived());
    Recipient threadRecipient = Objects.requireNonNull(SignalDatabase.threads().getRecipientForThreadId(messageRecord.getThreadId()));
    Recipient sender = messageRecord.isOutgoing() ? Recipient.self() : messageRecord.getIndividualRecipient();
    Recipient avatarRecipient = threadRecipient.isGroup() ? threadRecipient : sender;
    AudioSlide audioSlide = ((MmsMessageRecord) messageRecord).getSlideDeck().getAudioSlide();
    if (audioSlide == null) {
        Log.w(TAG, "Message does not have an audio slide. Can't play this voice note.");
        return null;
    }
    Uri uri = audioSlide.getUri();
    if (uri == null) {
        Log.w(TAG, "Audio slide does not have a URI. Can't play this voice note.");
        return null;
    }
    return buildMediaItem(context, threadRecipient, avatarRecipient, sender, startingPosition, messageRecord.getThreadId(), messageRecord.getId(), messageRecord.getDateReceived(), uri);
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 4 with AudioSlide

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

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(20);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(@NonNull final Pair<Uri, Long> result) {
            try {
                boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
                int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
                long expiresIn = recipients.getExpireMessages() * 1000;
                AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, ContentType.AUDIO_AAC);
                SlideDeck slideDeck = new SlideDeck();
                slideDeck.addSlide(audioSlide);
                sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId).addListener(new AssertedSuccessListener<Void>() {

                    @Override
                    public void onSuccess(Void nothing) {
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first);
                                return null;
                            }
                        }.execute();
                    }
                });
            } catch (InvalidMessageException e) {
                Log.w(TAG, e);
                Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_error_sending_voice_message, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Uri(android.net.Uri) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair)

Example 5 with AudioSlide

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

the class ConversationParentFragment method sendVoiceNote.

private void sendVoiceNote(@NonNull Uri uri, long size) {
    boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
    boolean initiating = threadId == -1;
    int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    AudioSlide audioSlide = new AudioSlide(requireContext(), uri, size, MediaUtil.AUDIO_AAC, true);
    SlideDeck slideDeck = new SlideDeck();
    slideDeck.addSlide(audioSlide);
    ListenableFuture<Void> sendResult = sendMediaMessage(recipient.getId(), forceSms, "", slideDeck, inputPanel.getQuote().orNull(), Collections.emptyList(), Collections.emptyList(), composeText.getMentions(), expiresIn, false, subscriptionId, initiating, true, null);
    sendResult.addListener(new AssertedSuccessListener<Void>() {

        @Override
        public void onSuccess(Void nothing) {
            draftViewModel.deleteBlob(uri);
        }
    });
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) SuppressLint(android.annotation.SuppressLint)

Aggregations

AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)5 Uri (android.net.Uri)3 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)3 SuppressLint (android.annotation.SuppressLint)2 Vibrator (android.os.Vibrator)2 Pair (android.util.Pair)2 ExecutionException (java.util.concurrent.ExecutionException)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 AssertedSuccessListener (org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener)2 ListenableFuture (org.thoughtcrime.securesms.util.concurrent.ListenableFuture)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SpannableString (android.text.SpannableString)1 Nullable (androidx.annotation.Nullable)1 WorkerThread (androidx.annotation.WorkerThread)1 TransportOption (org.thoughtcrime.securesms.TransportOption)1 VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)1 Draft (org.thoughtcrime.securesms.database.DraftDatabase.Draft)1 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)1 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)1