Merge branch 'picasso-cache-stablekey' into 'develop'
Use Picasso stableKey for better caching against pre-signed URLs Closes #133 See merge request funkwhale/funkwhale-android!269
This commit is contained in:
commit
cf5d6a21fe
|
@ -10,6 +10,7 @@ import audio.funkwhale.ffa.R
|
||||||
import audio.funkwhale.ffa.databinding.RowPlaylistBinding
|
import audio.funkwhale.ffa.databinding.RowPlaylistBinding
|
||||||
import audio.funkwhale.ffa.fragments.FFAAdapter
|
import audio.funkwhale.ffa.fragments.FFAAdapter
|
||||||
import audio.funkwhale.ffa.model.Playlist
|
import audio.funkwhale.ffa.model.Playlist
|
||||||
|
import audio.funkwhale.ffa.utils.maybeLoad
|
||||||
import audio.funkwhale.ffa.utils.toDurationString
|
import audio.funkwhale.ffa.utils.toDurationString
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
|
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
|
||||||
|
@ -80,7 +81,7 @@ class PlaylistsAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.load(url)
|
.maybeLoad(url)
|
||||||
.transform(RoundedCornersTransformation(32, 0, corner))
|
.transform(RoundedCornersTransformation(32, 0, corner))
|
||||||
.into(imageView)
|
.into(imageView)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import audio.funkwhale.ffa.R
|
||||||
import audio.funkwhale.ffa.activities.MainActivity
|
import audio.funkwhale.ffa.activities.MainActivity
|
||||||
import audio.funkwhale.ffa.model.Track
|
import audio.funkwhale.ffa.model.Track
|
||||||
import audio.funkwhale.ffa.utils.AppContext
|
import audio.funkwhale.ffa.utils.AppContext
|
||||||
|
import audio.funkwhale.ffa.utils.maybeLoad
|
||||||
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
|
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -68,7 +69,7 @@ class MediaControlsManager(
|
||||||
.run {
|
.run {
|
||||||
coverUrl?.let {
|
coverUrl?.let {
|
||||||
try {
|
try {
|
||||||
setLargeIcon(Picasso.get().load(coverUrl).get())
|
setLargeIcon(Picasso.get().maybeLoad(coverUrl).get())
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import audio.funkwhale.ffa.utils.Request
|
||||||
import audio.funkwhale.ffa.utils.RequestBus
|
import audio.funkwhale.ffa.utils.RequestBus
|
||||||
import audio.funkwhale.ffa.utils.Response
|
import audio.funkwhale.ffa.utils.Response
|
||||||
import audio.funkwhale.ffa.utils.log
|
import audio.funkwhale.ffa.utils.log
|
||||||
|
import audio.funkwhale.ffa.utils.maybeLoad
|
||||||
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
|
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
|
||||||
import audio.funkwhale.ffa.utils.onApi
|
import audio.funkwhale.ffa.utils.onApi
|
||||||
import com.google.android.exoplayer2.C
|
import com.google.android.exoplayer2.C
|
||||||
|
@ -376,7 +377,7 @@ class PlayerService : Service() {
|
||||||
runBlocking(IO) {
|
runBlocking(IO) {
|
||||||
this@apply.putBitmap(
|
this@apply.putBitmap(
|
||||||
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
|
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
|
||||||
Picasso.get().load(coverUrl).get()
|
Picasso.get().maybeLoad(coverUrl).get()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
|
@ -62,6 +62,8 @@ fun <T, U> Int.onApi(block: () -> T, elseBlock: (() -> U)) {
|
||||||
fun Picasso.maybeLoad(url: String?): RequestCreator {
|
fun Picasso.maybeLoad(url: String?): RequestCreator {
|
||||||
return if (url == null) load(R.drawable.cover)
|
return if (url == null) load(R.drawable.cover)
|
||||||
else load(url)
|
else load(url)
|
||||||
|
// Remote storage may have (pre-signed) ephemeral credentials in the query string
|
||||||
|
.stableKey(url.replace(Regex("\\?.*$"), ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Request.authorize(context: Context, oAuth: OAuth): Request {
|
fun Request.authorize(context: Context, oAuth: OAuth): Request {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Use Picasso stableKey for better caching against pre-signed URLs (thanks @rickosborne)
|
Loading…
Reference in New Issue