limiting the room bitmap loader image size, the notification icon size is relatively small and there's no cap on the image size

This commit is contained in:
Adam Brown 2022-02-21 13:03:31 +00:00
parent 65239e4034
commit eeb9785651
1 changed files with 7 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import android.graphics.Bitmap
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.signature.ObjectKey
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -28,6 +29,9 @@ import javax.inject.Singleton
@Singleton @Singleton
class BitmapLoader @Inject constructor(private val context: Context) { class BitmapLoader @Inject constructor(private val context: Context) {
private val iconWidth = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width)
private val iconHeight = context.resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height)
/** /**
* Get icon of a room. * Get icon of a room.
* If already in cache, use it, else load it and call BitmapLoaderListener.onBitmapsLoaded() when ready * If already in cache, use it, else load it and call BitmapLoaderListener.onBitmapsLoaded() when ready
@ -47,8 +51,10 @@ class BitmapLoader @Inject constructor(private val context: Context) {
Glide.with(context) Glide.with(context)
.asBitmap() .asBitmap()
.load(path) .load(path)
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888) .format(DecodeFormat.PREFER_ARGB_8888)
.submit() .signature(ObjectKey("room-icon-notification"))
.submit(iconWidth, iconHeight)
.get() .get()
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e, "decodeFile failed") Timber.e(e, "decodeFile failed")