From b400f3c83ff6fcd68ea426789a8d8e4a37389084 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 9 Jul 2021 16:31:26 +0200 Subject: [PATCH] Small cleanup --- .../composer/VoiceMessageRecorderView.kt | 31 +++++++++---------- .../layout/view_voice_message_recorder.xml | 3 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt index 839f73f385..13679da52b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageRecorderView.kt @@ -99,7 +99,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( callback?.onVoiceRecordingEnded(isCancelled = false) } - views.voiceMessagePlaybackLayout.findViewById(R.id.voiceMessageDeletePlayback).setOnClickListener { + views.voiceMessageDeletePlayback.setOnClickListener { stopRecordingTimer() hideRecordingViews(animationDuration = 0) views.voiceMessageSendButton.isVisible = false @@ -107,14 +107,14 @@ class VoiceMessageRecorderView @JvmOverloads constructor( callback?.onVoiceRecordingEnded(isCancelled = true) } - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackWaveform).setOnClickListener { + views.voicePlaybackWaveform.setOnClickListener { if (recordingState !== RecordingState.PLAYBACK) { recordingState = RecordingState.PLAYBACK showPlaybackViews() } } - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackControlButton).setOnClickListener { + views.voicePlaybackControlButton.setOnClickListener { callback?.onVoicePlaybackButtonClicked() } @@ -257,7 +257,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( private fun showRecordingTimer() { val formattedTimerText = DateUtils.formatElapsedTime((recordingTime).toLong()) if (recordingState == RecordingState.LOCKED) { - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackTime).apply { + views.voicePlaybackTime.apply { post { text = formattedTimerText } @@ -270,7 +270,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( } private fun showRecordingWaveform() { - val audioRecordView = views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackWaveform) + val audioRecordView = views.voicePlaybackWaveform audioRecordView.apply { post { recreate() @@ -302,7 +302,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( 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.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()) } @@ -322,15 +322,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor( private fun showRecordingLockedViews() { hideRecordingViews(animationDuration = 0) views.voiceMessagePlaybackLayout.isVisible = true - views.voiceMessagePlaybackLayout.findViewById(R.id.voiceMessagePlaybackTimerIndicator).isVisible = true - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackControlButton).isVisible = false + views.voiceMessagePlaybackTimerIndicator.isVisible = true + views.voicePlaybackControlButton.isVisible = false views.voiceMessageSendButton.isVisible = true context.toast(R.string.voice_message_tap_to_stop_toast) } private fun showPlaybackViews() { - views.voiceMessagePlaybackLayout.findViewById(R.id.voiceMessagePlaybackTimerIndicator).isVisible = false - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackControlButton).isVisible = true + views.voiceMessagePlaybackTimerIndicator.isVisible = false + views.voicePlaybackControlButton.isVisible = true callback?.onVoiceRecordingPlaybackModeOn() } @@ -343,7 +343,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor( ) } - enum class RecordingState { + private enum class RecordingState { NONE, STARTED, CANCELLING, @@ -359,15 +359,12 @@ class VoiceMessageRecorderView @JvmOverloads constructor( this.amplitudeList = state.amplitudeList } is VoiceMessagePlaybackTracker.Listener.State.Playing -> { - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackControlButton) - .setImageResource(R.drawable.ic_voice_pause) + views.voicePlaybackControlButton.setImageResource(R.drawable.ic_voice_pause) val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong()) - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackTime) - .setText(formattedTimerText) + views.voicePlaybackTime.setText(formattedTimerText) } is VoiceMessagePlaybackTracker.Listener.State.Idle -> { - views.voiceMessagePlaybackLayout.findViewById(R.id.voicePlaybackControlButton) - .setImageResource(R.drawable.ic_voice_play) + views.voicePlaybackControlButton.setImageResource(R.drawable.ic_voice_play) } } } diff --git a/vector/src/main/res/layout/view_voice_message_recorder.xml b/vector/src/main/res/layout/view_voice_message_recorder.xml index ff3046419c..40014cda86 100644 --- a/vector/src/main/res/layout/view_voice_message_recorder.xml +++ b/vector/src/main/res/layout/view_voice_message_recorder.xml @@ -49,7 +49,7 @@ app:layout_constraintBottom_toBottomOf="@id/voiceMessageMicButton" app:layout_constraintStart_toEndOf="@id/voiceMessageTimerIndicator" app:layout_constraintTop_toTopOf="@id/voiceMessageMicButton" - tools:text="00:03" + tools:text="0:03" tools:visibility="visible" />