Fix crashing

This commit is contained in:
Hemanth S 2020-05-26 04:16:12 +05:30
parent 7f9fa54292
commit acc77478b7
2 changed files with 12 additions and 9 deletions

View file

@ -189,6 +189,8 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
} }
loadAlbumCover() loadAlbumCover()
simpleSongAdapter.swapDataSet(album.songs) simpleSongAdapter.swapDataSet(album.songs)
viewModel.loadArtistAsync(album.artistId)
viewModel.loadAlbumInfoAsync(album)
} }
override fun moreAlbums(albums: List<Album>) { override fun moreAlbums(albums: List<Album>) {

View file

@ -32,22 +32,23 @@ class AlbumDetailsViewModel(
} }
private fun loadDetails() = viewModelScope.launch { private fun loadDetails() = viewModelScope.launch {
_album.value = loadAlbumAsync.await() ?: throw NullPointerException("Album couldn't found") _album.postValue(
loadAlbumAsync.await() ?: throw NullPointerException("Album couldn't found")
)
} }
private fun loadAlbumInfoAsync(album: Album) = viewModelScope.async(Dispatchers.IO) { fun loadAlbumInfoAsync(album: Album) = viewModelScope.launch(Dispatchers.IO) {
_repository.albumInfo(album.artistName ?: "-", album.title ?: "-") val lastFmAlbum = _repository.albumInfo(album.artistName ?: "-", album.title ?: "-")
_lastFmAlbum.postValue(lastFmAlbum)
} }
private fun loadArtistAsync(artistId: Int) = viewModelScope.async(Dispatchers.IO) { fun loadArtistAsync(artistId: Int) = viewModelScope.launch(Dispatchers.IO) {
_repository.artistById(artistId) val artist = _repository.artistById(artistId)
_artist.postValue(artist)
} }
private val loadAlbumAsync: Deferred<Album?> private val loadAlbumAsync: Deferred<Album?>
get() = viewModelScope.async(Dispatchers.IO) { get() = viewModelScope.async(Dispatchers.IO) {
_repository.albumById(albumId).apply { _repository.albumById(albumId)
_artist.value = loadArtistAsync(artistId).await()
_lastFmAlbum.value = loadAlbumInfoAsync(this).await()
}
} }
} }