본문 바로가기
Android

[Glide] 이미지 로딩 속도 체크하기

by 너츠너츠 2022. 12. 4.

.listener를 붙여서 RequestListener 구현 -> onResourceReady 안에서 준비완료된 시간을 측정하면 됩니다.

val glideStartTime = System.currentTimeMillis()

Glide.with(this)
   .load(imageUrl)
   .listener(object : RequestListener<Drawable> {
        override fun onLoadFailed(
            e: GlideException?,
            model: Any?,
            target: Target<Drawable>?,
            isFirstResource: Boolean,
        ): Boolean {
              return false
        }

        override fun onResourceReady(
             resource: Drawable?,
             model: Any?,
             target: Target<Drawable>?,
             dataSource: DataSource?,
             isFirstResource: Boolean,
         ): Boolean {
             val glideEndTime = System.currentTimeMillis()
             Log.d("ImageProcessTime", "$funcName processTime: ${(glideEndTime - glideStartTime) / 1000}")
//           Log.d("check@@@", "${resource} ${model} ${target} ${dataSource} ${isFirstResource}")
             return false
         }
     })
     .into(imageView)
반응형

댓글