一个封装了状态加载、屏幕适配和日志查看的Android MVC&MVP开发框架。👉项目地址👈
集成
- 在项目根目录下的
build.gradle
文件中加入:
1 2 3 4 5
| allprojects { repositories { maven { url 'https://jitpack.io' } } }
|
- 在项目app模块下的
build.gradle
文件中加入:
1 2 3 4 5 6 7 8 9
| android { viewBinding { enabled = true } }
dependencies { implementation 'com.github.EIong:BaseApp:2.0.0' }
|
使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| LogUtils.getConfig() .setSaveDays(3) .isLog2FileSwitch = true
BaseManager .setOpenAdaptScreen(true) .setAdaptScreenDirection(BaseManager.Direction.WIDTH) .setAdaptScreenValue(1080) .setLoadingAdapter(BaseLoadingAdapter()) .setLogEncryption("1111111111111111")
|
- MVC Activity继承
BaseActivity
,传入相应ViewBinding:
1
| class MvcActivity : BaseActivity<ActivityMvcBinding>()
|
- MVC Fragment继承
BaseFragment
,传入相应ViewBinding:
1
| class MvcFragment : BaseFragment<FragmentMvcBinding>()
|
1 2 3 4
| interface MvpContract { interface MvpPresenter : BaseContract.BasePresenter interface MvpView : BaseContract.BaseView }
|
- MVP Presenter继承
BasePresenter
,传入相应View,实现契约类中Presenter接口:
1
| class MvpPresenter : BasePresenter<MvpContract.MvpView>(), MvpContract.MvpPresenter
|
- MVP Activity继承
BaseActivity
,传入相应ViewBinding和Presenter,实现契约类中View接口:
1
| class MvpActivity : BaseActivity<ActivityMvpBinding, MvpPresenter>(), MvpContract.MvpView
|
- MVP Fragment继承
BaseFragment
,传入相应ViewBinding和Presenter,实现契约类中View接口:
1
| class MvpFragment : BaseFragment<FragmentMvpBinding, MvpPresenter>(), MvpContract.MvpView
|
在Activity和Fragment中通过vb
拿到ViewBinding对象,p
拿到Presenter对象,在Presenter中通过v
拿到View对象。
1
| override fun initialize(savedInstanceState: Bundle?)
|
- 请求权限:
- permissionsTip:请求权限提示
- cancel:取消按钮文本
- confirm:确定按钮文本
- onCancel:点击取消回调
- onGrantedAll:获取所有权限回调
1 2 3 4 5 6 7 8 9 10
| requestPermissions( permissionsTip, cancel, confirm, onCancel, onGrantedAll, permission1, permission2, ... )
|
- 覆写此方法自定义消息弹窗:
- message:消息内容
- cancel:取消按钮文本
- confirm:确定按钮文本
- onCancel:点击取消回调
- onConfirm:点击确定回调
1 2 3 4 5 6 7 8
| override fun showBaseDialog( activity: Activity, message: String, cancel: String, confirm: String, onCancel: () -> Unit, onConfirm: () -> Unit )
|
1
| showLoadingOverView(view)
|
1
| showSuccessOverView(view)
|
1
| showFailedOverView(view, retry)
|
1
| showEmptyOverView(view, retry)
|
1
| addClick(view1, view2, ...)
|
1
| override fun onClick(v: View)
|
1
| showViews(view1, view2, ...)
|
1
| hideViews(view1, view2, ...)
|
1
| goneViews(view1, view2, ...)
|
1
| BaseManager.goToLog(activity, password)
|
说明
框架中引入了Gloading(超轻量级,深度解耦Android App中全局加载中、加载失败及无数据视图),主要用于状态加载显示,引入了AndroidUtilCode(一个强大易用的安卓工具类库,它合理地封装了安卓开发中常用的函数,具有完善的Demo和单元测试,利用其封装好的APIs可以大大提高开发效率),主要用于屏幕适配和权限请求等,如需使用以上框架,无需重复引入,Respect~。