From 598364b8e0a8226b956cb3fd05df0ff7a61b3112 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Thu, 19 Dec 2019 21:18:11 +0530 Subject: [PATCH] Fix user profile images --- .../mainactivity/home/BannerHomeFragment.kt | 7 +++++ .../player/full/FullPlayerFragment.kt | 29 ++++++++++--------- .../monkey/retromusic/loaders/ArtistLoader.kt | 28 ------------------ .../retromusic/util/CustomArtistImageUtil.kt | 2 +- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt index 92fe4534..ef80c892 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/home/BannerHomeFragment.kt @@ -32,6 +32,7 @@ import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroColorUtil import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy import kotlinx.android.synthetic.main.abs_playlists.* import kotlinx.android.synthetic.main.fragment_banner_home.* import kotlinx.android.synthetic.main.home_content.* @@ -59,6 +60,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba Glide.with(requireContext()) .load(File(PreferenceUtil.getInstance(requireContext()).profileImage, Constants.USER_PROFILE)) .asBitmap() + .diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true) .placeholder(R.drawable.ic_person_flat) .error(R.drawable.ic_person_flat) .into(userImage) @@ -198,12 +201,16 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba val request = Glide.with(requireContext()) if (PreferenceUtil.getInstance(requireContext()).bannerImage.isEmpty()) { request.load(day) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true) .placeholder(R.drawable.material_design_default) .error(R.drawable.material_design_default) .into(it) } else { request.load(File(PreferenceUtil.getInstance(requireContext()).bannerImage, USER_BANNER)) .asBitmap() + .diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true) .placeholder(R.drawable.material_design_default) .error(R.drawable.material_design_default) .into(it) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt index b09d7140..798410ba 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt @@ -24,10 +24,12 @@ import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics import code.name.monkey.retromusic.model.lyrics.Lyrics import code.name.monkey.retromusic.util.NavigationUtil import com.bumptech.glide.Glide -import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.fragment_full.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Callback { private lateinit var lyricsLayout: FrameLayout @@ -213,18 +215,19 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca private val compositeDisposable = CompositeDisposable() private fun updateArtistImage() { - compositeDisposable.addAll(ArtistLoader.getArtistFlowable(context!!, MusicPlayerRemote.currentSong.artistId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - ArtistGlideRequest.Builder.from(Glide.with(requireContext()), it) - .generatePalette(requireContext()) - .build().into(object : RetroMusicColoredTarget(artistImage) { - override fun onColorReady(color: Int) { + CoroutineScope(Dispatchers.IO).launch { + val artist = ArtistLoader.getArtist(requireContext(), MusicPlayerRemote.currentSong.artistId) + withContext(Dispatchers.Main) { + ArtistGlideRequest.Builder.from(Glide.with(requireContext()), artist) + .generatePalette(requireContext()) + .build() + .into(object : RetroMusicColoredTarget(artistImage) { + override fun onColorReady(color: Int) { - } - }) - }) + } + }) + } + } } override fun onQueueChanged() { diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt index 9b52211f..3eae37f3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt @@ -30,20 +30,6 @@ object ArtistLoader { PreferenceUtil.getInstance(context).artistDetailSongSortOrder } - fun getAllArtistsFlowable( - context: Context - ): Observable> { - return Observable.create { e -> - SongLoader.getSongsFlowable(SongLoader.makeSongCursor( - context, null, null, - getSongLoaderSortOrder(context)) - ).subscribe { songs -> - e.onNext(splitIntoArtists(AlbumLoader.splitIntoAlbums(songs))) - e.onComplete() - } - } - } - fun getAllArtists(context: Context): ArrayList { val songs = SongLoader.getSongs(SongLoader.makeSongCursor( context, @@ -53,20 +39,6 @@ object ArtistLoader { return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs)) } - fun getArtistsFlowable(context: Context, query: String): Observable> { - return Observable.create { e -> - SongLoader.getSongsFlowable(SongLoader.makeSongCursor( - context, - AudioColumns.ARTIST + " LIKE ?", - arrayOf("%$query%"), - getSongLoaderSortOrder(context)) - ).subscribe { songs -> - e.onNext(splitIntoArtists(AlbumLoader.splitIntoAlbums(songs))) - e.onComplete() - } - } - } - fun getArtists(context: Context, query: String): ArrayList { val songs = SongLoader.getSongs(SongLoader.makeSongCursor( context, diff --git a/app/src/main/java/code/name/monkey/retromusic/util/CustomArtistImageUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/CustomArtistImageUtil.kt index 523639f1..e67f8ba5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/CustomArtistImageUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/CustomArtistImageUtil.kt @@ -80,7 +80,7 @@ class CustomArtistImageUtil private constructor(context: Context) { if (succesful) { mPreferences.edit().putBoolean(getFileName(artist), true).commit() ArtistSignatureUtil.getInstance(App.getContext()).updateArtistSignature(artist.name) - App.getContext().getContentResolver().notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload + App.getContext().contentResolver.notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload } return null }