Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class PodcastsViewModel : ViewModel() {
private val _podcasts = MutableStateFlow(listOf<Podcast>())
val podcasts: StateFlow<List<Podcast>> get() = _podcasts
private val downloadQueue: MutableMap<Int, Flow<Int>> = mutableMapOf()
init {
getPodcasts()
}
private fun getPodcasts() {
viewModelScope.launch(Dispatchers.Default) {
val initialPodcasts = arrayListOf<Podcast>()
repeat(100) {
initialPodcasts += Podcast(
id = it,
title = "Podcast #$it",
downloadProgress = 0
)
}
_podcasts.emit(initialPodcasts)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment