增加登录接口和问题回传接口变更
This commit is contained in:
@@ -10,7 +10,6 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.blankj.utilcode.util.ResourceUtils
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.bean.LoginUserBean
|
||||
import com.navinfo.omqs.db.MyRealmModule
|
||||
import com.navinfo.omqs.db.RoomAppDatabase
|
||||
import com.navinfo.omqs.http.NetResult
|
||||
import com.navinfo.omqs.http.NetworkService
|
||||
@@ -19,6 +18,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import kotlinx.coroutines.*
|
||||
import retrofit2.Response
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
@@ -74,7 +74,7 @@ class LoginViewModel @Inject constructor(
|
||||
var jobLogin: Job? = null;
|
||||
|
||||
init {
|
||||
loginUser.value = LoginUserBean(username = "admin", password = "123456")
|
||||
loginUser.value = LoginUserBean(userCode = "02911", passWord = "123456")
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class LoginViewModel @Inject constructor(
|
||||
* 处理注册按钮
|
||||
*/
|
||||
fun onClick(view: View) {
|
||||
loginUser.value!!.username = "admin2"
|
||||
loginUser.value!!.userCode = "admin2"
|
||||
loginUser.value = loginUser.value
|
||||
}
|
||||
|
||||
@@ -111,12 +111,36 @@ class LoginViewModel @Inject constructor(
|
||||
// withContext(Dispatchers.IO) {
|
||||
//网络访问
|
||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_NET_LOADING)
|
||||
//假装网络访问,等待2秒
|
||||
delay(1000)
|
||||
//登录访问
|
||||
when (val result = networkService.loginUser(LoginUserBean(userName,password))) {
|
||||
is NetResult.Success<*> ->{
|
||||
if (result.data!=null) {
|
||||
try {
|
||||
|
||||
} catch (e: IOException) {
|
||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_FAILURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
is NetResult.Error<*> ->{
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
is NetResult.Failure<*> ->{
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
//文件夹初始化
|
||||
try {
|
||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_INIT)
|
||||
createUserFolder(context, "02911")
|
||||
createUserFolder(context, userName)
|
||||
} catch (e: IOException) {
|
||||
loginStatus.postValue(LoginStatus.LOGIN_STATUS_FOLDER_FAILURE)
|
||||
}
|
||||
@@ -134,13 +158,13 @@ class LoginViewModel @Inject constructor(
|
||||
roomAppDatabase.getOfflineMapDao().insertOrUpdate(result.data)
|
||||
}
|
||||
}
|
||||
is NetResult.Error -> {
|
||||
is NetResult.Error<*> -> {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
is NetResult.Failure -> {
|
||||
is NetResult.Failure<*> -> {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
|
||||
@@ -91,13 +91,13 @@ class TaskViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
is NetResult.Error -> {
|
||||
is NetResult.Error<*> -> {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.exception.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
is NetResult.Failure -> {
|
||||
is NetResult.Failure<*> -> {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(context, "${result.code}:${result.msg}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
|
||||
Reference in New Issue
Block a user