Modify: 基类调整

This commit is contained in:
Quyunshuo
2020-08-31 15:23:31 +08:00
parent 48f543c919
commit 13b359ce8c
5 changed files with 13 additions and 5 deletions

View File

@ -26,6 +26,7 @@ abstract class BaseFrameActivity<VB : ViewBinding, VM : ViewModel>(private val v
protected abstract fun initViewBinding(): VB
protected abstract fun initView()
protected abstract fun initViewObserve()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -35,6 +36,7 @@ abstract class BaseFrameActivity<VB : ViewBinding, VM : ViewModel>(private val v
// 注册EventBus
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
initView()
initViewObserve()
}
override fun onDestroy() {

View File

@ -28,8 +28,8 @@ abstract class BaseFrameFragment<VB : ViewBinding, VM : ViewModel>(private val v
protected val mBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) { initViewBinding() }
protected abstract fun initViewBinding(): VB
protected abstract fun initView()
protected abstract fun initViewObserve()
override fun onCreateView(
inflater: LayoutInflater,
@ -46,6 +46,7 @@ abstract class BaseFrameFragment<VB : ViewBinding, VM : ViewModel>(private val v
// 注册EventBus
if (javaClass.isAnnotationPresent(EventBusRegister::class.java)) EventBusUtils.register(this)
initView()
initViewObserve()
}
override fun onDestroy() {

View File

@ -1,5 +1,6 @@
package com.quyunshuo.base.mvvm.vm
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.quyunshuo.base.mvvm.m.BaseRepository
@ -11,6 +12,9 @@ import com.quyunshuo.base.mvvm.m.BaseRepository
*/
abstract class BaseViewModel<R : BaseRepository> : ViewModel() {
// Loading 状态
val isLoading = MutableLiveData(false)
protected val mRepository: R by lazy { initRepository() }
protected abstract fun initRepository(): R

View File

@ -17,8 +17,6 @@ import java.util.concurrent.TimeUnit
*/
object NetServiceCreator {
private const val BASE_URL = ""
private const val CONNECT_TIME_OUT = 15L
private const val READ_TIME_OUT = 20L
@ -43,7 +41,7 @@ object NetServiceCreator {
private val retrofit by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
Retrofit.Builder()
.baseUrl(BASE_URL)
.baseUrl("")
.addConverterFactory(GsonConverterFactory.create()) // Gson转换器
.client(okHttpClient)
.build()

View File

@ -45,6 +45,9 @@
* 3.填写自己的 Bugly key 在 BaseApplication initialize() 方法中
* 这样就可以使用了,当然可以删除不用的第三方,或者添加相应要使用的第三方,具体规范看下面的框架解读
## Demo
* 项目里有一个demo分支,这是我写的一个小例子,可以结合Demo去熟悉这个框架
## 框架解读
**组件化相关**