mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 23:55:21 +01:00
Merge pull request #1676 from tomaThomas/improve-startup
Load data in parallel to improve startup time
This commit is contained in:
commit
6752ae2afa
1 changed files with 23 additions and 11 deletions
|
@ -32,6 +32,8 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
|||
import code.name.monkey.retromusic.util.logD
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
|
@ -58,14 +60,18 @@ class LibraryViewModel(
|
|||
loadLibraryContent()
|
||||
}
|
||||
|
||||
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
||||
fetchHomeSections()
|
||||
fetchSuggestions()
|
||||
fetchSongs()
|
||||
fetchAlbums()
|
||||
fetchArtists()
|
||||
fetchGenres()
|
||||
fetchPlaylists()
|
||||
private fun loadLibraryContent() {
|
||||
viewModelScope.launch(IO) {
|
||||
fetchHomeSections()
|
||||
awaitAll(
|
||||
async { fetchSuggestions() },
|
||||
async { fetchSongs() },
|
||||
async { fetchAlbums() },
|
||||
async { fetchArtists() },
|
||||
async { fetchGenres() },
|
||||
async { fetchPlaylists() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getSearchResult(): LiveData<List<Any>> = searchResults
|
||||
|
@ -333,8 +339,12 @@ class LibraryViewModel(
|
|||
createPlaylist(PlaylistEntity(playlistName = playlistName))
|
||||
insertSongs(songs.map { it.toSongEntity(playlistId) })
|
||||
withContext(Main) {
|
||||
context.showToast(context.getString(R.string.playlist_created_sucessfully,
|
||||
playlistName))
|
||||
context.showToast(
|
||||
context.getString(
|
||||
R.string.playlist_created_sucessfully,
|
||||
playlistName
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val playlist = playlists.firstOrNull()
|
||||
|
@ -350,7 +360,9 @@ class LibraryViewModel(
|
|||
context.getString(
|
||||
R.string.added_song_count_to_playlist,
|
||||
songs.size,
|
||||
playlistName))
|
||||
playlistName
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue