javadoc文档生成方式
- 生成目录:根目录/dokka/..
- 使用命令
#全部
./gradlew dokkaHtml
#单个
./gradlew :base:dokkaHtml
./gradlew :library:http-cache:dokkaHtml
A、初始化配置
规范:
1.初始化代码放到application工程下;
2.不要直接放到Application子类下去初始化;
3.规范使用参考yhdos项目下YHBaseUIConfig类;
一、base
YHBaseConfigProxy.init(object : IYHBaseConfig {
override fun isAppDebugModel(): Boolean {
return YHBaseUIConfig.isAppDebugModel()
}
override fun isRequestErrorDirectlyShowMessage(): Boolean {
return YHBaseUIConfig.isRequestErrorDirectlyShowMessage()
}
})
二、http-cache
CacheManager.setHttpCacheConfigInterceptor(object : IHttpCacheConfigInterceptor {
override fun isOpenMock(): Boolean {
return false
}
override fun isSuccessResponseCode(code: Int, request: Request): Boolean {
return (request != null // && request.url().toString().startsWith(UrlUtil.getUrl())
&& code == 200000)
}
override fun isSuccessResponse(response: String, request: Request): Boolean {
return !TextUtils.isEmpty(response) && response.startsWith("{\"code\":200000")
}
})
三、http-core
Https.addInterceptor(AppParamInterceptor())
Https.init(object : IHttpInitConfigInterceptor {
override fun isPrintLog(status: Int): Boolean = isHttpPrintLogDebugModel(status)
override fun configOkHttpClientBuilder(
builder: OkHttpClient.Builder,
url: String,
useCache: Boolean
) {
}
override fun configRetrofitBuilder(
builder: Retrofit.Builder,
url: String,
useCache: Boolean
) {
}
})
四、lib-imageLoader
无
五、lib-log
LogConfig.setIsDebug(UtilsConfig.isAllDebugModel() || BuildConfig.DEBUG)
LogUtils.initLogConfig()
六、lib-utils
UtilsConfig.setContext(context)
//如果使用
MMKV.initialize(context)
七、lib-widget
无
八、RecyclerView-Adapter
无
九、lib-baiduMap
十、lib-pay
十一、lib-photoview
十二、lib-picture
B、使用
一、base
-
IDelegateUI
关注方法功能,实现类BaseActivity、BaseFragment、BaseDialogFragment,约束应用层代码规范,方便阅读和维护; -
BaseViewModel
数据提供,封装了网络请求;
open class BaseViewModel : ViewModel() {
//需要关注这些常量的作用,他们可以进行逻辑运算组合(| or &)
companion object {
//默认
const val FLAG_DEFAULT: Int = 0x1 shl 31
//返回不用弹toast(如果不设置,请求出错会有默认toast)
const val FLAG_NO_TOAST: Int = 0x1
//请求发起loading动画
const val FLAG_LOADING: Int = 0x1 shl 1
//请求出错页面显示异常页面
const val FLAG_ERROR_LAYER: Int = 0x1 shl 2
}
}
-
IRsp
接口,适配服务器不同数据结构,方便应用层统一处理数据; -
YHRequest
BaseViewModel里内部类,封城了网络请求,所有请求通过该类来构造; -
ErrorLayer
接口,用于覆盖错误页面等其他情况页面;
二、http-cache
1.CachedInterceptor
核心类
OkHttpClient.Builder.addInterceptor(CachedInterceptor(useCache));
三、http-core
1.Https
核心类
Https.service(UrlUtil.getUrl(), SearchApi::class.java)
四、lib-imageLoader
1.YHImageRequestBuilder
核心类
YHImageLoader.with(context)
.load(url ?: "")
.placeholder(placeholderId)
.error(errorId)
.into(target)
五、lib-log
LogUtils.i("--> 请求Start:");
六、lib-utils
无
七、lib-widget
无
八、RecyclerView-Adapter
1.ItemViewDelegate
class SearchEditViewDelegate :
com.yh.base.recyclerview.adapter.ItemViewDelegate<SearchHistoryEntity, SearchItemEditBinding, Boolean> {
override fun isForViewType(bean: Any?, position: Int): Boolean = bean is SearchHistoryEntity
override fun getViewBinding(inflater: LayoutInflater, parent: ViewGroup?): SearchItemEditBinding = SearchItemEditBinding.inflate(inflater, parent, false)
override fun convert(mViewBinding: SearchItemEditBinding, bean: SearchHistoryEntity?, position: Int, flag: Boolean?) {
com.yh.base.lib.log.LogUtils.i("CategoryFirstViewDelegate convert position:$position")
mViewBinding.root.setTag(R.id.tag_position, position)
mViewBinding.root.setTag(R.id.tag_bean, bean)
if (bean == null) {
return
}
with(mViewBinding) {
tvName.text = bean.name
tvName.setBackgroundResource(R.drawable.shape_bg_tag_no)
tvName.setTextColor(ContextCompat.getColor(root.context, R.color.textColor_grey_normal))
}
}
}
2.SingleTypeAdapter
和 MultiItemTypeAdapter
class SearchGoodsAdapter(var context: Context, var isShowEnterShop: Boolean, var isLinear: Boolean) : com.yh.base.recyclerview.adapter.MultiItemTypeAdapter(context) {
init {
addItemViewDelegate(SearchGoodsLinearViewDelegate(isShowEnterShop, isLinear, true))
addItemViewDelegate(SearchGoodsGridViewDelegate(!isLinear, true))
addItemViewDelegate(SearchShopViewDelegate())
}
override fun isDefaultListener(): Boolean = false
}
九、lib-baiduMap
十、lib-pay
十一、lib-photoview
十二、lib-picture