Skip to content

Commit 4181496

Browse files
committed
添加登录个人setting item以及登录个人信息持久化
1 parent af18564 commit 4181496

File tree

53 files changed

+1132
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1132
-301
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/fuusy/jetpackkt/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.fuusy.common.ktx.setupWithNavController
1515
import com.fuusy.common.support.Constants
1616
import com.fuusy.home.ui.HomeFragment
1717
import com.fuusy.jetpackkt.databinding.ActivityMainBinding
18-
import com.fuusy.personal.PersonalFragment
18+
import com.fuusy.personal.ui.PersonalFragment
1919
import com.fuusy.project.ui.ProjectFragment
2020

2121
private const val TAG = "MainActivity"

common/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
1111
//gson
1212
implementation("com.google.code.gson:gson:2.8.6")
13-
14-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
13+
api 'com.blankj:utilcodex:1.29.0'
14+
implementation("com.tencent:mmkv-static:1.2.1")
1515

1616
}

common/src/main/java/com/fuusy/common/base/BaseActivity.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fuusy.common.base
22

33
import android.os.Bundle
4+
import android.widget.ImageView
5+
import android.widget.TextView
46
import androidx.appcompat.app.AppCompatActivity
57
import androidx.databinding.DataBindingUtil
68
import androidx.databinding.ViewDataBinding
@@ -47,4 +49,20 @@ abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity {
4749
fun dismissLoading() {
4850
mLoadingDialog.dismissDialog()
4951
}
52+
53+
54+
55+
/**
56+
* 设置toolbar名称
57+
*/
58+
protected fun setToolbarTitle(view: TextView, title: String) {
59+
view.text = title
60+
}
61+
62+
/**
63+
* 设置toolbar返回按键图片
64+
*/
65+
protected fun setToolbarBackIcon(view: ImageView, id: Int) {
66+
view.setBackgroundResource(id)
67+
}
5068
}

common/src/main/java/com/fuusy/common/base/BaseFragment.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import androidx.databinding.DataBindingUtil
1111
import androidx.databinding.ViewDataBinding
1212
import androidx.fragment.app.Fragment
1313
import androidx.lifecycle.Observer
14+
import com.fuusy.common.support.Constants
15+
import com.fuusy.common.utils.SpUtils
1416
import com.fuusy.common.view.LoadingDialog
1517
import retrofit2.HttpException
1618
import java.net.SocketTimeoutException
@@ -106,4 +108,12 @@ abstract class BaseFragment<T : ViewDataBinding, VM : BaseViewModel> : Fragment
106108
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show()
107109
}
108110

111+
112+
protected fun isLogin(): Boolean {
113+
val userName = SpUtils.getString(Constants.SP_KEY_USER_INFO_NAME)
114+
if (userName == null || userName.isEmpty()) {
115+
return false
116+
}
117+
return true
118+
}
109119
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
package com.fuusy.common.network
2-
3-
import kotlinx.coroutines.CoroutineScope
4-
import kotlinx.coroutines.coroutineScope
5-
import java.io.IOException
6-
7-
8-
/**
9-
* 错误方法
10-
*/
11-
open class BaseRepository() {
12-
13-
suspend fun <T : Any> executeResp(
14-
resp: BaseResp<T>, successBlock: (suspend CoroutineScope.() -> Unit)? = null,
15-
errorBlock: (suspend CoroutineScope.() -> Unit)? = null
16-
): ResState<T> {
17-
return coroutineScope {
18-
if (resp.errorCode == 0) {
19-
successBlock?.let { it() }
20-
ResState.Success(resp.data)
21-
} else {
22-
errorBlock?.let { it() }
23-
ResState.Error(IOException(resp.errorMsg))
24-
}
25-
}
26-
}
27-
1+
package com.fuusy.common.base
2+
3+
import com.fuusy.common.network.BaseResp
4+
import com.fuusy.common.network.ResState
5+
import kotlinx.coroutines.CoroutineScope
6+
import kotlinx.coroutines.coroutineScope
7+
import java.io.IOException
8+
9+
10+
/**
11+
* 错误方法
12+
*/
13+
open class BaseRepository() {
14+
15+
suspend fun <T : Any> executeResp(
16+
resp: BaseResp<T>, successBlock: (suspend CoroutineScope.() -> Unit)? = null,
17+
errorBlock: (suspend CoroutineScope.() -> Unit)? = null
18+
): ResState<T> {
19+
return coroutineScope {
20+
if (resp.errorCode == 0) {
21+
successBlock?.let { it() }
22+
ResState.Success(resp.data)
23+
} else {
24+
errorBlock?.let { it() }
25+
ResState.Error(IOException(resp.errorMsg))
26+
}
27+
}
28+
}
29+
2830
}

common/src/main/java/com/fuusy/common/base/BaseVmActivity.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.fuusy.common.base
22

33
import android.os.Bundle
44
import android.util.Log
5+
import android.widget.ImageView
6+
import android.widget.TextView
57
import android.widget.Toast
68
import androidx.appcompat.app.AppCompatActivity
79
import androidx.databinding.DataBindingUtil
@@ -13,9 +15,11 @@ import retrofit2.HttpException
1315
import java.net.SocketTimeoutException
1416

1517
private const val TAG = "BaseVmActivity"
18+
1619
abstract class BaseVmActivity<T : ViewDataBinding, VM : BaseViewModel> : AppCompatActivity {
1720

1821
constructor() : super()
22+
1923
private lateinit var mLoadingDialog: LoadingDialog
2024

2125
var mBinding: T? = null
@@ -46,13 +50,16 @@ abstract class BaseVmActivity<T : ViewDataBinding, VM : BaseViewModel> : AppComp
4650

4751
}
4852

53+
/**
54+
* 请求时网络异常的处理
55+
*/
4956
private fun throwableHandler(e: Throwable) {
5057
when (e) {
5158
is SocketTimeoutException -> showToast("连接超时")
5259
is HttpException -> {
5360
if (e.code() == 504) {
5461
showToast("网络异常,请检查您的网络状态")
55-
}else if (e.code() == 404) {
62+
} else if (e.code() == 404) {
5663
showToast("请求地址不存在")
5764
}
5865
}
@@ -89,4 +96,19 @@ abstract class BaseVmActivity<T : ViewDataBinding, VM : BaseViewModel> : AppComp
8996
fun dismissLoading() {
9097
mLoadingDialog.dismissDialog()
9198
}
99+
100+
/**
101+
* 设置toolbar名称
102+
*/
103+
protected fun setToolbarTitle(view: TextView, title: String) {
104+
view.text = title
105+
}
106+
107+
/**
108+
* 设置toolbar返回按键图片
109+
*/
110+
protected fun setToolbarBackIcon(view: ImageView, id: Int) {
111+
view.setBackgroundResource(id)
112+
}
113+
92114
}

common/src/main/java/com/fuusy/common/network/BaseState.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

common/src/main/java/com/fuusy/common/network/LoadState.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)