From e32f3a1f9dce29654b36a8e56d6ae883b5fbb8dd Mon Sep 17 00:00:00 2001 From: yimiao Date: Wed, 28 Jul 2021 14:57:08 +0800 Subject: [PATCH] =?UTF-8?q?author:wangyimiao=20desc:=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/common/commonlib/CommonApplication.kt | 11 ++++ .../commonlib/image/config/GlideBaseConfig.kt | 6 ++ .../image/config/GlideHolderConfig.kt | 3 + .../image/config/GlideTransitionConfig.kt | 3 + .../commonlib/image/loader/ConfigHelper.kt | 17 ++++++ .../image/loader/GlobalConfigHelper.kt | 10 ++++ .../common/commonlib/image/loader/ILoader.kt | 10 +++- .../commonlib/image/loader/ImageLoader.kt | 60 ++++++++++++++++++- .../image/module/OkHttpLibraryGlideModule.kt | 3 + .../common/commonlib/log/LogSecureHelper.kt | 3 + .../java/com/common/commonlib/log/Logger.kt | 6 ++ .../com/common/commonlib/net/BaseObserve.kt | 3 + .../common/commonlib/net/RequestCallBack.kt | 3 + .../common/commonlib/net/RequestManager.kt | 3 + .../common/commonlib/net/bean/BaseResponse.kt | 3 + .../common/commonlib/net/bean/RequestParam.kt | 3 + .../net/interceptor/BaseUrlInterceptor.kt | 3 + .../net/interceptor/RequestHeadInterceptor.kt | 3 + .../interceptor/ResponseHeadInterceptor.kt | 4 +- .../com/common/commonlib/utils/FTPUtils.kt | 3 + .../com/common/commonlib/utils/SpManager.kt | 3 + .../commonlib/view/SpaceItemDecoration.java | 6 ++ 22 files changed, 165 insertions(+), 4 deletions(-) diff --git a/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt b/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt index 0386b77..4165b13 100644 --- a/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt +++ b/commonLib/src/main/java/com/common/commonlib/CommonApplication.kt @@ -4,10 +4,21 @@ import android.annotation.SuppressLint import android.app.Application import android.content.Context +/** + * 基础Application + * + * @author wangym + * @since 2021/7/28 + */ @SuppressLint("StaticFieldLeak") object CommonApplication : Application() { private var commonContext: Context? = null + override fun onCreate() { + super.onCreate() + intLibs(this) + } + fun intLibs(context: Context) { commonContext = context } diff --git a/commonLib/src/main/java/com/common/commonlib/image/config/GlideBaseConfig.kt b/commonLib/src/main/java/com/common/commonlib/image/config/GlideBaseConfig.kt index 49f17d1..1baf07e 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/config/GlideBaseConfig.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/config/GlideBaseConfig.kt @@ -2,6 +2,12 @@ package com.common.commonlib.image.config import com.bumptech.glide.MemoryCategory +/** + * 图片加载基础配置 + * + * @author wangym + * @since 2021/7/28 + */ object GlideBaseConfig { enum class MemoryType(var memoryCategory: MemoryCategory) { diff --git a/commonLib/src/main/java/com/common/commonlib/image/config/GlideHolderConfig.kt b/commonLib/src/main/java/com/common/commonlib/image/config/GlideHolderConfig.kt index 4cb1446..e6360b2 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/config/GlideHolderConfig.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/config/GlideHolderConfig.kt @@ -4,6 +4,9 @@ import android.graphics.drawable.Drawable /** * 占位符配置 + * + * @author wangym + * @since 2021/7/28 */ class GlideHolderConfig { /** diff --git a/commonLib/src/main/java/com/common/commonlib/image/config/GlideTransitionConfig.kt b/commonLib/src/main/java/com/common/commonlib/image/config/GlideTransitionConfig.kt index 3e77c55..5ece0a3 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/config/GlideTransitionConfig.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/config/GlideTransitionConfig.kt @@ -5,6 +5,9 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions /** * 转换配置 * @param time 动画时长 + * + * @author wangym + * @since 2021/7/28 */ class GlideTransitionConfig(time: Int?) { val transition: DrawableTransitionOptions = if (time != null) { diff --git a/commonLib/src/main/java/com/common/commonlib/image/loader/ConfigHelper.kt b/commonLib/src/main/java/com/common/commonlib/image/loader/ConfigHelper.kt index bd70fbf..e54ad1c 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/loader/ConfigHelper.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/loader/ConfigHelper.kt @@ -8,9 +8,19 @@ import com.common.commonlib.image.config.GlideBaseConfig /** * 加载配置辅助类 + * + * @author wangym + * @since 2021/7/28 */ object ConfigHelper { + /** + * 带有过渡效果的加载 + * @param requestBuilder 请求构建器 + * @param transformations 过渡效果 + * + * @return 请求构建器 + */ fun loadWithTransformation( requestBuilder: RequestBuilder, transformations: List @@ -22,6 +32,13 @@ object ConfigHelper { return temp } + /** + * 带有缓存模式的加载 + * @param requestBuilder 请求构建器 + * @param loadingMode 加载缓存模式 + * + * @return 请求构建器 + */ fun loadWithMod( requestBuilder: RequestBuilder, loadingMode: GlideBaseConfig.LoadMode diff --git a/commonLib/src/main/java/com/common/commonlib/image/loader/GlobalConfigHelper.kt b/commonLib/src/main/java/com/common/commonlib/image/loader/GlobalConfigHelper.kt index 15b232d..bf254ec 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/loader/GlobalConfigHelper.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/loader/GlobalConfigHelper.kt @@ -7,9 +7,19 @@ import com.common.commonlib.image.config.GlideHolderConfig /** * 全局配置适配器 + * + * @author wangym + * @since 2021/7/28 */ object GlobalConfigHelper { + /** + * 全局占位符配置 + */ var globalHolderConfig: GlideHolderConfig? = null + + /** + * 全局过渡效果 + */ var globalTransition: DrawableTransitionOptions? = null fun loadWithGlobalConfig(requestBuilder: RequestBuilder): RequestBuilder { diff --git a/commonLib/src/main/java/com/common/commonlib/image/loader/ILoader.kt b/commonLib/src/main/java/com/common/commonlib/image/loader/ILoader.kt index d90d9ce..36326a5 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/loader/ILoader.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/loader/ILoader.kt @@ -6,7 +6,10 @@ import com.common.commonlib.image.config.GlideBaseConfig import com.common.commonlib.image.config.GlideHolderConfig /** - * 加载器接口 + * 图片加载器接口 + * + * @author wangym + * @since 2021/7/28 */ interface ILoader { @@ -64,16 +67,19 @@ interface ILoader { /** * 清理内存缓存 + * @param context 上下文 */ fun clearMemoryCache(context: Context) /** * 清理磁盘缓存 + * @param context 上下文 */ fun clearDiskCache(context: Context) /** - * 清理所有缓存 + * 清理缓存 + * @param context 上下文 */ fun clearAllCache(context: Context) } \ 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 b6c7cc2..9fc4230 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 @@ -17,27 +17,54 @@ import kotlinx.coroutines.runBlocking /** * 图片加载类 + * + * @author wangym + * @since 2021/7/28 */ object ImageLoader : ILoader { + /** + * 初始化Glide基础配置 + */ override fun init( context: Context, memoryCategory: GlideBaseConfig.MemoryType ) { Glide.get(context).setMemoryCategory(memoryCategory.memoryCategory) } + /** + * 设置全局占位符配置 + * @param globalHolderConfig 占位符配置 + */ fun setGlobalConfig(globalHolderConfig: GlideHolderConfig) { GlobalConfigHelper.globalHolderConfig = globalHolderConfig } + /** + * 设置全局过渡效果 + * @param transitionConfig 全局过渡配置 + */ fun setGlobalTransition(transitionConfig: GlideTransitionConfig) { GlobalConfigHelper.globalTransition = transitionConfig.transition } + /** + * 加载图片 + * @param context 上下文 + * @param url 图片链接 + * @param view 图片控件 + */ override fun load(context: Context, url: String?, view: ImageView) { 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) { var request = GlobalConfigHelper.loadWithGlobalConfig(Glide.with(context).load(url)) request = ConfigHelper.loadWithMod(request, GlideBaseConfig.LoadMode.DEFAULT) @@ -48,6 +75,13 @@ object ImageLoader : ILoader { loadIntoView(request, view) } + /** + * 以模式,加载图片 + * @param context 上下文 + * @param url 图片链接 + * @param view 图片控件 + * @param loadingMode 加载模式 + */ override fun loadWithMode( context: Context, url: String?, @@ -59,6 +93,13 @@ object ImageLoader : ILoader { loadIntoView(request, view) } + /** + * 加载图片,带有占位图 + * @param context 上下文 + * @param url 图片链接 + * @param view 图片控件 + * @param placeGlideHolder 占位图 + */ override fun loadWithPlaceHolder( context: Context, url: String, @@ -73,22 +114,39 @@ object ImageLoader : ILoader { ) } + /** + * 加载进控件 + * @param requestBuilder 请求构建器 + * @param view 图片控件 + */ private fun loadIntoView(requestBuilder: RequestBuilder, view: ImageView) { requestBuilder.into(view) } - override fun clearMemoryCache(context: Context){ + /** + * 清理内存缓存 + * @param context 上下文 + */ + override fun clearMemoryCache(context: Context) { GlobalScope.launch(Dispatchers.Main) { Glide.get(context).clearMemory() } } + /** + * 清理磁盘缓存 + * @param context 上下文 + */ override fun clearDiskCache(context: Context) = runBlocking { launch(Dispatchers.Default) { Glide.get(context).clearDiskCache() } } + /** + * 清理缓存 + * @param context 上下文 + */ override fun clearAllCache(context: Context) = runBlocking { GlobalScope.launch(Dispatchers.Main) { Glide.get(context).clearMemory() diff --git a/commonLib/src/main/java/com/common/commonlib/image/module/OkHttpLibraryGlideModule.kt b/commonLib/src/main/java/com/common/commonlib/image/module/OkHttpLibraryGlideModule.kt index f7fffd5..4b8ade9 100644 --- a/commonLib/src/main/java/com/common/commonlib/image/module/OkHttpLibraryGlideModule.kt +++ b/commonLib/src/main/java/com/common/commonlib/image/module/OkHttpLibraryGlideModule.kt @@ -11,6 +11,9 @@ import java.io.InputStream /** * okhttp配置 + * + * @author wangym + * @since 2021/7/28 */ @GlideModule class OkHttpLibraryGlideModule : LibraryGlideModule() { diff --git a/commonLib/src/main/java/com/common/commonlib/log/LogSecureHelper.kt b/commonLib/src/main/java/com/common/commonlib/log/LogSecureHelper.kt index 6556607..f186bf1 100644 --- a/commonLib/src/main/java/com/common/commonlib/log/LogSecureHelper.kt +++ b/commonLib/src/main/java/com/common/commonlib/log/LogSecureHelper.kt @@ -2,6 +2,9 @@ package com.common.commonlib.log /** * 日志敏感信息处理 + * + * @author wangym + * @since 2021/7/28 */ object LogSecureHelper { diff --git a/commonLib/src/main/java/com/common/commonlib/log/Logger.kt b/commonLib/src/main/java/com/common/commonlib/log/Logger.kt index 6d292d6..ad87293 100644 --- a/commonLib/src/main/java/com/common/commonlib/log/Logger.kt +++ b/commonLib/src/main/java/com/common/commonlib/log/Logger.kt @@ -2,6 +2,12 @@ package com.common.commonlib.log import android.util.Log +/** + * Log工具类 + * + * @author wangym + * @since 2021/7/28 + */ object Logger { var commonTag = "" var needSecurity = false diff --git a/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt b/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt index a951ca5..59bc5a2 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/BaseObserve.kt @@ -18,6 +18,9 @@ import javax.net.ssl.SSLHandshakeException /** * 请求基类 + * + * @author wangym + * @since 2021/7/28 */ open class BaseObserve { /** diff --git a/commonLib/src/main/java/com/common/commonlib/net/RequestCallBack.kt b/commonLib/src/main/java/com/common/commonlib/net/RequestCallBack.kt index 4f290af..dd8adc6 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/RequestCallBack.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/RequestCallBack.kt @@ -2,6 +2,9 @@ package com.common.commonlib.net /** * 请求回调 + * + * @author wangym + * @since 2021/7/28 */ interface RequestCallBack { fun onResult(result: T) diff --git a/commonLib/src/main/java/com/common/commonlib/net/RequestManager.kt b/commonLib/src/main/java/com/common/commonlib/net/RequestManager.kt index 84caadb..c248517 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/RequestManager.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/RequestManager.kt @@ -11,6 +11,9 @@ import java.util.concurrent.TimeUnit /** * 网络请求管理器 + * + * @author wangym + * @since 2021/7/28 */ object RequestManager { /** diff --git a/commonLib/src/main/java/com/common/commonlib/net/bean/BaseResponse.kt b/commonLib/src/main/java/com/common/commonlib/net/bean/BaseResponse.kt index 1c8394c..f7fa4c6 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/bean/BaseResponse.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/bean/BaseResponse.kt @@ -5,6 +5,9 @@ import kotlinx.android.parcel.Parcelize /** * 基础响应类 + * + * @author wangym + * @since 2021/7/28 */ @Parcelize open class BaseResponse : Parcelable { diff --git a/commonLib/src/main/java/com/common/commonlib/net/bean/RequestParam.kt b/commonLib/src/main/java/com/common/commonlib/net/bean/RequestParam.kt index f8e6845..e0a2884 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/bean/RequestParam.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/bean/RequestParam.kt @@ -2,6 +2,9 @@ package com.common.commonlib.net.bean /** * 请求参数 + * + * @author wangym + * @since 2021/7/28 */ data class RequestParam(var baseUrl: String) { var params: Map? = null diff --git a/commonLib/src/main/java/com/common/commonlib/net/interceptor/BaseUrlInterceptor.kt b/commonLib/src/main/java/com/common/commonlib/net/interceptor/BaseUrlInterceptor.kt index 2ba405c..01fc493 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/interceptor/BaseUrlInterceptor.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/interceptor/BaseUrlInterceptor.kt @@ -14,6 +14,9 @@ import java.util.* /** * HOST拦截器:动态替换HOST + * + * @author wangym + * @since 2021/7/28 */ class BaseUrlInterceptor : Interceptor { /** diff --git a/commonLib/src/main/java/com/common/commonlib/net/interceptor/RequestHeadInterceptor.kt b/commonLib/src/main/java/com/common/commonlib/net/interceptor/RequestHeadInterceptor.kt index 1a385a8..d609e73 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/interceptor/RequestHeadInterceptor.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/interceptor/RequestHeadInterceptor.kt @@ -6,6 +6,9 @@ import okhttp3.Response /** * 公共请求拦截器 + * + * @author wangym + * @since 2021/7/28 */ class RequestHeadInterceptor : Interceptor { /** diff --git a/commonLib/src/main/java/com/common/commonlib/net/interceptor/ResponseHeadInterceptor.kt b/commonLib/src/main/java/com/common/commonlib/net/interceptor/ResponseHeadInterceptor.kt index c25b917..7f8805b 100644 --- a/commonLib/src/main/java/com/common/commonlib/net/interceptor/ResponseHeadInterceptor.kt +++ b/commonLib/src/main/java/com/common/commonlib/net/interceptor/ResponseHeadInterceptor.kt @@ -1,11 +1,13 @@ package com.common.commonlib.net.interceptor -import android.util.Log import okhttp3.Interceptor import okhttp3.Response /** * 响应头部拦截器 + * + * @author wangym + * @since 2021/7/28 */ class ResponseHeadInterceptor(private var callBack: ResponseCallBack?) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { diff --git a/commonLib/src/main/java/com/common/commonlib/utils/FTPUtils.kt b/commonLib/src/main/java/com/common/commonlib/utils/FTPUtils.kt index 9e6126a..5f84163 100644 --- a/commonLib/src/main/java/com/common/commonlib/utils/FTPUtils.kt +++ b/commonLib/src/main/java/com/common/commonlib/utils/FTPUtils.kt @@ -10,6 +10,9 @@ import java.io.IOException /** * FTP工具类 + * + * @author wangym + * @since 2021/7/28 */ object FTPUtils { /** diff --git a/commonLib/src/main/java/com/common/commonlib/utils/SpManager.kt b/commonLib/src/main/java/com/common/commonlib/utils/SpManager.kt index e361cae..6e0075f 100644 --- a/commonLib/src/main/java/com/common/commonlib/utils/SpManager.kt +++ b/commonLib/src/main/java/com/common/commonlib/utils/SpManager.kt @@ -6,6 +6,9 @@ import android.content.SharedPreferences /** * sharedPreference管理类 + * + * @author wangym + * @since 2021/7/28 */ object SpManager { const val HAS_INIT = "has_init" diff --git a/commonLib/src/main/java/com/common/commonlib/view/SpaceItemDecoration.java b/commonLib/src/main/java/com/common/commonlib/view/SpaceItemDecoration.java index c7f4484..3fef5de 100644 --- a/commonLib/src/main/java/com/common/commonlib/view/SpaceItemDecoration.java +++ b/commonLib/src/main/java/com/common/commonlib/view/SpaceItemDecoration.java @@ -7,6 +7,12 @@ import androidx.recyclerview.widget.RecyclerView; import org.jetbrains.annotations.NotNull; +/** + * rv辅助类 + * + * @author wangym + * @since 2021/7/28 + */ public class SpaceItemDecoration extends RecyclerView.ItemDecoration { /** * 默认图片展示单行数量