From 195322ce95df6bfed533f675f694cc00d78acc02 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 19 Nov 2021 21:28:27 -0800 Subject: Replace tempFile with glide ref --- .../pitchedapps/frost/activities/ImageActivity.kt | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index 6d618347..c381591e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -43,6 +43,7 @@ import ca.allanwang.kau.utils.tint import ca.allanwang.kau.utils.toast import ca.allanwang.kau.utils.withAlpha import ca.allanwang.kau.utils.withMinAlpha +import com.github.piasy.biv.loader.ImageLoader import com.github.piasy.biv.view.ImageShownCallback import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -102,7 +103,7 @@ class ImageActivity : KauBaseActivity() { /** * Reference to the temporary file path */ - internal var tempFile: File? = null + internal val tempFile: File? get() = binding.imagePhoto.currentImageFile private lateinit var dragHelper: ViewDragHelper @@ -176,19 +177,19 @@ class ImageActivity : KauBaseActivity() { setContentView(binding.root) binding.init() launch(CoroutineExceptionHandler { _, throwable -> loadError(throwable) }) { - val tempFile = downloadTempImage() - this@ImageActivity.tempFile = tempFile +// val tempFile = downloadTempImage() +// this@ImageActivity.tempFile = tempFile binding.showImage(trueImageUrl.await()) } } private fun ActivityImage2Binding.showImage(url: String) { - imageProgress.fadeOut() imagePhoto.showImage(Uri.parse(url)) imagePhoto.setImageShownCallback(object : ImageShownCallback { override fun onThumbnailShown() {} override fun onMainImageShown() { + imageProgress.fadeOut() imagePhoto.animate().alpha(1f).scaleXY(1f).start() } }) @@ -227,6 +228,24 @@ class ImageActivity : KauBaseActivity() { setOnClickListener { state.onClick(this@ImageActivity) } } + imagePhoto.setImageLoaderCallback(object : ImageLoader.Callback { + override fun onCacheHit(imageType: Int, image: File?) {} + + override fun onCacheMiss(imageType: Int, image: File?) {} + + override fun onStart() {} + + override fun onProgress(progress: Int) {} + + override fun onFinish() {} + + override fun onSuccess(image: File) {} + + override fun onFail(error: Exception) { + loadError(error) + } + }) + imageProgress.tint(foregroundTint) error.apply { invisible() -- cgit v1.2.3