Skip to content

Commit 719e046

Browse files
committed
Fix possible blocking flow
1 parent e27b275 commit 719e046

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/helper/ShowMenuHelperViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
1313
import kotlinx.coroutines.flow.first
1414
import kotlinx.coroutines.flow.firstOrNull
1515
import kotlinx.coroutines.flow.mapLatest
16-
import kotlinx.coroutines.flow.onStart
1716

1817
@OptIn(ExperimentalCoroutinesApi::class)
1918
class ShowMenuHelperViewModel(
@@ -108,7 +107,10 @@ class ShowMenuHelperViewModel(
108107
}
109108

110109
suspend fun startDownload(show: MediathekShow, quality: Quality) {
111-
val persistedShow = mediathekRepository.getPersistedShowByApiId(show.apiId).first()
110+
val persistedShow = mediathekRepository
111+
.persistOrUpdateShow(show)
112+
.first()
113+
112114
downloadController.startDownload(persistedShow.id, quality)
113115
}
114116
}

app/src/main/java/de/christinecoenen/code/zapp/repositories/MediathekRepository.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ class MediathekRepository(private val database: Database) {
153153
.flowOn(Dispatchers.IO)
154154
}
155155

156-
fun getPersistedShowByApiId(apiId: String): Flow<PersistedMediathekShow> {
156+
fun getPersistedShowByApiId(apiId: String): Flow<PersistedMediathekShow?> {
157157
return database
158158
.mediathekShowDao()
159159
.getFromApiId(apiId)
160160
.distinctUntilChanged()
161-
.filterNotNull()
162161
.flowOn(Dispatchers.IO)
163162
}
164163

0 commit comments

Comments
 (0)