Use toBitmap().

This commit is contained in:
Isira Seneviratne 2023-03-01 05:02:51 +05:30
parent f9ab38add3
commit a8c8940026
2 changed files with 5 additions and 8 deletions

View File

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

View File

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