|
@@ -1,12 +1,11 @@
|
|
|
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.app.UIState
|
|
|
+import com.fastest.pass.app.WebResponse
|
|
|
import com.fastest.pass.login.data.model.LoginRequest
|
|
|
import com.fastest.pass.login.data.model.LoginResponse
|
|
|
import com.fastest.pass.login.domain.usecase.LoginUseCase
|
|
@@ -15,31 +14,17 @@ 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
|
|
|
+import com.fastest.pass.app.Result
|
|
|
@HiltViewModel
|
|
|
class LoginViewModel @Inject constructor(
|
|
|
private val loginUseCase: LoginUseCase
|
|
|
) : ViewModel() {
|
|
|
|
|
|
- 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 var _loginResponse =
|
|
|
mutableStateOf(UIState<WebResponse<LoginResponse>>())
|
|
|
val loginResponse: State<UIState<WebResponse<LoginResponse>>> =
|
|
|
_loginResponse
|
|
|
|
|
|
-
|
|
|
- private val _loader = MutableStateFlow<Boolean>(false)
|
|
|
- val loader: MutableStateFlow<Boolean> = _loader
|
|
|
-
|
|
|
- fun navigateTo(loginRoute: LoginRoute) {
|
|
|
- _router.value = loginRoute
|
|
|
- }
|
|
|
-
|
|
|
fun login(email: String, password: String) {
|
|
|
viewModelScope.launch {
|
|
|
val request = LoginRequest(email, password)
|
|
@@ -50,28 +35,21 @@ class LoginViewModel @Inject constructor(
|
|
|
}
|
|
|
|
|
|
is Result.Success -> {
|
|
|
- _loginResponse.value = UIState(true,result.data)
|
|
|
+ _loginResponse.value = UIState(false,result.data)
|
|
|
}
|
|
|
|
|
|
is Result.Failure -> {
|
|
|
-
|
|
|
+ _loginResponse.value = UIState(false)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /* fun onLoginClicked(email: String, password: String) {
|
|
|
- viewModelScope.launch {
|
|
|
- _loader.value = true
|
|
|
- Log.d("test_api_login", "onLoginClicked => LoginViewModel")
|
|
|
- val loginResult = loginUseCase(email, password)
|
|
|
- _loader.value = false
|
|
|
+ private val _router = MutableStateFlow<LoginRoute>(LoginRoute.OpenNoneScreen)
|
|
|
+ val router: MutableStateFlow<LoginRoute> = _router
|
|
|
|
|
|
- if (loginResult.second.status) {
|
|
|
- _loginResponse.value = loginResult.second
|
|
|
- }
|
|
|
- Log.d("loginResult", "loginResult = ${loginResult.second.message}")
|
|
|
- }
|
|
|
- }*/
|
|
|
+ fun navigateTo(loginRoute: LoginRoute) {
|
|
|
+ _router.value = loginRoute
|
|
|
+ }
|
|
|
}
|