Skip to content

Commit

Permalink
Merge branch 'issue/v2c-clear-resources' into issue/v2c-show-elapsed-…
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
zwarm committed Jun 14, 2024
2 parents 521481f + 9aa4aec commit 6b131e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.ui.voicetocontent

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Bundle
Expand All @@ -18,6 +19,7 @@ import org.wordpress.android.ui.compose.theme.AppTheme
import org.wordpress.android.R
import org.wordpress.android.util.audio.IAudioRecorder.Companion.REQUIRED_RECORDING_PERMISSIONS
import android.provider.Settings
import android.util.Log
import android.widget.FrameLayout
import androidx.compose.material.ExperimentalMaterialApi
import com.google.android.material.bottomsheet.BottomSheetBehavior
Expand Down Expand Up @@ -68,15 +70,10 @@ class VoiceToContentDialogFragment : BottomSheetDialogFragment() {
@SuppressLint("SwitchIntDef")
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_HIDDEN -> {
// Bottom sheet is hidden, you can listen for this event here
viewModel.onBottomSheetClosed()
}
BottomSheetBehavior.STATE_HIDDEN,
BottomSheetBehavior.STATE_COLLAPSED -> {
// Bottom sheet is collapsed, you can listen for this event here
viewModel.onBottomSheetClosed()
onBottomSheetClosed()
}
// Handle other states if necessary
}
}

Expand All @@ -88,9 +85,25 @@ class VoiceToContentDialogFragment : BottomSheetDialogFragment() {
// Disable touch interception by the bottom sheet to allow nested scrolling
bottomSheet.setOnTouchListener { _, _ -> false }
}

// Observe the ViewModel to update the cancelable state of closing on outside touch
viewModel.isCancelableOutsideTouch.observe(this) { cancelable ->
Log.i(javaClass.simpleName, "***=> disable outside touch")
dialog.setCanceledOnTouchOutside(cancelable)
}

return dialog
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
viewModel.onBottomSheetClosed()
}

private fun onBottomSheetClosed() {
dismiss()
}

private fun observeViewModel() {
viewModel.requestPermission.observe(viewLifecycleOwner) {
requestAllPermissionsForRecording()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class VoiceToContentViewModel @Inject constructor(
private val _onIneligibleForVoiceToContent = MutableLiveData<String>()
val onIneligibleForVoiceToContent = _onIneligibleForVoiceToContent as LiveData<String>

private val _isCancelableOutsideTouch = MutableLiveData(true)
val isCancelableOutsideTouch: LiveData<Boolean> get() = _isCancelableOutsideTouch

private var isStarted = false

private val _state = MutableStateFlow(VoiceToContentUiState(
Expand Down Expand Up @@ -130,6 +133,7 @@ class VoiceToContentViewModel @Inject constructor(

private fun startRecording() {
transitionToRecording()
disableDialogCancelableOutsideTouch()
recordingUseCase.startRecording { audioRecorderResult ->
when (audioRecorderResult) {
is Success -> {
Expand All @@ -149,6 +153,10 @@ class VoiceToContentViewModel @Inject constructor(
}
}

private fun disableDialogCancelableOutsideTouch() {
_isCancelableOutsideTouch.value = false
}

@Suppress("ReturnCount")
private fun getRecordingFile(recordingPath: String): File? {
if (recordingPath.isEmpty()) return null
Expand Down

0 comments on commit 6b131e0

Please sign in to comment.