From acc77478b7087870536829b79d455b43a7ab2e90 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Tue, 26 May 2020 04:16:12 +0530 Subject: [PATCH] Fix crashing --- .../activities/albums/AlbumDetailsActivity.kt | 2 ++ .../albums/AlbumDetailsViewModel.kt | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsActivity.kt index 98b30d23..65d6a1cc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsActivity.kt @@ -189,6 +189,8 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C } loadAlbumCover() simpleSongAdapter.swapDataSet(album.songs) + viewModel.loadArtistAsync(album.artistId) + viewModel.loadAlbumInfoAsync(album) } override fun moreAlbums(albums: List) { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsViewModel.kt index 5aa311e1..4debc3da 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/albums/AlbumDetailsViewModel.kt @@ -32,22 +32,23 @@ class AlbumDetailsViewModel( } 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) { - _repository.albumInfo(album.artistName ?: "-", album.title ?: "-") + fun loadAlbumInfoAsync(album: Album) = viewModelScope.launch(Dispatchers.IO) { + val lastFmAlbum = _repository.albumInfo(album.artistName ?: "-", album.title ?: "-") + _lastFmAlbum.postValue(lastFmAlbum) } - private fun loadArtistAsync(artistId: Int) = viewModelScope.async(Dispatchers.IO) { - _repository.artistById(artistId) + fun loadArtistAsync(artistId: Int) = viewModelScope.launch(Dispatchers.IO) { + val artist = _repository.artistById(artistId) + _artist.postValue(artist) } private val loadAlbumAsync: Deferred get() = viewModelScope.async(Dispatchers.IO) { - _repository.albumById(albumId).apply { - _artist.value = loadArtistAsync(artistId).await() - _lastFmAlbum.value = loadAlbumInfoAsync(this).await() - } + _repository.albumById(albumId) } } \ No newline at end of file