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) }