1 Star 3 Fork 0

iouoi / Pbase

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

引用

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

MIT License Copyright (c) 2021 iouoi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

安卓项目开发自用基类 展开 收起
Android
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Android
1
https://gitee.com/iouoi/pbase.git
git@gitee.com:iouoi/pbase.git
iouoi
pbase
Pbase
master

搜索帮助