代码拉取完成,页面将自动刷新
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.gitee.iouoi:pbase:latestVersion'
}
-keep class com.pbase.data.** { *; }
1. 整体架构参考 https://github.com/KunMinX/Jetpack-MVVM-Scaffold
2. 主要包含 表现层(ui)、领域层(domain)、数据层(DataRepository )三层,业务逻辑在domain层处理,
界面/控件通过绑定的LiveData驱动更新
3. 每个界面都包含一个state-ViewModel:
1. 托管 DataBinding 绑定的临时状态,以及视图控制器重建时状态的恢复。
2. state-ViewModel 的职责仅限于 状态托管,不建议在此处理 UI 逻辑
3. state-ViewModel中主要包含 ObservableField、LiveData、Request 以及它们的初始化操作,除此之外不包含任何逻辑。
4. 即:state-ViewModel中的livedata在xml中与控件完成绑定,要改变控件状态,只能通过改变对应的livedata完成
(见baseActivity/basefragment 的onCreate)
5. 参考 https://xiaozhuanlan.com/topic/9816742350
4. 通过shared-ViewModel 进行跨界面通讯
1. shared-ViewModel 的职责仅限于在 "跨页面通信" 的场景下,承担 "唯一可信源"
2. 所有跨页面的 "状态同步请求" 都交由该可信源在内部决策和处理,并统一分发给所有订阅者页面。
3. 内部LivData 统一使用UnPeekLiveData解决 "数据倒灌" 的问题。
4. 参考 https://xiaozhuanlan.com/topic/6719328450
5. 领域层由两类UseCase组成
1.普通UseCase
1. Request 通常按业务划分一个项目中通常存在多个 Request 类,
2. 每个页面配备的 state-ViewModel 实例可根据业务需要持有多个不同的 Request 实例。
3. 因为普通UseCase是被state-ViewModel持有,所以当界面重建后普通UseCase 实例及其缓存也一并得以保留
4. 参考 https://xiaozhuanlan.com/topic/8204519736
2.绑定界面生命周期的UseCase
1. UseCase负责管理需根据页面生命周期来叫停数据层业务
2. UseCase由Request持有,界面通过state-ViewModel获取对应的UseCase进行生命周期绑定
6. state-ViewModel 与 shared-ViewModel 仅通过命名区分,与BaseActivity中的ViewModel作用域不同
7.数据交互过程
1. ui控件绑定state-ViewModel中的LiveData/ObservableField
- ObservableField只有在数据发生改变时UI才会收到通知,而LiveData不同,
只要你postValue或者setValue,UI都会收到通知,不管数据有无变化
LiveData能感知Activity的生命周期,在Activity不活动的时候不会触发
2. 界面观察Request中的LiveData,修改对应ui控件绑定state-ViewModel中的LiveData来通知ui刷新
3. Request调用数据层的业务逻辑更新本身持有的LiveData
1. 此时所有观察此livedata的界面都会获得通知(生命周期非活跃状态的界面将在界面获得焦点后收到通知)
2. 若业务逻辑涉及生命周期则通过UseCase调用数据层的业务逻辑
1. Jetpack组件
>https://developer.android.google.cn/jetpack/androidx/explorer?case=popular
2. 权限控制
> implementation "com.github.getActivity:XXPermissions:leakcanary_version"
https://github.com/getActivity/XXPermissions
3. UnPeekLiveData 发送一次性事件
> implementation "com.kunminx.archi:unpeek-livedata:$unpeek_livedata_version"
https://github.com/KunMinX/UnPeek-LiveData
4. 界面适配框架
> api "com.github.JessYanCoding:AndroidAutoSize:$autosize_version"
https://github.com/JessYanCoding/AndroidAutoSize
5. rxJava/rxAndroid
> implementation "io.reactivex.rxjava3:rxjava:$rxjava_verson"
https://github.com/ReactiveX/RxJava
implementation "io.reactivex.rxjava3:rxandroid:$rxAndroid_verson"
https://github.com/ReactiveX/RxAndroid
6.okHttp
> implementation "com.squareup.okhttp3:okhttp:$okHttp_verson"
https://github.com/square/okhttp
7. retrofit2
> implementation "com.squareup.retrofit2:retrofit:$retrofit2_verson"
implementation "com.squareup.retrofit2:converter-gson:$retrofit2_verson"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2_verson"
https://square.github.io/retrofit/
8. gson
> implementation "com.google.code.gson:gson:$gson_verson"
https://github.com/google/gson
9. glide图片加载
> implementation "com.github.bumptech.glide:glide:$glide_verson"
implementation "com.github.bumptech.glide:compiler:$glide_verson"
混淆配置 -keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule
10. 土司组件,可解决华为等机型进制通知栏权限后土司无法弹出
> implementation "com.github.getActivity:ToastUtils:$toastutil_verson"
https://github.com/getActivity/ToastUtils
implementation "com.github.getActivity:XToast:$toastutil_verson"
https://github.com/getActivity/XToast
11. 标题栏组件
> implementation "com.github.getActivity:TitleBar:$titlebar_verson"
https://github.com/getActivity/TitleBar
混淆规则 -keep class com.hjq.bar.** {*;}
12. utils:常用工具类
> implementation "com.blankj:utilcodex:$utilcode_verson"
https://github.com/Blankj/AndroidUtilCode
13. dialog组件(base1中使用,base2后切换xpopup库)
> implementation "com.github.kongzue.DialogX:DialogX:$dialogx_version"
https://github.com/kongzue/DialogX
混淆规则 -keep class com.kongzue.dialogx.** { *; }
-dontwarn com.kongzue.dialogx.**
# 额外的,建议将 android.view 也列入 keep 范围:
-keep class android.view.** { *; }
# 若启用模糊效果,请增加如下配置:
-dontwarn androidx.renderscript.**
-keep public class androidx.renderscript.** { *; }
14. 下拉刷新,下拉加载组件
> implementation "io.github.scwang90:refresh-layout-kernel:$smartRefresh_version" //核心必须依赖
implementation "io.github.scwang90:refresh-header-classics:$smartRefresh_version" //经典刷新头
implementation "io.github.scwang90:refresh-footer-classics:$smartRefresh_version" //经典加载
https://github.com/scwang90/SmartRefreshLayout
15. 图片视频选择框架
> implementation "io.github.lucksiege:pictureselector:$pictureselector_version"
https://github.com/LuckSiege/PictureSelector/blob/master/README_CN.md
#PictureSelector 2.0
混淆规则 -keep class com.luck.picture.lib.** { *; }
#Ucrop
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
16. 选择器类库(仅导入基础选择器)
> implementation "com.github.gzu-liyujiang.AndroidPicker:Common:androidPicker_Version"//基础窗体
implementation "com.github.gzu-liyujiang.AndroidPicker:WheelView:androidPicker_Version"//仿ios滚轮选择器的滚轮控件
implementation "com.github.gzu-liyujiang.AndroidPicker:WheelPicker:$androidPicker_Version"//单项/数字、二三级联动、日期/时间等滚轮选择器:
https://github.com/gzu-liyujiang/AndroidPicker
17. 二维码
> implementation "com.github.bingoogolapple.BGAQRCode-Android:zxing:bgaqrCode_Version"
https://github.com/bingoogolapple/BGAQRCode-Android
18. 弹框组件,并可取代DrawerLayout侧边弹框功能和图片放大功能
> implementation "com.github.li-xiaojun:XPopup:xpopup_version"
https://github.com/li-xiaojun/XPopup
混淆
-dontwarn com.lxj.xpopup.widget.**
-keep class com.lxj.xpopup.widget.**{*;}
1. ui(界面基类):
1. page: activity/fragment
- BaseActivity/BaseFragment 参考 https://github.com/KunMinX/Strict-DataBinding
2. adapter: viewpager/recyclerView
3. view : 自定义控件
4. state : 存放state-ViewModel
5. shared : 存放shared-ViewModel
2. domain(领域层基类):
1. request(对数据请求的转发,ui与data的中间件):
2. usecase(协助request,专职负责生命周期相关):
3. data(数据层基类,业务流程):
1. response (结果返回):
1. DataResult.class : 专用于数据层返回结果给 domain 层或 ViewModel
2. BaseResponseStatus.class : 响应状态元信息基类
2. bean(实体类):
3. config(各种常量配置):
4. networkmanage(网络状态监控):
- 在application中初始化注册广播,存在与程序整个生命周期
5. http(网络请求)
- 参考 https://github.com/goldze/MVVMHabit
4. tools(自定义工具类)
1. nodrawable 使用bindingAdapter完成drawbale 文件的工工作
@{}中所有的数值支持 整型 和 浮点型,在内部统一处理为了dp单位
见 https://github.com/whataa/noDrawable
2. CommonBindingAdapter 自定义通用BindingAdapter存放 特有的接口应放置于对应的module
3. CountDownTime倒计时工具
4. Logger 日志打印类
5. JsonParser json解析
1. 公用title 使用<include/>标签引入,参考https://github.com/goldze/MVVMHabit 中 FormFragment 界面实现
psn 2021
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。