Split to sub fun

This commit is contained in:
Benoit Marty 2021-07-15 15:14:26 +02:00
parent bb742eb483
commit 6f947e979b

View File

@ -116,8 +116,26 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
views.voiceMessageMicButton.setOnTouchListener { _, event ->
return@setOnTouchListener when (event.action) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
handleMicActionDown(event)
true
}
MotionEvent.ACTION_UP -> {
handleMicActionUp()
true
}
MotionEvent.ACTION_MOVE -> {
handleMicActionMove(event)
true
}
else ->
false
}
}
}
private fun handleMicActionDown(event: MotionEvent) {
val recordingStarted = callback?.onVoiceRecordingStarted().orFalse()
if (recordingStarted) {
startRecordingTicker()
@ -130,9 +148,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
lastX = firstX
lastY = firstY
}
true
}
MotionEvent.ACTION_UP -> {
private fun handleMicActionUp() {
if (recordingState != RecordingState.LOCKED) {
stopRecordingTicker()
val isCancelled = recordingState == RecordingState.NONE || recordingState == RecordingState.CANCELLED
@ -140,18 +158,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
recordingState = RecordingState.NONE
hideRecordingViews()
}
true
}
MotionEvent.ACTION_MOVE -> {
handleMoveAction(event)
true
}
else -> false
}
}
}
private fun handleMoveAction(event: MotionEvent) {
private fun handleMicActionMove(event: MotionEvent) {
val currentX = event.rawX
val currentY = event.rawY