mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 18:57:43 +00:00
Hook up all voice message recording controls
This commit is contained in:
parent
0da2487401
commit
489516b03b
@ -43,9 +43,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
||||
import org.session.libsession.utilities.MediaTypes
|
||||
import org.session.libsession.utilities.ServiceUtil
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.concurrent.AssertedSuccessListener
|
||||
import org.session.libsignal.utilities.ListenableFuture
|
||||
import org.session.libsignal.utilities.guava.Optional
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.audio.AudioRecorder
|
||||
@ -93,7 +91,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
// Attachments
|
||||
private val audioRecorder = AudioRecorder(this)
|
||||
private val stopAudioHandler = Handler(Looper.getMainLooper())
|
||||
private val stopVoiceMessageRecordingTask = Runnable { stopVoiceMessageRecording() }
|
||||
private val stopVoiceMessageRecordingTask = Runnable { sendVoiceMessage() }
|
||||
private val attachmentManager by lazy { AttachmentManager(this, this) }
|
||||
private var isLockViewExpanded = false
|
||||
private var isShowingAttachmentOptions = false
|
||||
@ -628,11 +626,20 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
override fun onMicrophoneButtonUp(event: MotionEvent) {
|
||||
if (isValidLockViewLocation(event.rawX.roundToInt(), event.rawY.roundToInt())) {
|
||||
val x = event.rawX.roundToInt()
|
||||
val y = event.rawY.roundToInt()
|
||||
if (isValidLockViewLocation(x, y)) {
|
||||
inputBarRecordingView.lock()
|
||||
} else {
|
||||
hideVoiceMessageUI()
|
||||
stopVoiceMessageRecording()
|
||||
val recordButtonOverlay = inputBarRecordingView.recordButtonOverlay
|
||||
val location = IntArray(2) { 0 }
|
||||
recordButtonOverlay.getLocationOnScreen(location)
|
||||
val hitRect = Rect(location[0], location[1], location[0] + recordButtonOverlay.width, location[1] + recordButtonOverlay.height)
|
||||
if (hitRect.contains(x, y)) {
|
||||
sendVoiceMessage()
|
||||
} else {
|
||||
cancelVoiceMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -791,12 +798,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
override fun startRecordingVoiceMessage() {
|
||||
showVoiceMessageUI()
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
audioRecorder.startRecording()
|
||||
stopAudioHandler.postDelayed(stopVoiceMessageRecordingTask, 60000) // Limit voice messages to 1 minute each
|
||||
}
|
||||
|
||||
fun stopVoiceMessageRecording() {
|
||||
override fun sendVoiceMessage() {
|
||||
hideVoiceMessageUI()
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
val future = audioRecorder.stopRecording()
|
||||
stopAudioHandler.removeCallbacks(stopVoiceMessageRecordingTask)
|
||||
@ -814,6 +823,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun cancelVoiceMessage() {
|
||||
hideVoiceMessageUI()
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
audioRecorder.stopRecording()
|
||||
stopAudioHandler.removeCallbacks(stopVoiceMessageRecordingTask)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region General
|
||||
|
@ -52,10 +52,7 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
||||
// Microphone button
|
||||
microphoneOrSendButtonContainer.addView(microphoneButton)
|
||||
microphoneButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
||||
microphoneButton.onLongPress = {
|
||||
showVoiceMessageUI()
|
||||
startRecordingVoiceMessage()
|
||||
}
|
||||
microphoneButton.onLongPress = { startRecordingVoiceMessage() }
|
||||
microphoneButton.onMove = { delegate?.onMicrophoneButtonMove(it) }
|
||||
microphoneButton.onCancel = { delegate?.onMicrophoneButtonCancel(it) }
|
||||
microphoneButton.onUp = { delegate?.onMicrophoneButtonUp(it) }
|
||||
@ -95,10 +92,6 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
||||
delegate?.toggleAttachmentOptions()
|
||||
}
|
||||
|
||||
private fun showVoiceMessageUI() {
|
||||
delegate?.showVoiceMessageUI()
|
||||
}
|
||||
|
||||
private fun startRecordingVoiceMessage() {
|
||||
delegate?.startRecordingVoiceMessage()
|
||||
}
|
||||
|
@ -134,10 +134,14 @@ class InputBarRecordingView : RelativeLayout {
|
||||
}
|
||||
fadeInAnimation.start()
|
||||
recordButtonOverlayImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_up, context.theme))
|
||||
recordButtonOverlay.setOnClickListener { delegate?.sendVoiceMessage() }
|
||||
inputBarCancelButton.setOnClickListener { delegate?.cancelVoiceMessage() }
|
||||
}
|
||||
}
|
||||
|
||||
interface InputBarRecordingViewDelegate {
|
||||
|
||||
fun handleVoiceMessageUIHidden()
|
||||
fun sendVoiceMessage()
|
||||
fun cancelVoiceMessage()
|
||||
}
|
||||
|
@ -128,6 +128,7 @@
|
||||
<!-- The actual record button overlay -->
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/recordButtonOverlay"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
Loading…
x
Reference in New Issue
Block a user