|
|
@ -17,27 +17,54 @@ import kotlinx.coroutines.runBlocking
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 图片加载类
|
|
|
|
* 图片加载类
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @author wangym
|
|
|
|
|
|
|
|
* @since 2021/7/28
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
object ImageLoader : ILoader {
|
|
|
|
object ImageLoader : ILoader {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 初始化Glide基础配置
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun init(
|
|
|
|
override fun init(
|
|
|
|
context: Context, memoryCategory: GlideBaseConfig.MemoryType
|
|
|
|
context: Context, memoryCategory: GlideBaseConfig.MemoryType
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Glide.get(context).setMemoryCategory(memoryCategory.memoryCategory)
|
|
|
|
Glide.get(context).setMemoryCategory(memoryCategory.memoryCategory)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置全局占位符配置
|
|
|
|
|
|
|
|
* @param globalHolderConfig 占位符配置
|
|
|
|
|
|
|
|
*/
|
|
|
|
fun setGlobalConfig(globalHolderConfig: GlideHolderConfig) {
|
|
|
|
fun setGlobalConfig(globalHolderConfig: GlideHolderConfig) {
|
|
|
|
GlobalConfigHelper.globalHolderConfig = globalHolderConfig
|
|
|
|
GlobalConfigHelper.globalHolderConfig = globalHolderConfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置全局过渡效果
|
|
|
|
|
|
|
|
* @param transitionConfig 全局过渡配置
|
|
|
|
|
|
|
|
*/
|
|
|
|
fun setGlobalTransition(transitionConfig: GlideTransitionConfig) {
|
|
|
|
fun setGlobalTransition(transitionConfig: GlideTransitionConfig) {
|
|
|
|
GlobalConfigHelper.globalTransition = transitionConfig.transition
|
|
|
|
GlobalConfigHelper.globalTransition = transitionConfig.transition
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载图片
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
* @param url 图片链接
|
|
|
|
|
|
|
|
* @param view 图片控件
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun load(context: Context, url: String?, view: ImageView) {
|
|
|
|
override fun load(context: Context, url: String?, view: ImageView) {
|
|
|
|
loadWithMode(context, url, view, GlideBaseConfig.LoadMode.DEFAULT)
|
|
|
|
loadWithMode(context, url, view, GlideBaseConfig.LoadMode.DEFAULT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载圆角图片
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
* @param url 图片链接
|
|
|
|
|
|
|
|
* @param view 图片控件
|
|
|
|
|
|
|
|
* @param radius 圆角弧度
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun loadRound(context: Context, url: String?, view: ImageView, radius: Float) {
|
|
|
|
override fun loadRound(context: Context, url: String?, view: ImageView, radius: Float) {
|
|
|
|
var request = GlobalConfigHelper.loadWithGlobalConfig(Glide.with(context).load(url))
|
|
|
|
var request = GlobalConfigHelper.loadWithGlobalConfig(Glide.with(context).load(url))
|
|
|
|
request = ConfigHelper.loadWithMod(request, GlideBaseConfig.LoadMode.DEFAULT)
|
|
|
|
request = ConfigHelper.loadWithMod(request, GlideBaseConfig.LoadMode.DEFAULT)
|
|
|
@ -48,6 +75,13 @@ object ImageLoader : ILoader {
|
|
|
|
loadIntoView(request, view)
|
|
|
|
loadIntoView(request, view)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 以模式,加载图片
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
* @param url 图片链接
|
|
|
|
|
|
|
|
* @param view 图片控件
|
|
|
|
|
|
|
|
* @param loadingMode 加载模式
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun loadWithMode(
|
|
|
|
override fun loadWithMode(
|
|
|
|
context: Context,
|
|
|
|
context: Context,
|
|
|
|
url: String?,
|
|
|
|
url: String?,
|
|
|
@ -59,6 +93,13 @@ object ImageLoader : ILoader {
|
|
|
|
loadIntoView(request, view)
|
|
|
|
loadIntoView(request, view)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载图片,带有占位图
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
* @param url 图片链接
|
|
|
|
|
|
|
|
* @param view 图片控件
|
|
|
|
|
|
|
|
* @param placeGlideHolder 占位图
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun loadWithPlaceHolder(
|
|
|
|
override fun loadWithPlaceHolder(
|
|
|
|
context: Context,
|
|
|
|
context: Context,
|
|
|
|
url: String,
|
|
|
|
url: String,
|
|
|
@ -73,22 +114,39 @@ object ImageLoader : ILoader {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载进控件
|
|
|
|
|
|
|
|
* @param requestBuilder 请求构建器
|
|
|
|
|
|
|
|
* @param view 图片控件
|
|
|
|
|
|
|
|
*/
|
|
|
|
private fun loadIntoView(requestBuilder: RequestBuilder<Drawable>, view: ImageView) {
|
|
|
|
private fun loadIntoView(requestBuilder: RequestBuilder<Drawable>, view: ImageView) {
|
|
|
|
requestBuilder.into(view)
|
|
|
|
requestBuilder.into(view)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun clearMemoryCache(context: Context){
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 清理内存缓存
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
override fun clearMemoryCache(context: Context) {
|
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
Glide.get(context).clearMemory()
|
|
|
|
Glide.get(context).clearMemory()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 清理磁盘缓存
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun clearDiskCache(context: Context) = runBlocking<Unit> {
|
|
|
|
override fun clearDiskCache(context: Context) = runBlocking<Unit> {
|
|
|
|
launch(Dispatchers.Default) {
|
|
|
|
launch(Dispatchers.Default) {
|
|
|
|
Glide.get(context).clearDiskCache()
|
|
|
|
Glide.get(context).clearDiskCache()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 清理缓存
|
|
|
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
|
|
|
*/
|
|
|
|
override fun clearAllCache(context: Context) = runBlocking<Unit> {
|
|
|
|
override fun clearAllCache(context: Context) = runBlocking<Unit> {
|
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
Glide.get(context).clearMemory()
|
|
|
|
Glide.get(context).clearMemory()
|
|
|
|