Created
April 18, 2021 17:32
-
-
Save Skyyo/abd5f40163274c399cf04e03712ad0af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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