From 1d7e97005eeff20b6def1391c21d4b016dd48894 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 12 Nov 2017 00:08:09 -0800 Subject: [PATCH] Upgraded to Glide v4 from Glide v3. Also, added some accessor methods for track and album thumbnail ids. --- src/musikdroid/app/build.gradle | 5 +- .../io/casey/musikcube/remote/data/IAlbum.kt | 1 + .../io/casey/musikcube/remote/data/ITrack.kt | 1 + .../remote/data/impl/remote/RemoteAlbum.kt | 1 + .../remote/data/impl/remote/RemoteTrack.kt | 2 + .../musikcube/remote/playback/Metadata.kt | 2 + .../remote/playback/SystemService.kt | 11 ++-- .../remote/ui/view/MainMetadataView.kt | 58 +++++++++---------- 8 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/musikdroid/app/build.gradle b/src/musikdroid/app/build.gradle index 923277f69..d99450e01 100644 --- a/src/musikdroid/app/build.gradle +++ b/src/musikdroid/app/build.gradle @@ -70,17 +70,16 @@ dependencies { implementation 'org.slf4j:slf4j-android:1.7.21' implementation "android.arch.persistence.room:runtime:1.0.0" - annotationProcessor "android.arch.persistence.room:compiler:1.0.0" kapt "android.arch.persistence.room:compiler:1.0.0" compileOnly 'org.glassfish:javax.annotation:10.0-b28' implementation 'com.google.dagger:dagger:2.11' - annotationProcessor 'com.google.dagger:dagger-compiler:2.11' kapt 'com.google.dagger:dagger-compiler:2.11' implementation 'com.neovisionaries:nv-websocket-client:1.31' implementation 'com.squareup.okhttp3:okhttp:3.8.0' - implementation 'com.github.bumptech.glide:glide:3.8.0' + implementation 'com.github.bumptech.glide:glide:4.3.1' + kapt 'com.github.bumptech.glide:compiler:4.3.1' implementation 'io.reactivex.rxjava2:rxjava:2.1.0' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'com.google.android.exoplayer:exoplayer:r2.4.2' diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/IAlbum.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/IAlbum.kt index a6bb805df..02ea50b82 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/IAlbum.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/IAlbum.kt @@ -3,4 +3,5 @@ package io.casey.musikcube.remote.data interface IAlbum : ICategoryValue { val albumArtist: String val albumArtistId: Long + val thumbnailId: Long } \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/ITrack.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/ITrack.kt index 6fb11bec2..f851df71a 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/ITrack.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/ITrack.kt @@ -16,6 +16,7 @@ interface ITrack { val genreId: Long val artist: String val artistId: Long + val thumbnailId: Long fun getCategoryId(categoryType: String): Long fun toJson(): JSONObject diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteAlbum.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteAlbum.kt index 53ba1019d..b019deb9e 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteAlbum.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteAlbum.kt @@ -10,5 +10,6 @@ class RemoteAlbum(val json: JSONObject) : IAlbum { override val value: String get() = json.optString(Metadata.Album.TITLE, "") override val albumArtist: String get() = json.optString(Metadata.Album.ALBUM_ARTIST, "") override val albumArtistId: Long get() = json.optLong(Metadata.Album.ALBUM_ARTIST_ID, -1) + override val thumbnailId: Long get() = json.optLong(Metadata.Album.THUMBNAIL_ID, -1) override val type: String get() = Messages.Category.ALBUM } \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteTrack.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteTrack.kt index bff77fe25..1fb2fdd89 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteTrack.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/data/impl/remote/RemoteTrack.kt @@ -32,6 +32,8 @@ class RemoteTrack(val json: JSONObject) : ITrack { get() = json.optString(Metadata.Track.ARTIST, "") override val artistId: Long get() = json.optLong(Metadata.Track.ARTIST_ID, -1) + override val thumbnailId: Long + get() = json.optLong(Metadata.Track.THUMBNAIL_ID, -1) override fun getCategoryId(categoryType: String): Long { val idKey = CATEGORY_NAME_TO_ID[categoryType] diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/Metadata.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/Metadata.kt index 212f4b9f8..d6647f731 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/Metadata.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/Metadata.kt @@ -16,6 +16,7 @@ object Metadata { val GENRE_ID = "visual_genre_id" val ARTIST = "artist" val ARTIST_ID = "visual_artist_id" + val THUMBNAIL_ID = "thumbnail_id" } } @@ -25,6 +26,7 @@ object Metadata { val TITLE = "title" val ALBUM_ARTIST = "album_artist" val ALBUM_ARTIST_ID = "album_artist_id" + val THUMBNAIL_ID = "thumbnail_id" } } } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/SystemService.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/SystemService.kt index eea1e8d2b..5585745de 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/SystemService.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/playback/SystemService.kt @@ -17,9 +17,10 @@ import android.util.Log import android.view.KeyEvent import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.request.animation.GlideAnimation +import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.target.Target +import com.bumptech.glide.request.transition.Transition import io.casey.musikcube.remote.Application import io.casey.musikcube.remote.MainActivity import io.casey.musikcube.remote.R @@ -218,11 +219,11 @@ class SystemService : Service() { albumArtRequest = Glide .with(applicationContext) - .load(url) .asBitmap() - .diskCacheStrategy(DiskCacheStrategy.ALL) + .load(url) + .apply(BITMAP_OPTIONS) .into(object: SimpleTarget(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) { - override fun onResourceReady(bitmap: Bitmap?, glideAnimation: GlideAnimation?) { + override fun onResourceReady(bitmap: Bitmap?, transition: Transition?) { albumArtRequest = null if (albumArtModel.matches(artist, album)) { albumArt = bitmap @@ -490,6 +491,8 @@ class SystemService : Service() { var ACTION_SHUT_DOWN = "io.casey.musikcube.remote.SHUT_DOWN" var ACTION_SLEEP = "io.casey.musikcube.remote.SLEEP" + private val BITMAP_OPTIONS = RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL) + private val MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY_PAUSE or PlaybackStateCompat.ACTION_SKIP_TO_NEXT or diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/view/MainMetadataView.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/view/MainMetadataView.kt index 0f897971d..d75675efb 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/view/MainMetadataView.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/view/MainMetadataView.kt @@ -3,6 +3,7 @@ package io.casey.musikcube.remote.ui.view import android.content.Context import android.content.SharedPreferences import android.graphics.Color +import android.graphics.drawable.Drawable import android.support.annotation.AttrRes import android.text.SpannableStringBuilder import android.text.TextPaint @@ -17,9 +18,11 @@ import android.widget.FrameLayout import android.widget.ImageView import android.widget.TextView import com.bumptech.glide.Glide +import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.load.resource.drawable.GlideDrawable +import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target import io.casey.musikcube.remote.Application import io.casey.musikcube.remote.R @@ -246,37 +249,30 @@ class MainMetadataView : FrameLayout { Glide.with(context) .load(url) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .listener(object : RequestListener { - override fun onException( - e: Exception?, - model: String?, - target: Target?, - first: Boolean): Boolean - { - setMetadataDisplayMode(DisplayMode.NoArtwork) - lastArtworkUrl = null - return false - } + .apply(BITMAP_OPTIONS) + .listener(object : RequestListener { + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + if (!isPaused) { + preloadNextImage() + } - override fun onResourceReady( - resource: GlideDrawable, model: String, target: Target, - memory: Boolean, first: Boolean): Boolean { - if (!isPaused) { - preloadNextImage() + /* if the loadId doesn't match the current id, then the image was + loaded for a different song. throw it away. */ + if (albumArtModel.id != loadId) { + return true + } + else { + setMetadataDisplayMode(DisplayMode.Artwork) + return false + } } - /* if the loadId doesn't match the current id, then the image was - loaded for a different song. throw it away. */ - if (albumArtModel.id != loadId) { - return true - } - else { - setMetadataDisplayMode(DisplayMode.Artwork) + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + setMetadataDisplayMode(DisplayMode.NoArtwork) + lastArtworkUrl = null return false } - } - }) + }) .into(albumArtImageView) } else { @@ -299,8 +295,8 @@ class MainMetadataView : FrameLayout { val album = track.optString(Metadata.Track.ALBUM, "") if (!albumArtModel.matches(artist, album)) { - AlbumArtModel("", artist, album, AlbumArtModel.Size.Mega) { - _: AlbumArtModel, url: String? -> + AlbumArtModel("", artist, album, AlbumArtModel.Size.Mega) + { _: AlbumArtModel, url: String? -> val width = albumArtImageView.width val height = albumArtImageView.height Glide.with(context).load(url).downloadOnly(width, height) @@ -383,4 +379,8 @@ class MainMetadataView : FrameLayout { } } } + + private companion object { + val BITMAP_OPTIONS = RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL) + } }