Skip to content

Commit 6b51e4f

Browse files
committed
refactor: make listener suspendable
removes a call of launchCatchingIO
1 parent 14d3a56 commit 6b51e4f

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/cardviewer/CardMediaPlayer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ class CardMediaPlayer : Closeable {
126126
var playAvTagsJob: Job? = null
127127
val isPlaying get() = playAvTagsJob != null
128128

129-
private var onMediaGroupCompleted: (() -> Unit)? = null
129+
private var onMediaGroupCompleted: (suspend () -> Unit)? = null
130130

131-
fun setOnMediaGroupCompletedListener(listener: (() -> Unit)?) {
131+
fun setOnMediaGroupCompletedListener(listener: (suspend () -> Unit)?) {
132132
onMediaGroupCompleted = listener
133133
}
134134

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,12 @@ class ReviewerViewModel(
162162
updateNextTimes()
163163
}
164164
cardMediaPlayer.setOnMediaGroupCompletedListener {
165-
launchCatchingIO {
166-
if (!autoAdvance.shouldWaitForAudio()) return@launchCatchingIO
165+
if (!autoAdvance.shouldWaitForAudio()) return@setOnMediaGroupCompletedListener
167166

168-
if (showingAnswer.value) {
169-
autoAdvance.onShowAnswer()
170-
} else {
171-
autoAdvance.onShowQuestion()
172-
}
167+
if (showingAnswer.value) {
168+
autoAdvance.onShowAnswer()
169+
} else {
170+
autoAdvance.onShowQuestion()
173171
}
174172
}
175173
}

0 commit comments

Comments
 (0)