-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #10 from snuhcs-course/refactor/auth-frontend
Refactor/auth frontend
- Loading branch information
Showing
23 changed files
with
826 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
frontend/app/src/main/java/com/example/speechbuddy/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.example.speechbuddy | ||
|
||
import android.app.Application | ||
import com.example.speechbuddy.domain.utils.TokenSharedPreferences | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class MainApplication : Application() | ||
class MainApplication : Application(){ | ||
companion object{ | ||
lateinit var token_prefs : TokenSharedPreferences | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...rc/main/java/com/example/speechbuddy/compose/emailverification/EmailVerificationScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.example.speechbuddy.compose.emailverification | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.rememberNavController | ||
import com.example.speechbuddy.R | ||
import com.example.speechbuddy.compose.utils.ButtonLevel | ||
import com.example.speechbuddy.compose.utils.ButtonUi | ||
import com.example.speechbuddy.compose.utils.TextFieldUi | ||
import com.example.speechbuddy.compose.utils.TitleUi | ||
import com.example.speechbuddy.compose.utils.TopAppBarUi | ||
import com.example.speechbuddy.ui.SpeechBuddyTheme | ||
import com.example.speechbuddy.ui.models.EmailVerificationErrorType | ||
import com.example.speechbuddy.viewmodel.EmailVerificationViewModel | ||
|
||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun EmailVerificationScreen( | ||
source: String?, | ||
modifier: Modifier = Modifier, | ||
onBackClick: () -> Unit, | ||
navController: NavHostController, | ||
viewModel: EmailVerificationViewModel = hiltViewModel() | ||
) { | ||
val uiState by viewModel.uiState.collectAsState() | ||
val isEmailError = uiState.error?.type == EmailVerificationErrorType.EMAIL | ||
val isVerifyCodeError = uiState.error?.type == EmailVerificationErrorType.VERIFY_CODE | ||
val isError = isEmailError || isVerifyCodeError | ||
|
||
Surface( | ||
modifier = modifier.fillMaxSize() | ||
) { | ||
Scaffold( | ||
topBar = { TopAppBarUi(onBackClick = onBackClick) } | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(horizontal = 24.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
TitleUi( | ||
title = when (source) { | ||
"reset_password" -> stringResource(id = R.string.reset_password_title) | ||
"signup" -> stringResource(id = R.string.verify_email_field) | ||
else -> stringResource(id = R.string.verify_email_field) | ||
}, | ||
description = when (source) { | ||
"reset_password" -> stringResource(id = R.string.reset_password_subtitle1) | ||
"signup" -> stringResource(id = R.string.verify_email_explain) | ||
else -> stringResource(id = R.string.verify_email_explain_default) | ||
} | ||
) | ||
|
||
Spacer(modifier = Modifier.height(15.dp)) | ||
|
||
// Email Text Field | ||
TextFieldUi( | ||
value = viewModel.emailInput, | ||
onValueChange = { viewModel.setEmail(it) }, | ||
label = { Text(text = stringResource(id = R.string.email_field)) }, | ||
supportingButton = { | ||
ButtonUi( | ||
text = stringResource(id = R.string.send_validation_code), | ||
onClick = { viewModel.verifySend(source) }, | ||
level = ButtonLevel.TERTIARY | ||
) | ||
}, | ||
supportingText = { | ||
if (isEmailError) { | ||
Text(stringResource(id = uiState.error!!.messageId)) | ||
} else if(uiState.isSuccessfulSend) { | ||
Text(stringResource(id = R.string.verification_code_sent)) | ||
} | ||
}, | ||
isError = isError, | ||
isValid = uiState.isValidEmail, | ||
// If verification email is sent successfully, a user cannot change one's email input | ||
isEnabled = !uiState.isSuccessfulSend | ||
) | ||
|
||
// Verify code Text Field | ||
TextFieldUi( | ||
value = viewModel.verifyCodeInput, | ||
onValueChange = { viewModel.setVerifyCode(it) }, | ||
label = { Text(text = stringResource(id = R.string.validation_code)) }, | ||
supportingText = { | ||
if (isVerifyCodeError) { | ||
Text(stringResource(id = uiState.error!!.messageId)) | ||
} | ||
}, | ||
isError = isError, | ||
isValid = uiState.isValidVerifyCode, | ||
isEnabled = uiState.isSuccessfulSend | ||
) | ||
|
||
Spacer(modifier = Modifier.height(15.dp)) | ||
|
||
ButtonUi( | ||
text = stringResource(id = R.string.next), | ||
onClick = { viewModel.verifyAccept(source, navController) }, | ||
isEnabled = uiState.isSuccessfulSend | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 0 additions & 113 deletions
113
...pp/src/main/java/com/example/speechbuddy/compose/resetpassword/EmailVerificationScreen.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.