增加登录缓存校验
This commit is contained in:
parent
392fb91215
commit
0848ee491b
@ -1,6 +1,7 @@
|
|||||||
package com.navinfo.omqs.ui.activity.login
|
package com.navinfo.omqs.ui.activity.login
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -16,11 +17,11 @@ import com.navinfo.omqs.http.DefaultResponse
|
|||||||
import com.navinfo.omqs.http.NetResult
|
import com.navinfo.omqs.http.NetResult
|
||||||
import com.navinfo.omqs.http.NetworkService
|
import com.navinfo.omqs.http.NetworkService
|
||||||
import com.navinfo.omqs.tools.FileManager
|
import com.navinfo.omqs.tools.FileManager
|
||||||
|
import com.navinfo.omqs.util.NetUtils
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import retrofit2.Response
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -73,7 +74,9 @@ class LoginViewModel @Inject constructor(
|
|||||||
//是不是登录成功
|
//是不是登录成功
|
||||||
val loginStatus: MutableLiveData<LoginStatus> = MutableLiveData()
|
val loginStatus: MutableLiveData<LoginStatus> = MutableLiveData()
|
||||||
|
|
||||||
var jobLogin: Job? = null;
|
var jobLogin: Job? = null
|
||||||
|
|
||||||
|
var sharedPreferences: SharedPreferences? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loginUser.value = LoginUserBean(userCode = "haofuyue00213", passWord = "123456")
|
loginUser.value = LoginUserBean(userCode = "haofuyue00213", passWord = "123456")
|
||||||
@ -98,10 +101,26 @@ class LoginViewModel @Inject constructor(
|
|||||||
if (password.isEmpty()) {
|
if (password.isEmpty()) {
|
||||||
Toast.makeText(context, "请输入密码", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "请输入密码", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
sharedPreferences =
|
||||||
|
context.getSharedPreferences("USER_SHAREDPREFERENCES", Context.MODE_PRIVATE)
|
||||||
|
val userNameCache = sharedPreferences?.getString("userName", null)
|
||||||
|
val passwordCache = sharedPreferences?.getString("passWord", null)
|
||||||
|
val userCodeCache = sharedPreferences?.getString("userCode", null)
|
||||||
|
//增加缓存记录,不用每次连接网络登录
|
||||||
|
if (userNameCache != null && passwordCache != null && userCodeCache != null) {
|
||||||
|
if (userNameCache == userName && passwordCache == password) {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
createUserFolder(context, userCodeCache)
|
||||||
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_SUCCESS)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
//不指定IO,会在主线程里运行
|
//不指定IO,会在主线程里运行
|
||||||
jobLogin = viewModelScope.launch(Dispatchers.IO) {
|
jobLogin = viewModelScope.launch(Dispatchers.IO) {
|
||||||
loginCheck(context, userName, password)
|
loginCheck(context, userName, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,25 +134,33 @@ class LoginViewModel @Inject constructor(
|
|||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_NET_LOADING)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_NET_LOADING)
|
||||||
var userCode = "99999";
|
var userCode = "99999";
|
||||||
//登录访问
|
//登录访问
|
||||||
when (val result = networkService.loginUser(LoginUserBean(userName,password))) {
|
when (val result = networkService.loginUser(LoginUserBean(userName, password))) {
|
||||||
is NetResult.Success<*> ->{
|
is NetResult.Success<*> -> {
|
||||||
if (result.data!=null) {
|
if (result.data != null) {
|
||||||
try {
|
try {
|
||||||
val defaultUserResponse = result.data as DefaultResponse<SysUserBean>
|
val defaultUserResponse = result.data as DefaultResponse<SysUserBean>
|
||||||
if(defaultUserResponse.success){
|
if (defaultUserResponse.success) {
|
||||||
if(defaultUserResponse.obj==null|| defaultUserResponse.obj!!.userCode==null){
|
if (defaultUserResponse.obj == null || defaultUserResponse.obj!!.userCode == null) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "服务返回用户Code信息错误", Toast.LENGTH_SHORT)
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"服务返回用户Code信息错误",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
||||||
return
|
return
|
||||||
}else{
|
} else {
|
||||||
userCode = defaultUserResponse.obj?.userCode.toString()
|
userCode = defaultUserResponse.obj?.userCode.toString()
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "${defaultUserResponse.msg}", Toast.LENGTH_SHORT)
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${defaultUserResponse.msg}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
||||||
@ -145,7 +172,8 @@ class LoginViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is NetResult.Error<*> ->{
|
|
||||||
|
is NetResult.Error<*> -> {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
@ -153,7 +181,8 @@ class LoginViewModel @Inject constructor(
|
|||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
is NetResult.Failure<*> ->{
|
|
||||||
|
is NetResult.Failure<*> -> {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
@ -161,12 +190,16 @@ class LoginViewModel @Inject constructor(
|
|||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_CANCEL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
//文件夹初始化
|
//文件夹初始化
|
||||||
try {
|
try {
|
||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_INIT)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_INIT)
|
||||||
|
sharedPreferences?.edit()?.putString("userName", userName)?.commit()
|
||||||
|
sharedPreferences?.edit()?.putString("passWord", password)?.commit()
|
||||||
|
sharedPreferences?.edit()?.putString("userCode", userCode)?.commit()
|
||||||
createUserFolder(context, userCode)
|
createUserFolder(context, userCode)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_FAILURE)
|
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_FAILURE)
|
||||||
@ -185,18 +218,21 @@ class LoginViewModel @Inject constructor(
|
|||||||
roomAppDatabase.getOfflineMapDao().insertOrUpdate(result.data)
|
roomAppDatabase.getOfflineMapDao().insertOrUpdate(result.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetResult.Error<*> -> {
|
is NetResult.Error<*> -> {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetResult.Failure<*> -> {
|
is NetResult.Failure<*> -> {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetResult.Loading -> {}
|
is NetResult.Loading -> {}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
@ -234,7 +270,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
// 拷贝配置文件到用户目录下
|
// 拷贝配置文件到用户目录下
|
||||||
val omdbConfigFile = File(userFolder.absolutePath, Constant.OMDB_CONFIG);
|
val omdbConfigFile = File(userFolder.absolutePath, Constant.OMDB_CONFIG);
|
||||||
// if (!omdbConfigFile.exists()) {
|
// if (!omdbConfigFile.exists()) {
|
||||||
ResourceUtils.copyFileFromAssets(Constant.OMDB_CONFIG, omdbConfigFile.absolutePath)
|
ResourceUtils.copyFileFromAssets(Constant.OMDB_CONFIG, omdbConfigFile.absolutePath)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ class MainActivity : BaseActivity() {
|
|||||||
private fun setIndoorGroupEnable(enable: Boolean) {
|
private fun setIndoorGroupEnable(enable: Boolean) {
|
||||||
binding.mainActivitySnapshotFinish.isEnabled = enable
|
binding.mainActivitySnapshotFinish.isEnabled = enable
|
||||||
binding.mainActivityTraceSnapshotPoints.isEnabled = enable
|
binding.mainActivityTraceSnapshotPoints.isEnabled = enable
|
||||||
binding.mainActivitySnapshotMediaFlag.isEnabled = enable
|
//binding.mainActivitySnapshotMediaFlag.isEnabled = enable
|
||||||
binding.mainActivitySnapshotRewind.isEnabled = enable
|
binding.mainActivitySnapshotRewind.isEnabled = enable
|
||||||
binding.mainActivitySnapshotPause.isEnabled = enable
|
binding.mainActivitySnapshotPause.isEnabled = enable
|
||||||
binding.mainActivitySnapshotNext.isEnabled = enable
|
binding.mainActivitySnapshotNext.isEnabled = enable
|
||||||
|
@ -370,4 +370,5 @@ public class ShareUtil {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -362,6 +362,7 @@
|
|||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/main_activity_snapshot_media_flag"
|
android:id="@+id/main_activity_snapshot_media_flag"
|
||||||
style="@style/top_right_drawer_btns_style"
|
style="@style/top_right_drawer_btns_style"
|
||||||
|
android:visibility="gone"
|
||||||
android:onClick="@{()->mainActivity.mediaFlagOnclick()}"
|
android:onClick="@{()->mainActivity.mediaFlagOnclick()}"
|
||||||
android:src="@drawable/map_trace_mediaflag" />
|
android:src="@drawable/map_trace_mediaflag" />
|
||||||
|
|
||||||
|
@ -1708,9 +1708,13 @@
|
|||||||
<!-- 道路边界类型 -->
|
<!-- 道路边界类型 -->
|
||||||
<m v="OMDB_RDBOUND_BOUNDARYTYPE">
|
<m v="OMDB_RDBOUND_BOUNDARYTYPE">
|
||||||
<outline-layer id="boundaryType" stroke="#8e44ad" width="0.2" />
|
<outline-layer id="boundaryType" stroke="#8e44ad" width="0.2" />
|
||||||
<m k="boundaryType" v="0|1|2|3|4|5|6|7|8|9">
|
<m k="boundaryType" v="0|2|3|4|5|6|7|8|9">
|
||||||
<line stroke="#ffffff" use="boundaryType" width="0.2"/>
|
<line stroke="#ffffff" use="boundaryType" width="0.2"/>
|
||||||
</m>
|
</m>
|
||||||
|
<m k="boundaryType" v="1">
|
||||||
|
<!--无标线无可区分边界-->
|
||||||
|
<line dasharray="10,2,2,2,2,2,2,2" repeat-start="0" stroke="#ffffff" width="0.2" />
|
||||||
|
</m>
|
||||||
<!-- <outline-layer id="boundaryType" stroke="#fcba5a" width="0.2" />
|
<!-- <outline-layer id="boundaryType" stroke="#fcba5a" width="0.2" />
|
||||||
<m k="boundaryType" v="0">
|
<m k="boundaryType" v="0">
|
||||||
<!–不应用–>
|
<!–不应用–>
|
||||||
@ -1767,8 +1771,9 @@
|
|||||||
<m v="1">
|
<m v="1">
|
||||||
<line stroke="#ffffff" use="boundaryType" />
|
<line stroke="#ffffff" use="boundaryType" />
|
||||||
</m>
|
</m>
|
||||||
|
<!--只区分虚线与实线-->
|
||||||
<m v="2">
|
<m v="2">
|
||||||
<line stroke="#eccc68" use="boundaryType" />
|
<line dasharray="10,2,2,2,2,2,2,2" repeat-start="0" stroke="#eccc68" use="boundaryType" />
|
||||||
</m>
|
</m>
|
||||||
<m v="6">
|
<m v="6">
|
||||||
<line stroke="#0000ff" use="boundaryType" />
|
<line stroke="#0000ff" use="boundaryType" />
|
||||||
@ -1815,7 +1820,11 @@
|
|||||||
</m>
|
</m>
|
||||||
</m>
|
</m>
|
||||||
<m v="0|1|3|4|5|6|7|8|9">
|
<m v="0|1|3|4|5|6|7|8|9">
|
||||||
<line stroke="#ffffff" use="boundaryType"/>
|
<line stroke="#ffffff" use="boundaryType" />
|
||||||
|
</m>
|
||||||
|
<!--只区分虚线与实线-->
|
||||||
|
<m v="0|3|4|5|6|7|8|9">
|
||||||
|
<line dasharray="10,2,2,2,2,2,2,2" repeat-start="0" stroke="#ffffff" />
|
||||||
</m>
|
</m>
|
||||||
</m>
|
</m>
|
||||||
</m>
|
</m>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user