diff --git a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt index a5151d44f..a4cbf3937 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt @@ -3,9 +3,9 @@ package com.github.libretube.helpers import android.content.Context import android.graphics.Bitmap import android.graphics.BitmapFactory -import android.graphics.drawable.BitmapDrawable import android.net.Uri import android.widget.ImageView +import androidx.core.graphics.drawable.toBitmap import coil.ImageLoader import coil.disk.DiskCache import coil.load @@ -65,10 +65,7 @@ object ImageHelper { fun getAsync(context: Context, url: String?, onSuccess: (Bitmap) -> Unit) { val request = ImageRequest.Builder(context) .data(url) - .target { result -> - val bitmap = (result as BitmapDrawable).bitmap - onSuccess.invoke(bitmap) - } + .target { onSuccess(it.toBitmap()) } .build() imageLoader.enqueue(request) diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index 761130a6f..5b86bc4c7 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -7,7 +7,6 @@ import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.graphics.BitmapFactory -import android.graphics.drawable.BitmapDrawable import android.os.Build import android.os.Bundle import android.support.v4.media.MediaDescriptionCompat @@ -16,6 +15,7 @@ import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.PlaybackStateCompat import androidx.annotation.DrawableRes import androidx.core.app.NotificationCompat +import androidx.core.graphics.drawable.toBitmap import androidx.core.os.bundleOf import coil.request.ImageRequest import com.github.libretube.R @@ -122,8 +122,8 @@ class NowPlayingNotification( private fun enqueueThumbnailRequest(callback: PlayerNotificationManager.BitmapCallback) { val request = ImageRequest.Builder(context) .data(streams?.thumbnailUrl) - .target { result -> - val bm = (result as BitmapDrawable).bitmap + .target { + val bm = it.toBitmap() // returns the bitmap on Android 13+, for everything below scaled down to a square bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { ImageHelper.getSquareBitmap(bm)