Skip to content

Commit b7299c5

Browse files
committed
Merge branch 'v_1.6'
2 parents 1a081a5 + ea7e5bd commit b7299c5

24 files changed

+387
-578
lines changed

app/build.gradle

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "com.fmt.github"
1313
minSdkVersion 15
1414
targetSdkVersion 28
15-
versionCode 5
16-
versionName "1.5"
15+
versionCode 6
16+
versionName "1.6"
1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
1919
signingConfigs {
@@ -44,47 +44,31 @@ dependencies {
4444
implementation fileTree(dir: 'libs', include: ['*.jar'])
4545
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4646
//Androidx
47-
implementation 'androidx.appcompat:appcompat:1.0.2'
47+
implementation 'androidx.appcompat:appcompat:1.1.0'
4848
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4949
testImplementation 'junit:junit:4.12'
5050
androidTestImplementation 'androidx.test:runner:1.2.0'
5151
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
52-
implementation 'androidx.recyclerview:recyclerview:1.0.0'
52+
implementation 'androidx.recyclerview:recyclerview:1.1.0'
5353
implementation 'com.google.android.material:material:1.0.0'
5454

5555
//Android KTX 是一组 Kotlin 扩展程序,属于 Android Jetpack 系列
56-
implementation 'androidx.core:core-ktx:1.0.2'
56+
implementation 'androidx.core:core-ktx:1.1.0'
5757

5858
//协程
59-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M2'
60-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M2'
61-
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-beta01'
62-
63-
//第三方控件
64-
implementation 'de.hdodenhof:circleimageview:3.0.0'
65-
implementation 'com.just.agentweb:agentweb:4.0.3-beta'
66-
implementation project(path: ':simplebehavior')
67-
implementation 'com.github.bumptech.glide:glide:4.9.0'
68-
implementation 'com.github.GrenderG:Toasty:1.4.2'
69-
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
70-
implementation 'com.github.Kennyc1012:MultiStateView:2.1'
71-
implementation 'com.jaredrummler:animated-svg-view:1.0.6'
72-
implementation 'com.jeremyliao:live-event-bus-x:1.4.4'
73-
implementation 'com.github.nitrico.lastadapter:lastadapter:2.3.0'
74-
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-andx-15'
75-
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-andx-15'
76-
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
77-
implementation 'com.lxj:xpopup:1.8.10-x'
59+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
60+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
61+
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
7862

7963
//okhttp + retrofit(2.6.0支持协程)
8064
implementation("com.squareup.okhttp3:logging-interceptor:4.0.0")
8165
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
8266
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
8367

8468
//协程 + room
85-
implementation "androidx.room:room-runtime:2.1.0"
86-
kapt "androidx.room:room-compiler:2.1.0"
87-
implementation "androidx.room:room-ktx:2.1.0"
69+
implementation "androidx.room:room-runtime:2.2.3"
70+
kapt "androidx.room:room-compiler:2.2.3"
71+
implementation "androidx.room:room-ktx:2.2.3"
8872

8973
//koin(依赖注入)
9074
implementation "org.koin:koin-androidx-scope:2.0.1"
@@ -94,7 +78,22 @@ dependencies {
9478
//动态权限
9579
implementation 'com.afollestad:assent:2.3.1'
9680

97-
81+
//第三方控件
82+
implementation 'de.hdodenhof:circleimageview:3.0.0'
83+
implementation 'com.just.agentweb:agentweb:4.0.3-beta'
84+
implementation project(path: ':simplebehavior')
85+
implementation 'com.github.bumptech.glide:glide:4.9.0'
86+
implementation 'com.github.GrenderG:Toasty:1.4.2'
87+
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
88+
implementation 'com.github.Kennyc1012:MultiStateView:2.1'
89+
implementation 'com.jaredrummler:animated-svg-view:1.0.6'
90+
implementation 'com.jeremyliao:live-event-bus-x:1.4.4'
91+
implementation 'com.github.nitrico.lastadapter:lastadapter:2.3.0'
92+
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
93+
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
94+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
95+
implementation 'com.lxj:xpopup:1.8.10-x'
96+
9897
//bugly捕获异常
9998
implementation 'com.tencent.bugly:crashreport:latest.release'
10099

app/src/main/java/com/fmt/github/WelcomeActivity.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.fmt.github
22

33
import android.content.Intent
4-
import com.afollestad.assent.Permission
5-
import com.afollestad.assent.askForPermissions
4+
import com.afollestad.assent.*
65
import com.fmt.github.base.activity.BaseDataBindActivity
76
import com.fmt.github.databinding.ActivityWelcomeBinding
8-
import com.fmt.github.ext.getVersionName
9-
import com.fmt.github.ext.otherwise
10-
import com.fmt.github.ext.yes
7+
import com.fmt.github.ext.*
118
import com.fmt.github.home.activity.HomeActivity
129
import com.fmt.github.user.activity.LoginActivity
1310
import com.fmt.github.user.dao.UserDao
@@ -38,13 +35,15 @@ class WelcomeActivity : BaseDataBindActivity<ActivityWelcomeBinding>() {
3835
}
3936

4037
private fun askForPermission() {
41-
askForPermissions(Permission.READ_PHONE_STATE) { result ->
42-
result.isAllGranted(Permission.READ_PHONE_STATE).yes {
38+
runWithPermissions(Permission.READ_PHONE_STATE, granted = object : Callback {
39+
override fun invoke(result: AssentResult) {
4340
checkIsLogin()
44-
}.otherwise {
41+
}
42+
}, denied = object : Callback {
43+
override fun invoke(result: AssentResult) {
4544
finish()
4645
}
47-
}
46+
})
4847
}
4948

5049
private fun checkIsLogin() {

app/src/main/java/com/fmt/github/base/activity/BaseActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope()
1010

1111
override fun onCreate(savedInstanceState: Bundle?) {
1212
super.onCreate(savedInstanceState)
13+
setContentLayout()
14+
}
15+
16+
open fun setContentLayout() {
1317
setContentView(getLayoutId())
1418
initView()
1519
initData()

app/src/main/java/com/fmt/github/base/activity/BaseDataBindActivity.kt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
package com.fmt.github.base.activity
22

3-
import android.os.Bundle
4-
import androidx.appcompat.app.AppCompatActivity
53
import androidx.databinding.DataBindingUtil
64
import androidx.databinding.ViewDataBinding
7-
import kotlinx.coroutines.CoroutineScope
8-
import kotlinx.coroutines.MainScope
95
import kotlinx.coroutines.cancel
106

11-
abstract class BaseDataBindActivity<DB : ViewDataBinding> : AppCompatActivity(), CoroutineScope by MainScope() {
7+
abstract class BaseDataBindActivity<DB : ViewDataBinding> : BaseActivity() {
128

139
lateinit var mDataBind: DB
1410

15-
override fun onCreate(savedInstanceState: Bundle?) {
16-
super.onCreate(savedInstanceState)
17-
mDataBind = DataBindingUtil.setContentView(this,getLayoutId())
11+
override fun setContentLayout() {
12+
mDataBind = DataBindingUtil.setContentView(this, getLayoutId())
1813
initView()
1914
initData()
2015
}
2116

22-
abstract fun getLayoutId(): Int
23-
24-
abstract fun initView()
25-
26-
open fun initData() {
27-
28-
}
29-
3017
override fun onDestroy() {
3118
super.onDestroy()
3219
cancel()

app/src/main/java/com/fmt/github/base/activity/BaseDataBindVMActivity.kt

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,25 @@
11
package com.fmt.github.base.activity
22

3-
import android.os.Bundle
4-
import androidx.appcompat.app.AppCompatActivity
53
import androidx.databinding.DataBindingUtil
64
import androidx.databinding.ViewDataBinding
7-
import androidx.lifecycle.Observer
8-
import androidx.lifecycle.ViewModel
9-
import androidx.lifecycle.ViewModelProvider
10-
import com.fmt.github.App
11-
import com.fmt.github.base.viewmodel.*
12-
import com.fmt.github.ext.errorToast
13-
import kotlinx.coroutines.CoroutineScope
14-
import kotlinx.coroutines.MainScope
155
import kotlinx.coroutines.cancel
166

177
/**
188
* 封装带有协程基类(DataBinding + ViewModel),使用代理类完成
199
*
2010
*/
21-
abstract class BaseDataBindVMActivity<DB : ViewDataBinding> : AppCompatActivity(),
22-
CoroutineScope by MainScope() {
11+
abstract class BaseDataBindVMActivity<DB : ViewDataBinding> : BaseVMActivity() {
2312

2413
lateinit var mDataBind: DB
2514

26-
override fun onCreate(savedInstanceState: Bundle?) {
27-
super.onCreate(savedInstanceState)
15+
override fun setContentLayout() {
2816
mDataBind = DataBindingUtil.setContentView(this, getLayoutId())
2917
mDataBind.lifecycleOwner = this
3018
initViewModelAction()
3119
initView()
3220
initData()
3321
}
3422

35-
private fun initViewModelAction() {
36-
getViewModel().let { baseViewModel ->
37-
baseViewModel.mStateLiveData.observe(this, Observer { stateActionState ->
38-
when (stateActionState) {
39-
LoadState -> showLoading()
40-
SuccessState -> dismissLoading()
41-
is ErrorState -> {
42-
dismissLoading()
43-
stateActionState.message?.apply {
44-
errorToast(this)
45-
handleError()
46-
}
47-
}
48-
}
49-
})
50-
}
51-
}
52-
53-
abstract fun getLayoutId(): Int
54-
55-
abstract fun initView()
56-
57-
abstract fun getViewModel(): BaseViewModel
58-
59-
open fun initData() {
60-
61-
}
62-
63-
//由于不同页面可能加载动画不一致,提供空实现,子类根据自身情况进行实现
64-
open fun showLoading() {
65-
66-
}
67-
68-
open fun dismissLoading() {
69-
70-
}
71-
72-
//暴露自定义处理异常方法
73-
open fun handleError() {
74-
75-
}
76-
7723
override fun onDestroy() {
7824
super.onDestroy()
7925
cancel()//取消协程任务

app/src/main/java/com/fmt/github/base/activity/BaseVMActivity.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ abstract class BaseVMActivity : AppCompatActivity(), CoroutineScope by MainScope
1919

2020
override fun onCreate(savedInstanceState: Bundle?) {
2121
super.onCreate(savedInstanceState)
22-
setContentView(getLayoutId())
23-
initViewModelAction()
24-
initView()
25-
initData()
22+
setContentLayout()
2623
}
2724

28-
private fun initViewModelAction() {
25+
protected fun initViewModelAction() {
2926
getViewModel().let { baseViewModel ->
3027
baseViewModel.mStateLiveData.observe(this, Observer { stateActionState ->
3128
when (stateActionState) {
@@ -49,6 +46,13 @@ abstract class BaseVMActivity : AppCompatActivity(), CoroutineScope by MainScope
4946

5047
abstract fun getViewModel(): BaseViewModel
5148

49+
open fun setContentLayout() {
50+
setContentView(getLayoutId())
51+
initViewModelAction()
52+
initView()
53+
initData()
54+
}
55+
5256
open fun initData() {
5357

5458
}
@@ -69,5 +73,4 @@ abstract class BaseVMActivity : AppCompatActivity(), CoroutineScope by MainScope
6973
super.onDestroy()
7074
cancel()//取消协程任务
7175
}
72-
7376
}

0 commit comments

Comments
 (0)