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 code.name.monkey.retromusic.util.logD
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -58,14 +60,18 @@ class LibraryViewModel(
|
||||||
loadLibraryContent()
|
loadLibraryContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
private fun loadLibraryContent() {
|
||||||
fetchHomeSections()
|
viewModelScope.launch(IO) {
|
||||||
fetchSuggestions()
|
fetchHomeSections()
|
||||||
fetchSongs()
|
awaitAll(
|
||||||
fetchAlbums()
|
async { fetchSuggestions() },
|
||||||
fetchArtists()
|
async { fetchSongs() },
|
||||||
fetchGenres()
|
async { fetchAlbums() },
|
||||||
fetchPlaylists()
|
async { fetchArtists() },
|
||||||
|
async { fetchGenres() },
|
||||||
|
async { fetchPlaylists() },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSearchResult(): LiveData<List<Any>> = searchResults
|
fun getSearchResult(): LiveData<List<Any>> = searchResults
|
||||||
|
@ -333,8 +339,12 @@ class LibraryViewModel(
|
||||||
createPlaylist(PlaylistEntity(playlistName = playlistName))
|
createPlaylist(PlaylistEntity(playlistName = playlistName))
|
||||||
insertSongs(songs.map { it.toSongEntity(playlistId) })
|
insertSongs(songs.map { it.toSongEntity(playlistId) })
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
context.showToast(context.getString(R.string.playlist_created_sucessfully,
|
context.showToast(
|
||||||
playlistName))
|
context.getString(
|
||||||
|
R.string.playlist_created_sucessfully,
|
||||||
|
playlistName
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val playlist = playlists.firstOrNull()
|
val playlist = playlists.firstOrNull()
|
||||||
|
@ -350,7 +360,9 @@ class LibraryViewModel(
|
||||||
context.getString(
|
context.getString(
|
||||||
R.string.added_song_count_to_playlist,
|
R.string.added_song_count_to_playlist,
|
||||||
songs.size,
|
songs.size,
|
||||||
playlistName))
|
playlistName
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue