Small cleanup

This commit is contained in:
Benoit Marty 2021-07-09 16:31:26 +02:00
parent 3372177b0e
commit b400f3c83f
2 changed files with 16 additions and 18 deletions

View File

@ -99,7 +99,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
callback?.onVoiceRecordingEnded(isCancelled = false) callback?.onVoiceRecordingEnded(isCancelled = false)
} }
views.voiceMessagePlaybackLayout.findViewById<ImageButton>(R.id.voiceMessageDeletePlayback).setOnClickListener { views.voiceMessageDeletePlayback.setOnClickListener {
stopRecordingTimer() stopRecordingTimer()
hideRecordingViews(animationDuration = 0) hideRecordingViews(animationDuration = 0)
views.voiceMessageSendButton.isVisible = false views.voiceMessageSendButton.isVisible = false
@ -107,14 +107,14 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
callback?.onVoiceRecordingEnded(isCancelled = true) callback?.onVoiceRecordingEnded(isCancelled = true)
} }
views.voiceMessagePlaybackLayout.findViewById<AudioRecordView>(R.id.voicePlaybackWaveform).setOnClickListener { views.voicePlaybackWaveform.setOnClickListener {
if (recordingState !== RecordingState.PLAYBACK) { if (recordingState !== RecordingState.PLAYBACK) {
recordingState = RecordingState.PLAYBACK recordingState = RecordingState.PLAYBACK
showPlaybackViews() showPlaybackViews()
} }
} }
views.voiceMessagePlaybackLayout.findViewById<ImageButton>(R.id.voicePlaybackControlButton).setOnClickListener { views.voicePlaybackControlButton.setOnClickListener {
callback?.onVoicePlaybackButtonClicked() callback?.onVoicePlaybackButtonClicked()
} }
@ -257,7 +257,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
private fun showRecordingTimer() { private fun showRecordingTimer() {
val formattedTimerText = DateUtils.formatElapsedTime((recordingTime).toLong()) val formattedTimerText = DateUtils.formatElapsedTime((recordingTime).toLong())
if (recordingState == RecordingState.LOCKED) { if (recordingState == RecordingState.LOCKED) {
views.voiceMessagePlaybackLayout.findViewById<TextView>(R.id.voicePlaybackTime).apply { views.voicePlaybackTime.apply {
post { post {
text = formattedTimerText text = formattedTimerText
} }
@ -270,7 +270,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
} }
private fun showRecordingWaveform() { private fun showRecordingWaveform() {
val audioRecordView = views.voiceMessagePlaybackLayout.findViewById<AudioRecordView>(R.id.voicePlaybackWaveform) val audioRecordView = views.voicePlaybackWaveform
audioRecordView.apply { audioRecordView.apply {
post { post {
recreate() recreate()
@ -302,7 +302,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
views.voiceMessageSendButton.isVisible = false views.voiceMessageSendButton.isVisible = false
} }
fun hideRecordingViews(animationDuration: Int = 300) { private fun hideRecordingViews(animationDuration: Int = 300) {
views.voiceMessageMicButton.setImageResource(R.drawable.ic_voice_mic) views.voiceMessageMicButton.setImageResource(R.drawable.ic_voice_mic)
views.voiceMessageMicButton.animate().translationX(0f).translationY(0f).setDuration(animationDuration.toLong()).setDuration(0).start() views.voiceMessageMicButton.animate().translationX(0f).translationY(0f).setDuration(animationDuration.toLong()).setDuration(0).start()
(views.voiceMessageMicButton.layoutParams as MarginLayoutParams).apply { setMargins(0, 0, dpToPx(12).toInt(), dpToPx(12).toInt()) } (views.voiceMessageMicButton.layoutParams as MarginLayoutParams).apply { setMargins(0, 0, dpToPx(12).toInt(), dpToPx(12).toInt()) }
@ -322,15 +322,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
private fun showRecordingLockedViews() { private fun showRecordingLockedViews() {
hideRecordingViews(animationDuration = 0) hideRecordingViews(animationDuration = 0)
views.voiceMessagePlaybackLayout.isVisible = true views.voiceMessagePlaybackLayout.isVisible = true
views.voiceMessagePlaybackLayout.findViewById<ImageView>(R.id.voiceMessagePlaybackTimerIndicator).isVisible = true views.voiceMessagePlaybackTimerIndicator.isVisible = true
views.voiceMessagePlaybackLayout.findViewById<ImageView>(R.id.voicePlaybackControlButton).isVisible = false views.voicePlaybackControlButton.isVisible = false
views.voiceMessageSendButton.isVisible = true views.voiceMessageSendButton.isVisible = true
context.toast(R.string.voice_message_tap_to_stop_toast) context.toast(R.string.voice_message_tap_to_stop_toast)
} }
private fun showPlaybackViews() { private fun showPlaybackViews() {
views.voiceMessagePlaybackLayout.findViewById<ImageView>(R.id.voiceMessagePlaybackTimerIndicator).isVisible = false views.voiceMessagePlaybackTimerIndicator.isVisible = false
views.voiceMessagePlaybackLayout.findViewById<ImageView>(R.id.voicePlaybackControlButton).isVisible = true views.voicePlaybackControlButton.isVisible = true
callback?.onVoiceRecordingPlaybackModeOn() callback?.onVoiceRecordingPlaybackModeOn()
} }
@ -343,7 +343,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
) )
} }
enum class RecordingState { private enum class RecordingState {
NONE, NONE,
STARTED, STARTED,
CANCELLING, CANCELLING,
@ -359,15 +359,12 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
this.amplitudeList = state.amplitudeList this.amplitudeList = state.amplitudeList
} }
is VoiceMessagePlaybackTracker.Listener.State.Playing -> { is VoiceMessagePlaybackTracker.Listener.State.Playing -> {
views.voiceMessagePlaybackLayout.findViewById<ImageButton>(R.id.voicePlaybackControlButton) views.voicePlaybackControlButton.setImageResource(R.drawable.ic_voice_pause)
.setImageResource(R.drawable.ic_voice_pause)
val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong()) val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong())
views.voiceMessagePlaybackLayout.findViewById<TextView>(R.id.voicePlaybackTime) views.voicePlaybackTime.setText(formattedTimerText)
.setText(formattedTimerText)
} }
is VoiceMessagePlaybackTracker.Listener.State.Idle -> { is VoiceMessagePlaybackTracker.Listener.State.Idle -> {
views.voiceMessagePlaybackLayout.findViewById<ImageButton>(R.id.voicePlaybackControlButton) views.voicePlaybackControlButton.setImageResource(R.drawable.ic_voice_play)
.setImageResource(R.drawable.ic_voice_play)
} }
} }
} }

View File

@ -49,7 +49,7 @@
app:layout_constraintBottom_toBottomOf="@id/voiceMessageMicButton" app:layout_constraintBottom_toBottomOf="@id/voiceMessageMicButton"
app:layout_constraintStart_toEndOf="@id/voiceMessageTimerIndicator" app:layout_constraintStart_toEndOf="@id/voiceMessageTimerIndicator"
app:layout_constraintTop_toTopOf="@id/voiceMessageMicButton" app:layout_constraintTop_toTopOf="@id/voiceMessageMicButton"
tools:text="00:03" tools:text="0:03"
tools:visibility="visible" /> tools:visibility="visible" />
<TextView <TextView
@ -94,6 +94,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/voiceMessageMicButton" app:layout_constraintEnd_toStartOf="@id/voiceMessageMicButton"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:layout_marginBottom="120dp"
tools:visibility="visible"> tools:visibility="visible">
<ImageButton <ImageButton