|
@@ -10,9 +10,15 @@ import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.material.Scaffold
|
|
|
+import androidx.compose.material3.SnackbarHostState
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.platform.ComposeView
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.res.colorResource
|
|
|
+import androidx.compose.ui.res.stringResource
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
import androidx.fragment.app.viewModels
|
|
|
import com.fastest.pass.app.BaseFragment
|
|
@@ -27,7 +33,9 @@ import com.fastest.pass.login.presentation.viewmodels.LoginViewModel
|
|
|
import com.fastest.pass.login.utils.LoginNavigation
|
|
|
import com.fastest.pass.login.utils.LoginRoute
|
|
|
import com.fastest.pass.ui.theme.FastestPassTheme
|
|
|
+import com.fastest.pass.views.ShowCustomSnackBar
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
+import kotlinx.coroutines.launch
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
@AndroidEntryPoint
|
|
@@ -61,7 +69,11 @@ class LoginFragment : BaseFragment() {
|
|
|
.background(colorResource(id = R.color.white))
|
|
|
.padding(paddingValues.calculateBottomPadding())
|
|
|
) {
|
|
|
+ val snackBarStateRed = remember { SnackbarHostState() }
|
|
|
val loginResponse = viewmodel.loginResponse.value
|
|
|
+ val coroutineScope = rememberCoroutineScope()
|
|
|
+ val context = LocalContext.current
|
|
|
+ val message = loginResponse.response?.message
|
|
|
|
|
|
loginResponse.response?.data?.let {
|
|
|
if (loginResponse.response?.status == true) {
|
|
@@ -74,7 +86,17 @@ class LoginFragment : BaseFragment() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- LoginScreen(clickType = { clickType ->
|
|
|
+ LaunchedEffect(key1 = message) {
|
|
|
+ message?.let {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginScreen(
|
|
|
+ clickType = { clickType ->
|
|
|
when (clickType) {
|
|
|
ClickType.SIGNUP_CLICK -> {
|
|
|
viewmodel.navigateTo(LoginRoute.OpenSignUp)
|
|
@@ -95,11 +117,19 @@ class LoginFragment : BaseFragment() {
|
|
|
// viewmodel.login("eng.asix@gmail.com", "password")
|
|
|
}
|
|
|
}
|
|
|
- }, onLoginClickCredentials = { email , password ->
|
|
|
+ },
|
|
|
+ onLoginClickCredentials = { email , password ->
|
|
|
Log.d("test_api_login", "onLoginClickCredentials => LoginFragment : $email , $password")
|
|
|
viewmodel.login(email, password)
|
|
|
- })
|
|
|
+ },
|
|
|
+ onShowSnackBar = { text ->
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(context.getString(text))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
+ ShowCustomSnackBar(snackBarStateRed, R.color.red_login_button, R.color.white)
|
|
|
GenericLoader(loginResponse.isLoading)
|
|
|
|
|
|
}
|