Move the bitmap scaling logic to the ImageHelper

This commit is contained in:
Bnyro 2023-01-15 13:20:33 +01:00
parent fe42714c52
commit a52bd6247c
2 changed files with 19 additions and 13 deletions

View File

@ -88,4 +88,20 @@ object ImageHelper {
}
return null
}
/**
* Get a squared bitmap with the same width and height from a bitmap
* @param bitmap The bitmap to resize
*/
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
)
}
}

View File

@ -118,22 +118,12 @@ class NowPlayingNotification(
ImageHelper.imageLoader.enqueue(request)
// returns the bitmap on Android 13+, for everything below scaled down to a square
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) getSquareBitmap(bitmap) else bitmap
return if (
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
) ImageHelper.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
*/