From 407686ca5b4dc6fdd450395fa37aca0e125f3ebb Mon Sep 17 00:00:00 2001 From: juntao Date: Tue, 17 Nov 2020 17:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=93=BE=E6=8E=A5=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E5=9B=BE=E7=89=87=E5=A4=8D=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gh/common/util/ImageUtils.kt | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/gh/common/util/ImageUtils.kt b/app/src/main/java/com/gh/common/util/ImageUtils.kt index e0866f87d6..9d7e100731 100644 --- a/app/src/main/java/com/gh/common/util/ImageUtils.kt +++ b/app/src/main/java/com/gh/common/util/ImageUtils.kt @@ -286,61 +286,61 @@ object ImageUtils { */ @JvmStatic fun display(view: SimpleDraweeView?, url: String?) { - url?.let { - val width = view?.layoutParams?.width - val height = view?.layoutParams?.height + if (url.isNullOrEmpty()) return - var lowResUrl = "" - var highResUrl = "" + val width = view?.layoutParams?.width + val height = view?.layoutParams?.height - // 找同一图片地址已加载过的图片作为低质量预览图 - // TODO 根据实际请求大小(w_width)来避免小图用大图作为低质量图片 - for (cachedImageUrl in mImageUrlCacheSet) { - if (cachedImageUrl.contains(url)) { - lowResUrl = cachedImageUrl - break - } + var lowResUrl = "" + var highResUrl = "" + + // 找同一图片地址已加载过的图片作为低质量预览图 + // TODO 根据实际请求大小(w_width)来避免小图用大图作为低质量图片 + for (cachedImageUrl in mImageUrlCacheSet) { + if (cachedImageUrl.contains(url)) { + lowResUrl = cachedImageUrl + break } + } - val loadImageClosure: (autoPlay: Boolean, highResUrl: String, lowResUrl: String) -> Unit = { autoPlay, hUrl, lUrl -> - view?.controller = Fresco.newDraweeControllerBuilder() - .setImageRequest(ImageRequest.fromUri(hUrl)) - .apply { - if (lUrl.isNotEmpty() - && lUrl != hUrl - && hUrl != view?.getTag(R.string.highResImageTag)) { - lowResImageRequest = ImageRequest.fromUri(lUrl) - } - autoPlayAnimations = autoPlay + val loadImageClosure: (autoPlay: Boolean, highResUrl: String, lowResUrl: String) -> Unit = { autoPlay, hUrl, lUrl -> + view?.controller = Fresco.newDraweeControllerBuilder() + .setImageRequest(ImageRequest.fromUri(hUrl)) + .apply { + if (lUrl.isNotEmpty() + && lUrl != hUrl + && hUrl != view?.getTag(R.string.highResImageTag)) { + lowResImageRequest = ImageRequest.fromUri(lUrl) } - .build() + autoPlayAnimations = autoPlay + } + .build() - view?.setTag(R.string.highResImageTag, highResUrl) + view?.setTag(R.string.highResImageTag, highResUrl) + } + + val shouldLoadAsGif = url.endsWith(".gif") && view?.getTag(R.id.tag_show_gif) != false + + if (shouldLoadAsGif && view?.tag == url) return + + if (width != null && width > 0) { + highResUrl = if (shouldLoadAsGif) { + resizeGif(url, width, height ?: 0) + } else { + getTransformLimitUrl(url, width, view.context) ?: "" } - - val shouldLoadAsGif = it.endsWith(".gif") && view?.getTag(R.id.tag_show_gif) != false - - if (shouldLoadAsGif && view?.tag == url) return - - if (width != null && width > 0) { + loadImageClosure(shouldLoadAsGif, highResUrl, lowResUrl) + } else { + view?.post { highResUrl = if (shouldLoadAsGif) { - resizeGif(url, width, height ?: 0) + resizeGif(url, view.width, height ?: 0) } else { - getTransformLimitUrl(url, width, view.context) ?: "" + getTransformLimitUrl(url, view.width, view.context) ?: "" } loadImageClosure(shouldLoadAsGif, highResUrl, lowResUrl) - } else { - view?.post { - highResUrl = if (shouldLoadAsGif) { - resizeGif(url, view.width, height ?: 0) - } else { - getTransformLimitUrl(url, view.width, view.context) ?: "" - } - loadImageClosure(shouldLoadAsGif, highResUrl, lowResUrl) - } } - view?.tag = url } + view?.tag = url } // Wifi/4G:x2 traffic:x1