updating voice view interface method names for consistency

This commit is contained in:
Adam Brown 2021-11-18 17:11:10 +00:00
parent 734e7df910
commit c5746a59ae
3 changed files with 33 additions and 55 deletions

View file

@ -704,10 +704,6 @@ class RoomDetailFragment @Inject constructor(
}
}
override fun onVoiceRecordingPlaybackModeOn() {
roomDetailViewModel.handle(RoomDetailAction.PauseRecordingVoiceMessage)
}
override fun onVoicePlaybackButtonClicked() {
roomDetailViewModel.handle(RoomDetailAction.PlayOrPauseRecordingPlayback)
}
@ -724,21 +720,23 @@ class RoomDetailFragment @Inject constructor(
updateRecordingUiState(state)
}
override fun sendVoiceMessage() {
override fun onSendVoiceMessage() {
updateRecordingUiState(RecordingUiState.None)
}
override fun deleteVoiceMessage() {
override fun onDeleteVoiceMessage() {
roomDetailViewModel.handle(RoomDetailAction.EndRecordingVoiceMessage(isCancelled = true))
updateRecordingUiState(RecordingUiState.None)
}
override fun onRecordingLimitReached() {
updateRecordingUiState(RecordingUiState.Playback)
roomDetailViewModel.handle(RoomDetailAction.PauseRecordingVoiceMessage)
}
override fun recordingWaveformClicked() {
override fun onRecordingWaveformClicked() {
updateRecordingUiState(RecordingUiState.Playback)
roomDetailViewModel.handle(RoomDetailAction.PauseRecordingVoiceMessage)
}
private fun updateRecordingUiState(state: RecordingUiState) {

View file

@ -41,14 +41,13 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
interface Callback {
fun onVoiceRecordingStarted()
fun onVoiceRecordingPlaybackModeOn()
fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?)
fun onVoicePlaybackButtonClicked()
fun onUiStateChanged(state: RecordingUiState)
fun sendVoiceMessage()
fun deleteVoiceMessage()
fun onSendVoiceMessage()
fun onDeleteVoiceMessage()
fun onRecordingLimitReached()
fun recordingWaveformClicked()
fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?)
fun onRecordingWaveformClicked()
}
// We need to define views as lateinit var to be able to check if initialized for the bug fix on api 21 and 22.
@ -70,25 +69,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
initListeners()
}
override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
// onVisibilityChanged is called by constructor on api 21 and 22.
if (!this::voiceMessageViews.isInitialized) return
val parentChanged = changedView == this
voiceMessageViews.renderVisibilityChanged(parentChanged, visibility)
}
private fun initListeners() {
voiceMessageViews.start(object : VoiceMessageViews.Actions {
override fun onRequestRecording() {
callback.onVoiceRecordingStarted()
}
override fun onMicButtonReleased() {
callback.onVoiceRecordingEnded(lastKnownState)
}
override fun updateState(updater: (RecordingUiState) -> RecordingUiState) {
override fun onRequestRecording() = callback.onVoiceRecordingStarted()
override fun onMicButtonReleased() = callback.onVoiceRecordingEnded(lastKnownState)
override fun onSendVoiceMessage() = callback.onSendVoiceMessage()
override fun onDeleteVoiceMessage() = callback.onDeleteVoiceMessage()
override fun onWaveformClicked() = callback.onRecordingWaveformClicked()
override fun onVoicePlaybackButtonClicked() = callback.onVoicePlaybackButtonClicked()
override fun onMicButtonDrag(updater: (RecordingUiState) -> RecordingUiState) {
when (val currentState = lastKnownState) {
null, RecordingUiState.None -> {
// ignore drag events when the view is idle
@ -104,25 +93,17 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
}
}
override fun sendMessage() {
callback.sendVoiceMessage()
}
override fun delete() {
callback.deleteVoiceMessage()
}
override fun waveformClicked() {
callback.recordingWaveformClicked()
}
override fun onVoicePlaybackButtonClicked() {
callback.onVoicePlaybackButtonClicked()
}
})
}
override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
// onVisibilityChanged is called by constructor on api 21 and 22.
if (!this::voiceMessageViews.isInitialized) return
val parentChanged = changedView == this
voiceMessageViews.renderVisibilityChanged(parentChanged, visibility)
}
fun display(recordingState: RecordingUiState) {
if (lastKnownState == recordingState) return
val previousState = lastKnownState
@ -139,7 +120,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
RecordingUiState.Cancelled -> {
stopRecordingTicker()
voiceMessageViews.hideRecordingViews(recordingState) { callback.deleteVoiceMessage() }
voiceMessageViews.hideRecordingViews(recordingState) { callback.onDeleteVoiceMessage() }
vibrate(context)
}
RecordingUiState.Locked -> {
@ -151,7 +132,6 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
RecordingUiState.Playback -> {
stopRecordingTicker()
voiceMessageViews.showPlaybackViews()
callback.onVoiceRecordingPlaybackModeOn()
}
is DraggingState -> when (recordingState) {
is DraggingState.Cancelling -> voiceMessageViews.renderCancelling(recordingState.distanceX)

View file

@ -48,16 +48,16 @@ class VoiceMessageViews(
fun start(actions: Actions) {
views.voiceMessageSendButton.setOnClickListener {
views.voiceMessageSendButton.isVisible = false
actions.sendMessage()
actions.onSendVoiceMessage()
}
views.voiceMessageDeletePlayback.setOnClickListener {
views.voiceMessageSendButton.isVisible = false
actions.delete()
actions.onDeleteVoiceMessage()
}
views.voicePlaybackWaveform.setOnClickListener {
actions.waveformClicked()
actions.onWaveformClicked()
}
views.voicePlaybackControlButton.setOnClickListener {
@ -81,7 +81,7 @@ class VoiceMessageViews(
true
}
MotionEvent.ACTION_MOVE -> {
actions.updateState { currentState -> positions.process(event, currentState) }
actions.onMicButtonDrag { currentState -> positions.process(event, currentState) }
true
}
else -> false
@ -341,10 +341,10 @@ class VoiceMessageViews(
interface Actions {
fun onRequestRecording()
fun onMicButtonReleased()
fun updateState(updater: (RecordingUiState) -> RecordingUiState)
fun sendMessage()
fun delete()
fun waveformClicked()
fun onMicButtonDrag(updater: (RecordingUiState) -> RecordingUiState)
fun onSendVoiceMessage()
fun onDeleteVoiceMessage()
fun onWaveformClicked()
fun onVoicePlaybackButtonClicked()
}
}