From 588fbd918acb90c00fe46f36611944a63ac863b3 Mon Sep 17 00:00:00 2001 From: yimiao Date: Thu, 22 Jul 2021 17:53:50 +0800 Subject: [PATCH] =?UTF-8?q?author:wangyimiao=20desc:=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=8A=A0=E8=BD=BD=E5=BA=93=E8=BF=87=E6=B8=A1?= =?UTF-8?q?=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/common/commonlibtest/MainActivity.java | 5 ++++- app/src/main/res/layout/activity_main.xml | 4 ++-- commonLib/proguard-rules.pro | 2 +- .../image/config/GlideTransitionConfig.kt | 14 ++++++++++++++ .../commonlib/image/loader/GlobalConfigHelper.kt | 16 +++++++++++++++- .../common/commonlib/image/loader/ImageLoader.kt | 6 ++++++ 6 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 commonLib/src/main/java/com/common/commonlib/image/config/GlideTransitionConfig.kt diff --git a/app/src/main/java/com/common/commonlibtest/MainActivity.java b/app/src/main/java/com/common/commonlibtest/MainActivity.java index bd0e243..cecc44d 100644 --- a/app/src/main/java/com/common/commonlibtest/MainActivity.java +++ b/app/src/main/java/com/common/commonlibtest/MainActivity.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.util.Log; import com.common.commonlib.image.config.GlideHolderConfig; +import com.common.commonlib.image.config.GlideTransitionConfig; import com.common.commonlib.image.loader.ImageLoader; import com.common.commonlib.net.RequestCallBack; import com.common.commonlib.net.interceptor.RequestHeadInterceptor; @@ -42,8 +43,10 @@ public class MainActivity extends AppCompatActivity { String url = "https://pics1.baidu.com/feed/48540923dd54564eb4cf53d7fabb2e84d0584f25.jpeg?token=d52b80fe96b3211270261b6c71b9efe2"; String url_1 = "https://pics6.baidu.com/feed/574e9258d109b3decb67a7bc7b814e87820a4cca.jpeg?token=56f8cb89982903d054e94bb89e34f84c&s=0D84C41006A072B8D38C054D030030E2"; GlideHolderConfig config = new GlideHolderConfig(); - config.setErrorId(R.drawable.ic_record_delete); + config.setHolderId(R.drawable.ic_record_delete); ImageLoader.INSTANCE.setGlobalConfig(config); + ImageLoader.INSTANCE.setTransition(new GlideTransitionConfig(1000)); + ImageLoader.INSTANCE.load(this, url_1, binding.iv); binding.tv.setOnClickListener(l -> { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ff5ad2f..5271a83 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,8 +7,8 @@ ): RequestBuilder { - return loadWithGlobalConfig(requestBuilder, globalHolderConfig) + return loadWithGlobalConfig(requestBuilder, globalHolderConfig, globalTransition) } fun loadWithGlobalConfig( requestBuilder: RequestBuilder, holderConfig: GlideHolderConfig? + ): RequestBuilder { + return loadWithGlobalConfig(requestBuilder, holderConfig, globalTransition) + } + + private fun loadWithGlobalConfig( + requestBuilder: RequestBuilder, + holderConfig: GlideHolderConfig?, + transition: DrawableTransitionOptions? ): RequestBuilder { var request = requestBuilder if (holderConfig != null) { @@ -42,6 +52,10 @@ object GlobalConfigHelper { request = request.fallback(holderConfig.fallBackId) } } + + if (transition != null) { + request = request.transition(transition) + } return request } } \ No newline at end of file diff --git a/commonLib/src/main/java/com/common/commonlib/image/loader/ImageLoader.kt b/commonLib/src/main/java/com/common/commonlib/image/loader/ImageLoader.kt index 2a57775..fd44290 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/loader/ImageLoader.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/loader/ImageLoader.kt @@ -4,8 +4,10 @@ import android.content.Context import android.widget.ImageView import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.common.commonlib.image.config.GlideBaseConfig import com.common.commonlib.image.config.GlideHolderConfig +import com.common.commonlib.image.config.GlideTransitionConfig import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -25,6 +27,10 @@ object ImageLoader : ILoader { GlobalConfigHelper.globalHolderConfig = globalHolderConfig } + fun setTransition(transitionConfig: GlideTransitionConfig) { + GlobalConfigHelper.globalTransition = transitionConfig.transition + } + override fun load(context: Context, url: String?, view: ImageView) { loadWithMode(context, url, view, GlideBaseConfig.LoadMode.DEFAULT) }