Skip to content

Commit

Permalink
Merge pull request #69 from PetJournal/feature/change-to-new-security…
Browse files Browse the repository at this point in the history
…-code-screen-designer

Feature/change to new security code screen designer
  • Loading branch information
N0stalgiaUltra authored Sep 19, 2024
2 parents d99f295 + 93f5669 commit f64a106
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import androidx.compose.ui.unit.sp
import androidx.core.view.WindowInsetsCompat
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.theme.PetJournalTheme
import ir.kaaveh.sdpcompose.sdp
import ir.kaaveh.sdpcompose.ssp

@Composable
fun HeaderImageLogoImagePasswordAndTitle(
Expand All @@ -45,15 +47,15 @@ fun HeaderImageLogoImagePasswordAndTitle(
modifierImage: Modifier = Modifier,
modifierTextTitle: Modifier = Modifier.padding(start = 8.dp),
styleTitle: TextStyle = MaterialTheme.typography.displayMedium,
spaceBetween: Dp = 0.dp,
spaceBetween: Dp = 0.sdp,
textAlign: TextAlign? = null
) {
val view = LocalView.current
val cutoutInsets = WindowInsetsCompat.toWindowInsetsCompat(view.rootWindowInsets, view)

val topPadding = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
with(LocalDensity.current) {
(cutoutInsets.displayCutout?.safeInsetTop?.toDp() ?: 0.dp) + 10.dp
(cutoutInsets.displayCutout?.safeInsetTop?.toDp() ?: 0.sdp) + 5.sdp
}
} else {
10.dp
Expand All @@ -68,16 +70,16 @@ fun HeaderImageLogoImagePasswordAndTitle(
modifier = Modifier
.fillMaxWidth()
.shadow(
elevation = 8.dp,
shape = RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp),
elevation = 8.sdp,
shape = RoundedCornerShape(bottomStart = 8.sdp, bottomEnd = 8.sdp),
clip = false
)
) {
Row(
Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.background)
.padding(top = topPadding, bottom = 10.dp),
.padding(top = topPadding, bottom = 3.sdp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
) {
Expand All @@ -90,13 +92,13 @@ fun HeaderImageLogoImagePasswordAndTitle(
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp),
.padding(start = 10.sdp),
) {

Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.size(150.dp)
.size(120.sdp)
) {
Image(
painter = painterResource(id = R.drawable.image_password_semi_circulo),
Expand All @@ -113,7 +115,7 @@ fun HeaderImageLogoImagePasswordAndTitle(
painter = painterResource(id = R.drawable.image_password_asterisk),
contentDescription = stringResource(R.string.content_description_image_password),
modifier = Modifier
.size(35.dp)
.size(30.sdp)

)
}
Expand All @@ -125,30 +127,32 @@ fun HeaderImageLogoImagePasswordAndTitle(
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(5.dp),
.padding(12.sdp),
) {
Text(
text = title,
style = styleTitle,
modifier = modifierTextTitle,
color = MaterialTheme.colorScheme.primary,
textAlign = textAlign,
fontSize = 24.sp,
fontSize = 20.ssp,
fontWeight = FontWeight(100)
)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(5.dp),
) {
androidx.compose.material.Text(
text = subText,
style = MaterialTheme.typography.titleLarge,
color = if (isSystemInDarkTheme()) MaterialTheme.colorScheme.primary else Color.Unspecified,
)
if (!subText.isEmpty()){
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.padding(10.sdp),
) {
androidx.compose.material.Text(
text = subText,
style = MaterialTheme.typography.bodyMedium,
color = if (isSystemInDarkTheme()) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen

sealed class AwaitingCodeFormEvent {
data class CodeOTPChanged (val code: String) : com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent()
data class EmailChanged (val email: String) : com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent()
object Submit : com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent()
object ResendCode : com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent()
data class CodeOTPChanged(val code: String) : AwaitingCodeFormEvent()
data class EmailChanged(val email: String) : AwaitingCodeFormEvent()
object Submit : AwaitingCodeFormEvent()
object ResendCode : AwaitingCodeFormEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fun AwaitingCodeScreen(arg: String?, navController: NavController) {

LaunchedEffect(key1 = context) {
if (arg != null) {
viewModel.onEvent(AwaitingCodeFormEvent.EmailChanged(arg))
// viewModel.onEvent(AwaitingCodeFormEvent.EmailChanged(arg))
} else {
navController.navigateUp()
// navController.navigateUp()
}
viewModel.validationEvents.collect { event ->
when (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.receiveAsFlow

abstract class AwaitingCodeViewModel : ViewModel() {
abstract val state: StateFlow<com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormState>
abstract val state: StateFlow<AwaitingCodeFormState>
abstract val buttonIsEnable: StateFlow<Boolean>
abstract val validationEventChannel: Channel<ValidationEvent>
open val validationEvents: Flow<ValidationEvent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.soujunior.domain.model.request.ForgotPasswordModel
import com.soujunior.domain.repository.ValidationRepository
import com.soujunior.domain.use_case.auth.AwaitingCodeUseCase
import com.soujunior.domain.use_case.auth.ForgotPasswordUseCase
import com.soujunior.petjournal.ui.util.ValidationEvent
import com.soujunior.petjournal.ui.states.TaskState
import com.soujunior.petjournal.ui.util.ValidationEvent
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -20,8 +20,10 @@ class AwaitingCodeViewModelImpl(
private val forgotPasswordUseCase: ForgotPasswordUseCase
) : AwaitingCodeViewModel() {

private val _state = MutableStateFlow(com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormState())
override val state: StateFlow<com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormState> = _state
private val _state =
MutableStateFlow(AwaitingCodeFormState())
override val state: StateFlow<AwaitingCodeFormState> =
_state

private val _buttonIsEnable = MutableStateFlow(false)
override val buttonIsEnable: StateFlow<Boolean> = _buttonIsEnable
Expand All @@ -47,12 +49,12 @@ class AwaitingCodeViewModelImpl(
}
}

override fun onEvent(event: com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent) {
override fun onEvent(event: AwaitingCodeFormEvent) {
when (event) {
is com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent.CodeOTPChanged -> changeCode(event.code)
is com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent.EmailChanged -> changeEmail(event.email)
is com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent.Submit -> postOtpVerification()
is com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent.ResendCode -> resendOtpVerification()
is AwaitingCodeFormEvent.CodeOTPChanged -> changeCode(event.code)
is AwaitingCodeFormEvent.EmailChanged -> changeEmail(event.email)
is AwaitingCodeFormEvent.Submit -> postOtpVerification()
is AwaitingCodeFormEvent.ResendCode -> resendOtpVerification()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
package com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.components

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.components.Button2
import com.soujunior.petjournal.ui.components.Button3
import com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent
import com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeViewModel
import com.soujunior.petjournal.ui.states.TaskState
import ir.kaaveh.sdpcompose.sdp

@Composable
fun Footer(navController: NavController, viewModel: AwaitingCodeViewModel) {
val buttonIsEnable by viewModel.buttonIsEnable.collectAsState()
val taskState by viewModel.taskState.collectAsState()

Spacer(modifier = Modifier.padding(20.dp))
Button2(
text = "Enviar",
border = null,
submit = { viewModel.onEvent(com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.AwaitingCodeFormEvent.Submit) },
enableButton = buttonIsEnable,
modifier = Modifier.size(height = 50.dp, width = 240.dp),
buttonColor = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primary
),
isLoading = taskState is TaskState.Loading
)
Spacer(modifier = Modifier.padding(5.dp))
//TODO("Extrair string")
Text(
text = "Dica: Caso não encontre o e-mail na sua caixa de entrada, verifique a pasta de Spam!",
style = MaterialTheme.typography.titleLarge,
textAlign = TextAlign.Center,
color = if (isSystemInDarkTheme()) MaterialTheme.colorScheme.primary else Color.Unspecified
)
val isDarkMode = isSystemInDarkTheme()
Spacer(modifier = Modifier.padding(10.sdp))
Row {
Button3(
submit = { navController.popBackStack() },
enableButton = true,
modifier = Modifier
.weight(1f)
.padding(end = 5.sdp),
text = stringResource(R.string.back),
buttonColor = ButtonDefaults.buttonColors(
MaterialTheme.colorScheme.surface
),
textColor = MaterialTheme.colorScheme.primary
)
Button2(
buttonColor = if (isDarkMode) ButtonDefaults.buttonColors(MaterialTheme.colorScheme.onPrimary)
else ButtonDefaults.buttonColors(MaterialTheme.colorScheme.primary),
text = stringResource(R.string.send),
border = null,
textColor = if (isDarkMode) MaterialTheme.colorScheme.primary else Color.White,
submit = { viewModel.onEvent(AwaitingCodeFormEvent.Submit) },
enableButton = buttonIsEnable,
modifier = Modifier
.weight(1f)
.padding(start = 5.sdp),
isLoading = taskState is TaskState.Loading
)
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
package com.soujunior.petjournal.ui.screens_app.account_manager.awaitingCodeScreen.components

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.soujunior.petjournal.ui.components.CreateTitleAndImageLogo
import com.soujunior.petjournal.R
import com.soujunior.petjournal.ui.components.HeaderImageLogoImagePasswordAndTitle
import ir.kaaveh.sdpcompose.sdp

@Composable
fun Header() {
CreateTitleAndImageLogo(
title = "Acabamos de enviar um código para seu e-mail",
spaceBetween = 16.dp,
textAlign = TextAlign.Center

)

Spacer(modifier = Modifier.padding(16.dp))

Text(
text = "Insira no campo abaixo o código de verificação de 6 digitos enviado para o seu email.",
style = MaterialTheme.typography.titleLarge,
HeaderImageLogoImagePasswordAndTitle(
title = stringResource(R.string.txt_we_just_sent_a_code_to_your_email),
spaceBetween = 10.sdp,
subText = stringResource(R.string.txt_enter_the_6_digit_verification_code_sent_to_your_email_in_the_field_below),
textAlign = TextAlign.Center,
color = if (isSystemInDarkTheme()) MaterialTheme.colorScheme.primary else Color.Unspecified
styleTitle = MaterialTheme.typography.bodyMedium
)

Spacer(modifier = Modifier.padding(32.dp))


}
Loading

0 comments on commit f64a106

Please sign in to comment.