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() { override fun onVoicePlaybackButtonClicked() {
roomDetailViewModel.handle(RoomDetailAction.PlayOrPauseRecordingPlayback) roomDetailViewModel.handle(RoomDetailAction.PlayOrPauseRecordingPlayback)
} }
@ -724,21 +720,23 @@ class RoomDetailFragment @Inject constructor(
updateRecordingUiState(state) updateRecordingUiState(state)
} }
override fun sendVoiceMessage() { override fun onSendVoiceMessage() {
updateRecordingUiState(RecordingUiState.None) updateRecordingUiState(RecordingUiState.None)
} }
override fun deleteVoiceMessage() { override fun onDeleteVoiceMessage() {
roomDetailViewModel.handle(RoomDetailAction.EndRecordingVoiceMessage(isCancelled = true)) roomDetailViewModel.handle(RoomDetailAction.EndRecordingVoiceMessage(isCancelled = true))
updateRecordingUiState(RecordingUiState.None) updateRecordingUiState(RecordingUiState.None)
} }
override fun onRecordingLimitReached() { override fun onRecordingLimitReached() {
updateRecordingUiState(RecordingUiState.Playback) updateRecordingUiState(RecordingUiState.Playback)
roomDetailViewModel.handle(RoomDetailAction.PauseRecordingVoiceMessage)
} }
override fun recordingWaveformClicked() { override fun onRecordingWaveformClicked() {
updateRecordingUiState(RecordingUiState.Playback) updateRecordingUiState(RecordingUiState.Playback)
roomDetailViewModel.handle(RoomDetailAction.PauseRecordingVoiceMessage)
} }
private fun updateRecordingUiState(state: RecordingUiState) { private fun updateRecordingUiState(state: RecordingUiState) {

View File

@ -41,14 +41,13 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
interface Callback { interface Callback {
fun onVoiceRecordingStarted() fun onVoiceRecordingStarted()
fun onVoiceRecordingPlaybackModeOn() fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?)
fun onVoicePlaybackButtonClicked() fun onVoicePlaybackButtonClicked()
fun onUiStateChanged(state: RecordingUiState) fun onUiStateChanged(state: RecordingUiState)
fun sendVoiceMessage() fun onSendVoiceMessage()
fun deleteVoiceMessage() fun onDeleteVoiceMessage()
fun onRecordingLimitReached() fun onRecordingLimitReached()
fun recordingWaveformClicked() fun onRecordingWaveformClicked()
fun onVoiceRecordingEnded(lastKnownState: RecordingUiState?)
} }
// We need to define views as lateinit var to be able to check if initialized for the bug fix on api 21 and 22. // 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() 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() { private fun initListeners() {
voiceMessageViews.start(object : VoiceMessageViews.Actions { voiceMessageViews.start(object : VoiceMessageViews.Actions {
override fun onRequestRecording() { override fun onRequestRecording() = callback.onVoiceRecordingStarted()
callback.onVoiceRecordingStarted() override fun onMicButtonReleased() = callback.onVoiceRecordingEnded(lastKnownState)
} override fun onSendVoiceMessage() = callback.onSendVoiceMessage()
override fun onDeleteVoiceMessage() = callback.onDeleteVoiceMessage()
override fun onMicButtonReleased() { override fun onWaveformClicked() = callback.onRecordingWaveformClicked()
callback.onVoiceRecordingEnded(lastKnownState) override fun onVoicePlaybackButtonClicked() = callback.onVoicePlaybackButtonClicked()
} override fun onMicButtonDrag(updater: (RecordingUiState) -> RecordingUiState) {
override fun updateState(updater: (RecordingUiState) -> RecordingUiState) {
when (val currentState = lastKnownState) { when (val currentState = lastKnownState) {
null, RecordingUiState.None -> { null, RecordingUiState.None -> {
// ignore drag events when the view is idle // 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) { fun display(recordingState: RecordingUiState) {
if (lastKnownState == recordingState) return if (lastKnownState == recordingState) return
val previousState = lastKnownState val previousState = lastKnownState
@ -139,7 +120,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
} }
RecordingUiState.Cancelled -> { RecordingUiState.Cancelled -> {
stopRecordingTicker() stopRecordingTicker()
voiceMessageViews.hideRecordingViews(recordingState) { callback.deleteVoiceMessage() } voiceMessageViews.hideRecordingViews(recordingState) { callback.onDeleteVoiceMessage() }
vibrate(context) vibrate(context)
} }
RecordingUiState.Locked -> { RecordingUiState.Locked -> {
@ -151,7 +132,6 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
RecordingUiState.Playback -> { RecordingUiState.Playback -> {
stopRecordingTicker() stopRecordingTicker()
voiceMessageViews.showPlaybackViews() voiceMessageViews.showPlaybackViews()
callback.onVoiceRecordingPlaybackModeOn()
} }
is DraggingState -> when (recordingState) { is DraggingState -> when (recordingState) {
is DraggingState.Cancelling -> voiceMessageViews.renderCancelling(recordingState.distanceX) is DraggingState.Cancelling -> voiceMessageViews.renderCancelling(recordingState.distanceX)

View File

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