Skip to content

Commit

Permalink
升级 gradle 优化一些API
Browse files Browse the repository at this point in the history
  • Loading branch information
crimson0829 committed Mar 7, 2020
1 parent 933197e commit 3ecdb29
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 101 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.70'
repositories {

maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
Expand All @@ -14,7 +14,7 @@ buildscript {
}
dependencies {
apply from: "config.gradle"
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
6 changes: 3 additions & 3 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ext {
minSdkVersion : 16,
devSdkVersion : 21,
targetSdkVersion : 29,
versionCode : 1,
versionName : '1.0',
versionCode : 17,
versionName : '1.1.7',
applicationId : 'com.crimson.mvvm_frame'
]

Expand All @@ -32,7 +32,7 @@ ext {
lifecycleArchVersion : "2.2.0",

//design
googleMaterialVersion : "1.2.0-alpha04",
googleMaterialVersion : "1.2.0-alpha05",

//rxJava & network & db
rxjava2Version : "2.2.16",
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Dec 20 11:34:45 CST 2019
#Wed Mar 04 11:30:21 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
22 changes: 12 additions & 10 deletions library_mvvm/src/main/java/com/crimson/mvvm/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Observer
import com.crimson.mvvm.config.AppConfigOptions
import com.crimson.mvvm.ext.isNotNull
import com.crimson.mvvm.ext.isNull
import com.crimson.mvvm.ext.tryCatch
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity
import java.lang.reflect.ParameterizedType
Expand Down Expand Up @@ -50,12 +52,12 @@ abstract class BaseActivity<VB : ViewDataBinding, VM : BaseViewModel> : RxAppCom

vb = DataBindingUtil.setContentView(this, initContentView(savedInstanceState))
vm = initViewModel()
if (vm == null) {
if (vm.isNull) {
val type: Type? = javaClass.genericSuperclass
if (type is ParameterizedType && type.actualTypeArguments.size == 2) {
tryCatch {
vm = tryCatch {
val viewModel = type.actualTypeArguments[1] as? Class<VM>
vm = viewModel?.newInstance()
viewModel?.newInstance()
}
}
}
Expand Down Expand Up @@ -90,7 +92,7 @@ abstract class BaseActivity<VB : ViewDataBinding, VM : BaseViewModel> : RxAppCom
})

vm?.onLoadingViewResultLD?.observe(this, Observer {
onLoadingViewResult(it?:false)
onLoadingViewResult(it ?: false)
})

vm?.dataLoadingLD?.observe(this, Observer {
Expand Down Expand Up @@ -156,15 +158,15 @@ abstract class BaseActivity<VB : ViewDataBinding, VM : BaseViewModel> : RxAppCom
* 如果想定制化单个页面的LoadingView,可重写该方法实现
*/
open fun checkLoadingViewImpl() {
if (loadingView == null) {
if (loadingView.isNull) {
val clazz = AppConfigOptions.LOADING_VIEW_CLAZZ
if (clazz != null) {
tryCatch {
val constructor = clazz.getConstructor(Context::class.java)
loadingView = constructor.newInstance(this)
if (clazz.isNotNull) {
loadingView = tryCatch {
val constructor = clazz?.getConstructor(Context::class.java)
constructor?.newInstance(this)
}
}
if (loadingView == null) {
if (loadingView.isNull) {
loadingView = CommonViewLoading(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import androidx.fragment.app.FragmentActivity
import com.crimson.mvvm.R
import com.crimson.mvvm.config.AppConfigOptions
import com.crimson.mvvm.config.ViewLifeCycleManager
import com.crimson.mvvm.coroutines.ioCoroutineGlobal
import com.crimson.mvvm.ext.Api
import com.crimson.mvvm.ext.afterApi
import com.crimson.mvvm.ext.runOnIO
import com.crimson.mvvm.rx.bus.RxBus
import com.crimson.mvvm.rx.bus.RxCode
import com.crimson.mvvm.utils.StatusBarUtils
Expand Down Expand Up @@ -50,7 +50,6 @@ open class BaseActivityLifecycle : ActivityLifecycleCallbacks {
initDefaultView(activity)



}

override fun onActivityStarted(activity: Activity) {
Expand All @@ -65,7 +64,7 @@ open class BaseActivityLifecycle : ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity) {
if (isBackground) {
isBackground = false
RxBus.get().post(RxCode.APP_ISBACKGROUND,isBackground)
RxBus.get().post(RxCode.APP_ISBACKGROUND, isBackground)
}
}

Expand All @@ -78,7 +77,7 @@ open class BaseActivityLifecycle : ActivityLifecycleCallbacks {
--foregroundCount
if (foregroundCount <= 0) {
isBackground = true
RxBus.get().post(RxCode.APP_ISBACKGROUND,isBackground)
RxBus.get().post(RxCode.APP_ISBACKGROUND, isBackground)
}

}
Expand All @@ -98,30 +97,26 @@ open class BaseActivityLifecycle : ActivityLifecycleCallbacks {
* 将activity添加到全局管理器
*/
private fun addActivityToManager(activity: Activity) {
runOnIO {
//添加activity入栈
ViewLifeCycleManager.addActivityToStack(activity)
if (activity is FragmentActivity) {
//注册fragment生命周期
activity.supportFragmentManager.registerFragmentLifecycleCallbacks(
fragmentLifeCycle,
true
)
}
//添加activity入栈
ViewLifeCycleManager.addActivityToStack(activity)
if (activity is FragmentActivity) {
//注册fragment生命周期
activity.supportFragmentManager.registerFragmentLifecycleCallbacks(
fragmentLifeCycle,
true
)
}
}

/**
* 将activity在全局管理器中移除
*/
private fun removeActivityFromManager(activity: Activity) {
runOnIO {
ViewLifeCycleManager.removeActivityFromStack(activity)
if (activity is FragmentActivity) {
activity.supportFragmentManager.unregisterFragmentLifecycleCallbacks(
fragmentLifeCycle
)
}
ViewLifeCycleManager.removeActivityFromStack(activity)
if (activity is FragmentActivity) {
activity.supportFragmentManager.unregisterFragmentLifecycleCallbacks(
fragmentLifeCycle
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.crimson.mvvm.base

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.crimson.mvvm.module.ModuleConfig
import com.crimson.mvvm.module.appModule
import com.crimson.mvvm.rx.bus.RxBus
import com.crimson.mvvm.rx.bus.RxCode
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
Expand Down Expand Up @@ -50,12 +53,14 @@ open class BaseApplication : Application() {

//组件初始化
ModuleConfig.initModule(this)

}


/**
* 默认实现 BaseActivityLifecycle
* 默认实现 BaseActivityLifecycle,如果重写,这里的实现最好继承BaseActivityLifecycle
*/
open fun initActivityLifecycle(): ActivityLifecycleCallbacks?{
open fun initActivityLifecycle(): ActivityLifecycleCallbacks? {
return BaseActivityLifecycle()
}

Expand Down
23 changes: 14 additions & 9 deletions library_mvvm/src/main/java/com/crimson/mvvm/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Observer
import com.crimson.mvvm.config.AppConfigOptions
import com.crimson.mvvm.ext.isNotNull
import com.crimson.mvvm.ext.isNull
import com.crimson.mvvm.ext.tryCatch
import com.trello.rxlifecycle3.components.support.RxFragment
import java.lang.reflect.ParameterizedType
Expand Down Expand Up @@ -64,16 +66,19 @@ abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel> : RxFragme
* 是否可见状态 为了避免和[Fragment.isVisible]冲突 换个名字
*/
private var isFragmentVisible = false

/**
* 标志位,View已经初始化完成。
* 用isAdded()属性代替
* isPrepared还是准一些,isAdded有可能出现onCreateView没走完但是isAdded了
*/
private var isPrepared = false

/**
* 是否第一次加载
*/
private var isFirstLoad = true

/**
* <pre>
* 忽略isFirstLoad的值,强制刷新数据,但仍要Visible & Prepared
Expand Down Expand Up @@ -133,12 +138,12 @@ abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel> : RxFragme
)

vm = initViewModel()
if (vm == null) {
if (vm.isNull) {
val type: Type? = javaClass.genericSuperclass
if (type is ParameterizedType && type.actualTypeArguments.size == 2) {
tryCatch {
vm = tryCatch {
val viewModel = type.actualTypeArguments[1] as? Class<VM>
vm = viewModel?.newInstance()
viewModel?.newInstance()
}

}
Expand Down Expand Up @@ -237,15 +242,15 @@ abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel> : RxFragme
* 如果想定制化单个页面的LoadingView,可重写该方法实现
*/
open fun checkLoadingViewImpl() {
if (loadingView == null) {
if (loadingView.isNull) {
val clazz = AppConfigOptions.LOADING_VIEW_CLAZZ
if (clazz != null) {
tryCatch {
val constructor = clazz.getConstructor(Context::class.java)
loadingView = constructor.newInstance(context)
if (clazz.isNotNull) {
loadingView = tryCatch {
val constructor = clazz?.getConstructor(Context::class.java)
constructor?.newInstance(context)
}
}
if (loadingView == null) {
if (loadingView.isNull) {
context?.let {
loadingView = CommonViewLoading(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.crimson.mvvm.config.ViewLifeCycleManager
import com.crimson.mvvm.ext.runOnIO
import com.crimson.mvvm.coroutines.ioCoroutineGlobal

/**
* @author crimson
Expand All @@ -15,18 +15,16 @@ open class BaseFragmentLifeCycle : FragmentManager.FragmentLifecycleCallbacks()

override fun onFragmentCreated(fm: FragmentManager, f: Fragment, savedInstanceState: Bundle?) {
super.onFragmentCreated(fm, f, savedInstanceState)
runOnIO {
ViewLifeCycleManager.addFragmentToStack(f)
}
ViewLifeCycleManager.addFragmentToStack(f)


}


override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) {
super.onFragmentDestroyed(fm, f)
runOnIO {
ViewLifeCycleManager.removeFragmentFromStack(f)
}
ViewLifeCycleManager.removeFragmentFromStack(f)


}

Expand Down
2 changes: 2 additions & 0 deletions library_mvvm/src/main/java/com/crimson/mvvm/base/BaseModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.koin.core.inject
* @author crimson
* @date 2019-12-21
* base model
* model中用于获取remoteData和localData,并处理数据后交给viewModel
*
*/
open class BaseModel : IModel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.crimson.widget.loading.LoadingLayout
* @author crimson
* @date 2019-12-29
* 默认 view loading impl
*
*/
class CommonViewLoading(context: Context) : IViewDataLoading {

Expand Down Expand Up @@ -44,7 +45,7 @@ class CommonViewLoading(context: Context) : IViewDataLoading {
if (view.contains(emptyView)) {
view.removeView(emptyView)
}
if (view.contains(loadingView)){
if (view.contains(loadingView)) {
view.removeView(loadingView)
}
view.addView(loadingView)
Expand All @@ -54,7 +55,7 @@ class CommonViewLoading(context: Context) : IViewDataLoading {

override fun onLoadingViewResult(view: View?, needEmptyView: Boolean) {
if (view is ViewGroup) {
if (view.contains(loadingView)){
if (view.contains(loadingView)) {
view.removeView(loadingView)
}

Expand Down Expand Up @@ -86,7 +87,7 @@ class CommonViewLoading(context: Context) : IViewDataLoading {
view.removeView(loadingView)
}
//添加error view
if (view.contains(loadingError)){
if (view.contains(loadingError)) {
view.removeView(loadingError)
}
view.addView(loadingError)
Expand Down
2 changes: 1 addition & 1 deletion library_mvvm/src/main/java/com/crimson/mvvm/base/IModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import org.koin.core.KoinComponent
/**
* @author crimson
* @date 2019-12-21
* model impl interface
* model interface
*/
interface IModel : KoinComponent
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.crimson.mvvm.base
/**
* @author crimson
* @date 2020-01-14
* statusBar init interrface
* statusBar init interface
*/
interface IStatusBar {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ITitleBar {
/**
* 初始化titleBar, 如果是true就消费,以下的方法都会失效;默认false默认设置在BaseActivityLifecycle中实现
*/
fun initTitleBar():Boolean
fun initTitleBar(): Boolean

/**
* 初始化返回按钮图标
Expand Down
3 changes: 2 additions & 1 deletion library_mvvm/src/main/java/com/crimson/mvvm/base/IView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import org.koin.core.KoinComponent
/**
* @author crimson
* @date 2019-12-21
* view impl interface
* view interface
* BaseActivity 和 BaseFragment 默认实现该接口,在 BaseActivityLifecycle 做方法回调
*/
interface IView : KoinComponent {

Expand Down
Loading

0 comments on commit 3ecdb29

Please sign in to comment.