Use coroutine instead of Handler
Summary: ^ Reviewed By: LukeDefeo Differential Revision: D39848640 fbshipit-source-id: 31e9ecc6e52105c61c8765d5d8b4c2c493026416
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ee9415a8d4
commit
ff3fb338ab
@@ -8,8 +8,9 @@
|
|||||||
package com.facebook.flipper.plugins.uidebugger.common
|
package com.facebook.flipper.plugins.uidebugger.common
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.os.Handler
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import android.os.Looper
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/** BitmapPool is intended to be used on the main thread. In other words, it is not thread-safe. */
|
/** BitmapPool is intended to be used on the main thread. In other words, it is not thread-safe. */
|
||||||
class BitmapPool(private val config: Bitmap.Config = Bitmap.Config.RGB_565) {
|
class BitmapPool(private val config: Bitmap.Config = Bitmap.Config.RGB_565) {
|
||||||
@@ -19,7 +20,7 @@ class BitmapPool(private val config: Bitmap.Config = Bitmap.Config.RGB_565) {
|
|||||||
fun readyForReuse()
|
fun readyForReuse()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var handler: Handler = Handler(Looper.getMainLooper())
|
val mainScope = CoroutineScope(Dispatchers.Main)
|
||||||
|
|
||||||
private val container: MutableMap<String, MutableList<Bitmap>> = mutableMapOf()
|
private val container: MutableMap<String, MutableList<Bitmap>> = mutableMapOf()
|
||||||
private var isRecycled = false
|
private var isRecycled = false
|
||||||
@@ -54,7 +55,8 @@ class BitmapPool(private val config: Bitmap.Config = Bitmap.Config.RGB_565) {
|
|||||||
inner class LeasedBitmap(override val bitmap: Bitmap) : ReusableBitmap {
|
inner class LeasedBitmap(override val bitmap: Bitmap) : ReusableBitmap {
|
||||||
override fun readyForReuse() {
|
override fun readyForReuse() {
|
||||||
val key = generateKey(bitmap.width, bitmap.height)
|
val key = generateKey(bitmap.width, bitmap.height)
|
||||||
handler.post {
|
|
||||||
|
mainScope.launch {
|
||||||
if (isRecycled) {
|
if (isRecycled) {
|
||||||
bitmap.recycle()
|
bitmap.recycle()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user