Search in sources :

Example 1 with VoiceNoteDraft

use of org.thoughtcrime.securesms.components.voice.VoiceNoteDraft in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method onRecorderCanceled.

@Override
public void onRecorderCanceled() {
    voiceRecorderWakeLock.release();
    updateToggleButtonState();
    Vibrator vibrator = ServiceUtil.getVibrator(requireContext());
    vibrator.vibrate(50);
    requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    ListenableFuture<VoiceNoteDraft> future = audioRecorder.stopRecording();
    if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
        future.addListener(new DeleteCanceledVoiceNoteListener());
    } else {
        draftViewModel.setVoiceNoteDraftFuture(future);
    }
}
Also used : VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Vibrator(android.os.Vibrator)

Example 2 with VoiceNoteDraft

use of org.thoughtcrime.securesms.components.voice.VoiceNoteDraft in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method getDraftsForCurrentState.

private Drafts getDraftsForCurrentState() {
    Drafts drafts = new Drafts();
    if (recipient.get().isGroup() && !recipient.get().isActiveGroup()) {
        return drafts;
    }
    if (!Util.isEmpty(composeText)) {
        drafts.add(new Draft(Draft.TEXT, composeText.getTextTrimmed().toString()));
        List<Mention> draftMentions = composeText.getMentions();
        if (!draftMentions.isEmpty()) {
            drafts.add(new Draft(Draft.MENTION, Base64.encodeBytes(MentionUtil.mentionsToBodyRangeList(draftMentions).toByteArray())));
        }
    }
    for (Slide slide : attachmentManager.buildSlideDeck().getSlides()) {
        if (slide.hasAudio() && slide.getUri() != null)
            drafts.add(new Draft(Draft.AUDIO, slide.getUri().toString()));
        else if (slide.hasVideo() && slide.getUri() != null)
            drafts.add(new Draft(Draft.VIDEO, slide.getUri().toString()));
        else if (slide.hasLocation())
            drafts.add(new Draft(Draft.LOCATION, ((LocationSlide) slide).getPlace().serialize()));
        else if (slide.hasImage() && slide.getUri() != null)
            drafts.add(new Draft(Draft.IMAGE, slide.getUri().toString()));
    }
    Optional<QuoteModel> quote = inputPanel.getQuote();
    if (quote.isPresent()) {
        drafts.add(new Draft(Draft.QUOTE, new QuoteId(quote.get().getId(), quote.get().getAuthor()).serialize()));
    }
    Draft voiceNoteDraft = draftViewModel.getVoiceNoteDraft();
    if (voiceNoteDraft != null) {
        drafts.add(voiceNoteDraft);
    }
    return drafts;
}
Also used : LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) QuoteId(org.thoughtcrime.securesms.mms.QuoteId) Mention(org.thoughtcrime.securesms.database.model.Mention) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 3 with VoiceNoteDraft

use of org.thoughtcrime.securesms.components.voice.VoiceNoteDraft in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method saveDraft.

protected ListenableFuture<Long> saveDraft() {
    final SettableFuture<Long> future = new SettableFuture<>();
    if (this.recipient == null) {
        future.set(threadId);
        return future;
    }
    final Context context = requireContext().getApplicationContext();
    final Drafts drafts = getDraftsForCurrentState();
    final long thisThreadId = this.threadId;
    final RecipientId recipientId = this.recipient.getId();
    final int thisDistributionType = this.distributionType;
    final ListenableFuture<VoiceNoteDraft> voiceNoteDraftFuture = draftViewModel.consumeVoiceNoteDraftFuture();
    new AsyncTask<Long, Void, Long>() {

        @Override
        protected Long doInBackground(Long... params) {
            if (voiceNoteDraftFuture != null) {
                try {
                    Draft voiceNoteDraft = voiceNoteDraftFuture.get().asDraft();
                    draftViewModel.setVoiceNoteDraft(recipientId, voiceNoteDraft);
                    drafts.add(voiceNoteDraft);
                } catch (ExecutionException | InterruptedException e) {
                    Log.w(TAG, "Could not extract voice note draft data.", e);
                }
            }
            ThreadDatabase threadDatabase = SignalDatabase.threads();
            DraftDatabase draftDatabase = SignalDatabase.drafts();
            long threadId = params[0];
            if (drafts.size() > 0) {
                if (threadId == -1)
                    threadId = threadDatabase.getOrCreateThreadIdFor(getRecipient(), thisDistributionType);
                draftDatabase.replaceDrafts(threadId, drafts);
                threadDatabase.updateSnippet(threadId, drafts.getSnippet(context), drafts.getUriSnippet(), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
            } else if (threadId > 0) {
                threadDatabase.update(threadId, false);
            }
            if (drafts.isEmpty()) {
                draftDatabase.clearDrafts(threadId);
            }
            return threadId;
        }

        @Override
        protected void onPostExecute(Long result) {
            future.set(result);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, thisThreadId);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SuppressLint(android.annotation.SuppressLint) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft)

Example 4 with VoiceNoteDraft

use of org.thoughtcrime.securesms.components.voice.VoiceNoteDraft in project Signal-Android by WhisperSystems.

the class AudioRecorder method stopRecording.

@NonNull
public ListenableFuture<VoiceNoteDraft> stopRecording() {
    Log.i(TAG, "stopRecording()");
    final SettableFuture<VoiceNoteDraft> future = new SettableFuture<>();
    executor.execute(() -> {
        if (recorder == null) {
            sendToFuture(future, new IOException("MediaRecorder was never initialized successfully!"));
            return;
        }
        recorder.stop();
        try {
            long size = MediaUtil.getMediaSize(context, captureUri);
            sendToFuture(future, new VoiceNoteDraft(captureUri, size));
        } catch (IOException ioe) {
            Log.w(TAG, ioe);
            sendToFuture(future, ioe);
        }
        recorder = null;
        captureUri = null;
    });
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) IOException(java.io.IOException) NonNull(androidx.annotation.NonNull)

Example 5 with VoiceNoteDraft

use of org.thoughtcrime.securesms.components.voice.VoiceNoteDraft in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method onRecorderFinished.

@Override
public void onRecorderFinished() {
    voiceRecorderWakeLock.release();
    updateToggleButtonState();
    Vibrator vibrator = ServiceUtil.getVibrator(requireContext());
    vibrator.vibrate(20);
    requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    ListenableFuture<VoiceNoteDraft> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<VoiceNoteDraft>() {

        @Override
        public void onSuccess(@NonNull final VoiceNoteDraft result) {
            sendVoiceNote(result.getUri(), result.getSize());
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(requireContext(), R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)6 Vibrator (android.os.Vibrator)2 DraftDatabase (org.thoughtcrime.securesms.database.DraftDatabase)2 Draft (org.thoughtcrime.securesms.database.DraftDatabase.Draft)2 Drafts (org.thoughtcrime.securesms.database.DraftDatabase.Drafts)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 File (java.io.File)1 IOException (java.io.IOException)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1 Mention (org.thoughtcrime.securesms.database.model.Mention)1 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)1 GifSlide (org.thoughtcrime.securesms.mms.GifSlide)1 ImageSlide (org.thoughtcrime.securesms.mms.ImageSlide)1 LocationSlide (org.thoughtcrime.securesms.mms.LocationSlide)1 QuoteId (org.thoughtcrime.securesms.mms.QuoteId)1