mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +05:30
scale imgages differently
This commit is contained in:
parent
588f99edba
commit
91fc986f41
@ -105,28 +105,33 @@ class NowPlayingNotification(
|
|||||||
callback: PlayerNotificationManager.BitmapCallback
|
callback: PlayerNotificationManager.BitmapCallback
|
||||||
): Bitmap? {
|
): Bitmap? {
|
||||||
var bitmap: Bitmap? = null
|
var bitmap: Bitmap? = null
|
||||||
var resizedBitmap: Bitmap? = null
|
|
||||||
|
|
||||||
val request = ImageRequest.Builder(context)
|
val request = ImageRequest.Builder(context)
|
||||||
.data(streams?.thumbnailUrl)
|
.data(streams?.thumbnailUrl)
|
||||||
.target { result ->
|
.target { result ->
|
||||||
bitmap = (result as BitmapDrawable).bitmap
|
bitmap = (result as BitmapDrawable).bitmap
|
||||||
resizedBitmap = Bitmap.createScaledBitmap(
|
|
||||||
bitmap!!,
|
|
||||||
bitmap!!.width,
|
|
||||||
bitmap!!.width,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
ImageHelper.imageLoader.enqueue(request)
|
ImageHelper.imageLoader.enqueue(request)
|
||||||
|
|
||||||
// returns the scaled bitmap if it got fetched successfully
|
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
||||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) resizedBitmap else bitmap
|
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) getSquareBitmap(bitmap) else bitmap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSquareBitmap(bitmap: Bitmap?): Bitmap? {
|
||||||
|
bitmap ?: return null
|
||||||
|
val newSize = minOf(bitmap.width, bitmap.height)
|
||||||
|
return Bitmap.createBitmap(
|
||||||
|
bitmap,
|
||||||
|
(bitmap.width - newSize) / 2,
|
||||||
|
(bitmap.height - newSize) / 2,
|
||||||
|
newSize,
|
||||||
|
newSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [MediaSessionCompat] amd a [MediaSessionConnector] for the player
|
* Creates a [MediaSessionCompat] amd a [MediaSessionConnector] for the player
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user