From b8a2b1747738f5097d2783d29a121fc03f2cf369 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 4 Nov 2020 14:49:28 +1100 Subject: [PATCH] Limit voice messages to one minute --- .../securesms/conversation/ConversationActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 12c8e337ce..465de91e5f 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -330,6 +330,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private AttachmentTypeSelector attachmentTypeSelector; private AttachmentManager attachmentManager; private AudioRecorder audioRecorder; + private Handler audioHandler; + private Runnable stopRecordingTask; private BroadcastReceiver securityUpdateReceiver; private Stub emojiDrawerStub; protected HidingLinearLayout quickAttachmentToggle; @@ -2579,6 +2581,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); audioRecorder.startRecording(); + + audioHandler = new Handler(); + stopRecordingTask = () -> inputPanel.onRecordReleased(); + audioHandler.postDelayed(stopRecordingTask, 60000); } @Override @@ -2588,6 +2594,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onRecorderFinished() { + if (audioHandler != null && stopRecordingTask != null) { + audioHandler.removeCallbacks(stopRecordingTask); + } updateToggleButtonState(); Vibrator vibrator = ServiceUtil.getVibrator(this); vibrator.vibrate(20); @@ -2629,6 +2638,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onRecorderCanceled() { + if (audioHandler != null && stopRecordingTask != null) { + audioHandler.removeCallbacks(stopRecordingTask); + } updateToggleButtonState(); Vibrator vibrator = ServiceUtil.getVibrator(this); vibrator.vibrate(50);