Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Created April 18, 2021 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skyyo/abd5f40163274c399cf04e03712ad0af to your computer and use it in GitHub Desktop.
Save Skyyo/abd5f40163274c399cf04e03712ad0af to your computer and use it in GitHub Desktop.
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