Fix issue with gif search and emoji loading on lowmem devices.

This commit is contained in:
Alex Hart
2021-05-05 09:59:05 -03:00
committed by Cody Henthorne
parent 5e2a3ac644
commit 02d060ca0a
5 changed files with 85 additions and 10 deletions

View File

@@ -0,0 +1,40 @@
package org.thoughtcrime.securesms.emoji
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.bumptech.glide.load.Option
import com.bumptech.glide.load.Options
import com.bumptech.glide.load.ResourceDecoder
import com.bumptech.glide.load.engine.Resource
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapResource
import java.io.InputStream
/**
* Allows fine grain control over how we decode Emoji pages via a scale factor.
*
* This can be set via RequestOptions on a Glide request:
*
* ```
* .apply(RequestOptions().set(EmojiBitmapDecoder.OPTION, inSampleSize)
* ```
*/
class EmojiBitmapDecoder(private val bitmapPool: BitmapPool) : ResourceDecoder<InputStream, Bitmap> {
override fun handles(source: InputStream, options: Options): Boolean {
return options.get(OPTION)?.let { it > 1 } ?: false
}
override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<Bitmap>? {
val bitmapOptions = BitmapFactory.Options()
bitmapOptions.inSampleSize = requireNotNull(options.get(OPTION))
return BitmapResource.obtain(BitmapFactory.decodeStream(source, null, bitmapOptions), bitmapPool)
}
companion object {
@JvmField
val OPTION: Option<Int> = Option.memory("emoji_sample_size", 1)
}
}