mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #3210 from Isira-Seneviratne/toBitmap
Use toBitmap() extension function.
This commit is contained in:
commit
58374ddba1
@ -3,9 +3,9 @@ package com.github.libretube.helpers
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.drawable.BitmapDrawable
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.disk.DiskCache
|
import coil.disk.DiskCache
|
||||||
import coil.load
|
import coil.load
|
||||||
@ -65,10 +65,7 @@ object ImageHelper {
|
|||||||
fun getAsync(context: Context, url: String?, onSuccess: (Bitmap) -> Unit) {
|
fun getAsync(context: Context, url: String?, onSuccess: (Bitmap) -> Unit) {
|
||||||
val request = ImageRequest.Builder(context)
|
val request = ImageRequest.Builder(context)
|
||||||
.data(url)
|
.data(url)
|
||||||
.target { result ->
|
.target { onSuccess(it.toBitmap()) }
|
||||||
val bitmap = (result as BitmapDrawable).bitmap
|
|
||||||
onSuccess.invoke(bitmap)
|
|
||||||
}
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
imageLoader.enqueue(request)
|
imageLoader.enqueue(request)
|
||||||
|
@ -7,7 +7,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.drawable.BitmapDrawable
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.media.MediaDescriptionCompat
|
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 android.support.v4.media.session.PlaybackStateCompat
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -122,8 +122,8 @@ class NowPlayingNotification(
|
|||||||
private fun enqueueThumbnailRequest(callback: PlayerNotificationManager.BitmapCallback) {
|
private fun enqueueThumbnailRequest(callback: PlayerNotificationManager.BitmapCallback) {
|
||||||
val request = ImageRequest.Builder(context)
|
val request = ImageRequest.Builder(context)
|
||||||
.data(streams?.thumbnailUrl)
|
.data(streams?.thumbnailUrl)
|
||||||
.target { result ->
|
.target {
|
||||||
val bm = (result as BitmapDrawable).bitmap
|
val bm = it.toBitmap()
|
||||||
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
||||||
bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||||
ImageHelper.getSquareBitmap(bm)
|
ImageHelper.getSquareBitmap(bm)
|
||||||
|
Loading…
Reference in New Issue
Block a user