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);
}
}
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;
}
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());
}
}
}
}
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();
}
});
}
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());
}
}
}
}
Aggregations