|
@@ -1,17 +1,21 @@
|
|
|
package com.fastest.pass.login.presentation.viewmodels
|
|
|
|
|
|
import android.util.Log
|
|
|
+import androidx.compose.runtime.State
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
+import com.fastest.pass.di.UIState
|
|
|
+import com.fastest.pass.di.WebResponse
|
|
|
+import com.fastest.pass.login.data.model.LoginRequest
|
|
|
import com.fastest.pass.login.data.model.LoginResponse
|
|
|
-import com.fastest.pass.login.data.model.LoginResult
|
|
|
import com.fastest.pass.login.domain.usecase.LoginUseCase
|
|
|
import com.fastest.pass.login.utils.LoginRoute
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
import kotlinx.coroutines.launch
|
|
|
import javax.inject.Inject
|
|
|
-
|
|
|
+import com.fastest.pass.di.Result
|
|
|
@HiltViewModel
|
|
|
class LoginViewModel @Inject constructor(
|
|
|
private val loginUseCase: LoginUseCase
|
|
@@ -20,8 +24,14 @@ class LoginViewModel @Inject constructor(
|
|
|
private val _router = MutableStateFlow<LoginRoute>(LoginRoute.OpenNoneScreen)
|
|
|
val router: MutableStateFlow<LoginRoute> = _router
|
|
|
|
|
|
- private val _loginResponse = MutableStateFlow<LoginResponse<Any>>(LoginResponse(false, ""))
|
|
|
- val loginResponse: MutableStateFlow<LoginResponse<Any>> = _loginResponse
|
|
|
+ /* private val _loginResponse = MutableStateFlow<LoginResponse<Any>>(LoginResponse(false, ""))
|
|
|
+ val loginResponse: MutableStateFlow<LoginResponse<Any>> = _loginResponse*/
|
|
|
+
|
|
|
+ private var _loginResponse =
|
|
|
+ mutableStateOf(UIState<WebResponse<LoginResponse>>())
|
|
|
+ val loginResponse: State<UIState<WebResponse<LoginResponse>>> =
|
|
|
+ _loginResponse
|
|
|
+
|
|
|
|
|
|
private val _loader = MutableStateFlow<Boolean>(false)
|
|
|
val loader: MutableStateFlow<Boolean> = _loader
|
|
@@ -30,7 +40,28 @@ class LoginViewModel @Inject constructor(
|
|
|
_router.value = loginRoute
|
|
|
}
|
|
|
|
|
|
- fun onLoginClicked(email: String, password: String) {
|
|
|
+ fun login(email: String, password: String) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val request = LoginRequest(email, password)
|
|
|
+ loginUseCase(request) { result ->
|
|
|
+ when (result) {
|
|
|
+ is Result.Loading -> {
|
|
|
+ _loginResponse.value = UIState(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ is Result.Success -> {
|
|
|
+ _loginResponse.value = UIState(true,result.data)
|
|
|
+ }
|
|
|
+
|
|
|
+ is Result.Failure -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* fun onLoginClicked(email: String, password: String) {
|
|
|
viewModelScope.launch {
|
|
|
_loader.value = true
|
|
|
Log.d("test_api_login", "onLoginClicked => LoginViewModel")
|
|
@@ -42,5 +73,5 @@ class LoginViewModel @Inject constructor(
|
|
|
}
|
|
|
Log.d("loginResult", "loginResult = ${loginResult.second.message}")
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|