Fix not updating artist cover when selecting #926

This commit is contained in:
Hemanth S 2020-10-17 15:07:44 +05:30
parent 85bd49f391
commit 02ff1b92cb

View file

@ -14,6 +14,7 @@
*/ */
package code.name.monkey.retromusic.fragments.artists package code.name.monkey.retromusic.fragments.artists
import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.Spanned import android.text.Spanned
@ -137,7 +138,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
} }
} }
fun showArtist(artist: Artist) { private fun showArtist(artist: Artist) {
this.artist = artist this.artist = artist
loadArtistImage(artist) loadArtistImage(artist)
if (RetroUtil.isAllowedToDownloadMetadata(requireContext())) { if (RetroUtil.isAllowedToDownloadMetadata(requireContext())) {
@ -164,7 +165,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
songTitle.text = songText songTitle.text = songText
albumTitle.text = albumText albumTitle.text = albumText
songAdapter.swapDataSet(artist.songs.sortedBy { it.trackNumber }) songAdapter.swapDataSet(artist.songs.sortedBy { it.trackNumber })
artist.albums?.let { albumAdapter.swapDataSet(it) } albumAdapter.swapDataSet(artist.albums)
} }
private fun loadBiography( private fun loadBiography(
@ -174,7 +175,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
biography = null biography = null
this.lang = lang this.lang = lang
detailsViewModel.getArtistInfo(name, lang, null) detailsViewModel.getArtistInfo(name, lang, null)
.observe(viewLifecycleOwner, Observer { result -> .observe(viewLifecycleOwner, { result ->
when (result) { when (result) {
is Result.Loading -> println("Loading") is Result.Loading -> println("Loading")
is Result.Error -> println("Error") is Result.Error -> println("Error")
@ -282,6 +283,21 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
return true return true
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQUEST_CODE_SELECT_IMAGE -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let {
CustomArtistImageUtil.getInstance(requireContext())
.setCustomArtistImage(artist, it)
}
}
else -> if (resultCode == Activity.RESULT_OK) {
println("OK")
}
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_artist_detail, menu) inflater.inflate(R.menu.menu_artist_detail, menu)