Search in sources :

Example 1 with AssertedSuccessListener

use of org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener 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)

Aggregations

Uri (android.net.Uri)1 Vibrator (android.os.Vibrator)1 Pair (android.util.Pair)1 ExecutionException (java.util.concurrent.ExecutionException)1 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)1 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)1 AssertedSuccessListener (org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener)1 ListenableFuture (org.thoughtcrime.securesms.util.concurrent.ListenableFuture)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1