Upgraded to Glide v4 from Glide v3. Also, added some accessor methods

for track and album thumbnail ids.
This commit is contained in:
casey langen 2017-11-12 00:08:09 -08:00
parent 93156e99aa
commit 1d7e97005e
8 changed files with 45 additions and 36 deletions

View File

@ -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'

View File

@ -3,4 +3,5 @@ package io.casey.musikcube.remote.data
interface IAlbum : ICategoryValue {
val albumArtist: String
val albumArtistId: Long
val thumbnailId: Long
}

View File

@ -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

View File

@ -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
}

View File

@ -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]

View File

@ -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"
}
}
}

View File

@ -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<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
override fun onResourceReady(bitmap: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) {
override fun onResourceReady(bitmap: Bitmap?, transition: Transition<in Bitmap>?) {
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

View File

@ -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<String, GlideDrawable> {
override fun onException(
e: Exception?,
model: String?,
target: Target<GlideDrawable>?,
first: Boolean): Boolean
{
setMetadataDisplayMode(DisplayMode.NoArtwork)
lastArtworkUrl = null
return false
}
.apply(BITMAP_OPTIONS)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (!isPaused) {
preloadNextImage()
}
override fun onResourceReady(
resource: GlideDrawable, model: String, target: Target<GlideDrawable>,
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<Drawable>?, 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)
}
}