Search in sources :

Example 6 with VoiceNoteDraft

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

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 7 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 8 with VoiceNoteDraft

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

the class BlobProvider method deleteOrphanedDraftFiles.

private static void deleteOrphanedDraftFiles(@NonNull Context context) {
    File directory = getOrCreateDirectory(context, DRAFT_ATTACHMENTS_DIRECTORY);
    File[] files = directory.listFiles();
    if (files == null || files.length == 0) {
        Log.d(TAG, "No attachment drafts exist. Skipping.");
        return;
    }
    DraftDatabase draftDatabase = SignalDatabase.drafts();
    DraftDatabase.Drafts voiceNoteDrafts = draftDatabase.getAllVoiceNoteDrafts();
    @SuppressWarnings("ConstantConditions") List<String> draftFileNames = voiceNoteDrafts.stream().map(VoiceNoteDraft::fromDraft).map(VoiceNoteDraft::getUri).map(BlobProvider::getId).filter(Objects::nonNull).map(BlobProvider::buildFileName).collect(Collectors.toList());
    for (final File file : files) {
        if (!draftFileNames.contains(file.getName())) {
            if (file.delete()) {
                Log.d(TAG, "Deleted orphaned attachment draft: " + file.getName());
            } else {
                Log.d(TAG, "Failed to delete orphaned attachment draft: " + file.getName());
            }
        }
    }
}
Also used : DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Objects(java.util.Objects) File(java.io.File)

Example 9 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)

Example 10 with VoiceNoteDraft

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

the class BlobProvider method deleteOrphanedDraftFiles.

private static void deleteOrphanedDraftFiles(@NonNull Context context) {
    File directory = getOrCreateDirectory(context, DRAFT_ATTACHMENTS_DIRECTORY);
    File[] files = directory.listFiles();
    if (files == null || files.length == 0) {
        Log.d(TAG, "No attachment drafts exist. Skipping.");
        return;
    }
    DraftDatabase draftDatabase = SignalDatabase.drafts();
    DraftDatabase.Drafts voiceNoteDrafts = draftDatabase.getAllVoiceNoteDrafts();
    @SuppressWarnings("ConstantConditions") List<String> draftFileNames = voiceNoteDrafts.stream().map(VoiceNoteDraft::fromDraft).map(VoiceNoteDraft::getUri).map(BlobProvider::getId).filter(Objects::nonNull).map(BlobProvider::buildFileName).collect(Collectors.toList());
    for (final File file : files) {
        if (!draftFileNames.contains(file.getName())) {
            if (file.delete()) {
                Log.d(TAG, "Deleted orphaned attachment draft: " + file.getName());
            } else {
                Log.d(TAG, "Failed to delete orphaned attachment draft: " + file.getName());
            }
        }
    }
}
Also used : DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Objects(java.util.Objects) File(java.io.File)

Aggregations

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