feat: 调整View抽象层
This commit is contained in:
@@ -18,7 +18,7 @@ import java.lang.reflect.ParameterizedType
|
||||
* @Remark: Activity基类 与项目无关
|
||||
*/
|
||||
abstract class BaseFrameActivity<VB : ViewBinding, VM : ViewModel> :
|
||||
AppCompatActivity(), FrameView {
|
||||
AppCompatActivity(), FrameView<VB> {
|
||||
|
||||
protected val mBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
val vbClass: Class<VB> =
|
||||
@@ -40,8 +40,9 @@ abstract class BaseFrameActivity<VB : ViewBinding, VM : ViewModel> :
|
||||
ARouter.getInstance().inject(this)
|
||||
// 注册EventBus
|
||||
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
|
||||
initView()
|
||||
initViewObserve()
|
||||
mBinding.initView()
|
||||
initLiveDataObserve()
|
||||
initRequestData()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType
|
||||
* @Class: BaseFrameFragment
|
||||
* @Remark: Fragment基类 与项目无关
|
||||
*/
|
||||
abstract class BaseFrameFragment<VB : ViewBinding, VM : ViewModel> : Fragment(), FrameView {
|
||||
abstract class BaseFrameFragment<VB : ViewBinding, VM : ViewModel> : Fragment(), FrameView<VB> {
|
||||
|
||||
protected val mBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
val vbClass: Class<VB> =
|
||||
@@ -47,8 +47,9 @@ abstract class BaseFrameFragment<VB : ViewBinding, VM : ViewModel> : Fragment(),
|
||||
ARouter.getInstance().inject(this)
|
||||
// 注册EventBus
|
||||
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
|
||||
initView()
|
||||
initViewObserve()
|
||||
mBinding.initView()
|
||||
initLiveDataObserve()
|
||||
initRequestData()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -15,7 +15,8 @@ import java.lang.reflect.ParameterizedType
|
||||
* @Class: BaseFrameNotMVVMActivity
|
||||
* @Remark: 不使用 MVVM 的 Activity 基类
|
||||
*/
|
||||
abstract class BaseFrameNotMVVMActivity<VB : ViewBinding> : AppCompatActivity(), FrameNotMVVMView {
|
||||
abstract class BaseFrameNotMVVMActivity<VB : ViewBinding> : AppCompatActivity(),
|
||||
FrameNotMVVMView<VB> {
|
||||
|
||||
protected val mBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
val vbClass: Class<VB> =
|
||||
@@ -31,7 +32,7 @@ abstract class BaseFrameNotMVVMActivity<VB : ViewBinding> : AppCompatActivity(),
|
||||
ARouter.getInstance().inject(this)
|
||||
// 注册EventBus
|
||||
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
|
||||
initView()
|
||||
mBinding.initView()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.lang.reflect.ParameterizedType
|
||||
* @Class: BaseFrameNotMVVMFragment
|
||||
* @Remark: 不使用 MVVM 的 Fragment 基类
|
||||
*/
|
||||
abstract class BaseFrameNotMVVMFragment<VB : ViewBinding> : Fragment(), FrameNotMVVMView {
|
||||
abstract class BaseFrameNotMVVMFragment<VB : ViewBinding> : Fragment(), FrameNotMVVMView<VB> {
|
||||
|
||||
protected val mBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
|
||||
val vbClass: Class<VB> =
|
||||
@@ -40,7 +40,7 @@ abstract class BaseFrameNotMVVMFragment<VB : ViewBinding> : Fragment(), FrameNot
|
||||
ARouter.getInstance().inject(this)
|
||||
// 注册EventBus
|
||||
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
|
||||
initView()
|
||||
mBinding.initView()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.quyunshuo.base.mvvm.v
|
||||
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/10/13
|
||||
* @Class: FrameNotMVVMView
|
||||
* @Remark: View层基类抽象
|
||||
*/
|
||||
interface FrameNotMVVMView {
|
||||
interface FrameNotMVVMView<VB : ViewBinding> {
|
||||
/**
|
||||
* 初始化View
|
||||
*/
|
||||
fun initView()
|
||||
fun VB.initView()
|
||||
}
|
||||
@@ -1,19 +1,26 @@
|
||||
package com.quyunshuo.base.mvvm.v
|
||||
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
/**
|
||||
* @Author: QuYunShuo
|
||||
* @Time: 2020/10/13
|
||||
* @Class: FrameView
|
||||
* @Remark: View层基类抽象
|
||||
*/
|
||||
interface FrameView {
|
||||
interface FrameView<VB : ViewBinding> {
|
||||
/**
|
||||
* 初始化View
|
||||
*/
|
||||
fun initView()
|
||||
fun VB.initView()
|
||||
|
||||
/**
|
||||
* 订阅LiveData
|
||||
* 初始化LiveData的订阅关系
|
||||
*/
|
||||
fun initViewObserve()
|
||||
fun initLiveDataObserve()
|
||||
|
||||
/**
|
||||
* 初始化界面创建时的数据请求
|
||||
*/
|
||||
fun initRequestData()
|
||||
}
|
||||
Reference in New Issue
Block a user