Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.ichi2.anki.R
import com.ichi2.anki.databinding.CheckPronunciationFragmentBinding
import com.ichi2.anki.ui.windows.reviewer.ReviewerViewModel
import com.ichi2.anki.utils.ext.collectIn
import com.ichi2.utils.show
import dev.androidbroadcast.vbpd.viewBinding

/**
* Integrates [AudioRecordView] with [AudioPlayView] to play the recorded audios.
Expand All @@ -40,8 +42,7 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
private val viewModel: CheckPronunciationViewModel by viewModels()
private val studyScreenViewModel: ReviewerViewModel by viewModels({ requireParentFragment() })

private lateinit var playView: AudioPlayView
private lateinit var recordView: AudioRecordView
private val binding by viewBinding(CheckPronunciationFragmentBinding::bind)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint rule didn't catch the layout name for this fragment, it should be R.layout.fragment_check_pronunciation.


private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
Expand All @@ -65,8 +66,6 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
playView = view.findViewById(R.id.audio_play_view)
recordView = view.findViewById(R.id.audio_record_view)

setupViewListeners()
observeViewModel()
Expand All @@ -79,11 +78,11 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
return
}
viewModel.resetAll()
recordView.forceReset()
binding.recordView.forceReset()
}

private fun setupViewListeners() {
playView.setButtonPressListener(
binding.playView.setButtonPressListener(
object : AudioPlayView.ButtonPressListener {
override fun onPlayButtonPressed() {
viewModel.onPlayOrReplay()
Expand All @@ -95,7 +94,7 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
},
)

recordView.setRecordingListener(
binding.recordView.setRecordingListener(
object : AudioRecordView.RecordingListener {
override fun onRecordingPermissionRequired() {
requestPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
Expand All @@ -118,24 +117,24 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen

private fun observeViewModel() {
viewModel.isPlaybackVisibleFlow.flowWithLifecycle(lifecycle).collectIn(lifecycleScope) { isVisible ->
playView.isVisible = isVisible
recordView.setRecordDisplayVisibility(!isVisible)
binding.playView.isVisible = isVisible
binding.recordView.setRecordDisplayVisibility(!isVisible)
}
viewModel.playbackProgressFlow
.flowWithLifecycle(lifecycle)
.collectIn(lifecycleScope) { progress ->
playView.setPlaybackProgress(progress)
binding.playView.setPlaybackProgress(progress)
}
viewModel.playbackProgressBarMaxFlow
.flowWithLifecycle(lifecycle)
.collectIn(lifecycleScope) { max ->
playView.setPlaybackProgressBarMax(max)
binding.playView.setPlaybackProgressBarMax(max)
}
viewModel.playIconFlow.flowWithLifecycle(lifecycle).collectIn(lifecycleScope) { iconRes ->
playView.changePlayIcon(iconRes)
binding.playView.changePlayIcon(iconRes)
}
viewModel.replayFlow.flowWithLifecycle(lifecycle).collectIn(lifecycleScope) {
playView.rotateReplayIcon()
binding.playView.rotateReplayIcon()
}
}

Expand All @@ -145,7 +144,7 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
.collectIn(lifecycleScope) { isEnabled ->
if (!isEnabled) {
viewModel.resetAll()
recordView.forceReset()
binding.recordView.forceReset()
}
}
studyScreenViewModel.replayVoiceFlow
Expand All @@ -154,9 +153,9 @@ class CheckPronunciationFragment : Fragment(R.layout.check_pronunciation_fragmen
viewModel.onPlayOrReplay()
}
studyScreenViewModel.onCardUpdatedFlow.flowWithLifecycle(lifecycle).collectIn(lifecycleScope) { showingAnswer ->
playView.isVisible = false
binding.playView.isVisible = false
viewModel.onCancelPlayback()
recordView.setRecordDisplayVisibility(true)
binding.recordView.setRecordDisplayVisibility(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>

<com.ichi2.anki.ui.windows.reviewer.audiorecord.AudioPlayView
android:id="@+id/audio_play_view"
android:id="@+id/play_view"
android:layout_width="0dp"
android:layout_height="48dp"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -30,7 +30,7 @@
/>

<com.ichi2.anki.ui.windows.reviewer.audiorecord.AudioRecordView
android:id="@+id/audio_record_view"
android:id="@+id/record_view"
android:layout_width="match_parent"
android:layout_height="48dp"
app:layout_constraintTop_toTopOf="parent"
Expand Down