-
Notifications
You must be signed in to change notification settings - Fork 0
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 #86 from everymeals/feature/school_auth_screen
[Feature/school_auth_screen]: 학교 이메일 인증 작업
Showing
21 changed files
with
581 additions
and
14 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: 7 additions & 0 deletions
7
data/src/main/java/com/everymeal/data/datasource/auth/AuthRemoteDataSource.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,7 @@ | ||
package com.everymeal.data.datasource.auth | ||
|
||
import com.everymeal.domain.model.auth.Email | ||
|
||
interface AuthRemoteDataSource { | ||
suspend fun postEmail(email: Email): Result<String> | ||
} |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/everymeal/data/datasource/auth/AuthRemoteRemoteDataSourceImpl.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,16 @@ | ||
package com.everymeal.data.datasource.auth | ||
|
||
import com.everymeal.data.model.auth.toEmailRequest | ||
import com.everymeal.data.model.unwrapData | ||
import com.everymeal.data.service.auth.AuthApi | ||
import com.everymeal.domain.model.auth.Email | ||
import javax.inject.Inject | ||
|
||
class AuthRemoteRemoteDataSourceImpl @Inject constructor( | ||
private val authApi: AuthApi | ||
) : AuthRemoteDataSource { | ||
|
||
override suspend fun postEmail(email: Email): Result<String> = runCatching { | ||
authApi.postEmail(email.toEmailRequest()) | ||
}.unwrapData() | ||
} |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/everymeal/data/model/auth/EmailRequest.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,20 @@ | ||
package com.everymeal.data.model.auth | ||
|
||
|
||
import com.everymeal.domain.model.auth.Email | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class EmailRequest( | ||
@SerialName("email") | ||
val email: String? = null | ||
) | ||
|
||
fun EmailRequest.toEmail() = Email( | ||
email = email ?: "" | ||
) | ||
|
||
fun Email.toEmailRequest() = EmailRequest( | ||
email = email | ||
) |
14 changes: 14 additions & 0 deletions
14
data/src/main/java/com/everymeal/data/repository/DefaultAuthRepository.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,14 @@ | ||
package com.everymeal.data.repository | ||
|
||
import com.everymeal.data.datasource.auth.AuthRemoteDataSource | ||
import com.everymeal.domain.model.auth.Email | ||
import com.everymeal.domain.repository.auth.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class DefaultAuthRepository @Inject constructor( | ||
private val authRemoteDataSource: AuthRemoteDataSource | ||
) : AuthRepository { | ||
override suspend fun postEmail(email: Email): Result<String> { | ||
return authRemoteDataSource.postEmail(email) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/everymeal/data/service/auth/AuthApi.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,10 @@ | ||
package com.everymeal.data.service.auth | ||
|
||
import com.everymeal.data.model.BaseResponse | ||
import com.everymeal.data.model.auth.EmailRequest | ||
import retrofit2.http.POST | ||
|
||
interface AuthApi { | ||
@POST("/api/v1/users/email") | ||
suspend fun postEmail(emailRequest: EmailRequest): BaseResponse<String> | ||
} |
5 changes: 5 additions & 0 deletions
5
domain/src/main/java/com/everymeal/domain/model/auth/Email.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,5 @@ | ||
package com.everymeal.domain.model.auth | ||
|
||
data class Email( | ||
val email: String | ||
) |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/com/everymeal/domain/repository/auth/AuthRepository.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,8 @@ | ||
package com.everymeal.domain.repository.auth | ||
|
||
import com.everymeal.domain.model.auth.Email | ||
|
||
interface AuthRepository { | ||
suspend fun postEmail(email: Email): Result<String> | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/com/everymeal/domain/usecase/auth/PostEmailUseCase.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,15 @@ | ||
package com.everymeal.domain.usecase.auth | ||
|
||
import com.everymeal.domain.model.auth.Email | ||
import com.everymeal.domain.repository.auth.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class PostEmailUseCase @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) { | ||
suspend operator fun invoke( | ||
email: Email | ||
): Result<String> { | ||
return authRepository.postEmail(email) | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -101,4 +101,4 @@ fun MainScreen( | |
@Composable | ||
fun MainScreenPreview() { | ||
MainScreen() | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
presentation/src/main/java/com/everymeal/presentation/ui/signup/school/SchoolAuthScreen.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,126 @@ | ||
package com.everymeal.presentation.ui.signup.school | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CenterAlignedTopAppBar | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
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 com.everymeal.presentation.R | ||
import com.everymeal.presentation.components.EveryMealConditionAgreeDialog | ||
import com.everymeal.presentation.components.EveryMealConditionAgreeDialogItem | ||
import com.everymeal.presentation.ui.signup.school.email.SchoolAuthPostEmailScreen | ||
import com.everymeal.presentation.ui.theme.EveryMealTypography | ||
|
||
enum class SchoolAuthScreenType { | ||
POST_EMAIL, | ||
VERIFY_TOKEN, | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun SchoolAuthScreen( | ||
viewModel: SchoolAuthViewModel = hiltViewModel() | ||
) { | ||
val viewState by viewModel.viewState.collectAsState() | ||
Scaffold( | ||
topBar = { | ||
CenterAlignedTopAppBar( | ||
title = { | ||
Text( | ||
text = stringResource(id = R.string.school_auth_title), | ||
style = EveryMealTypography.Subtitle2, | ||
) | ||
}, | ||
navigationIcon = { | ||
Image( | ||
modifier = Modifier | ||
.size(48.dp) | ||
.padding(12.dp), | ||
painter = painterResource(id = R.drawable.icon_x_mono), | ||
contentDescription = "close" | ||
) | ||
}) | ||
} | ||
) | ||
{ innerPadding -> | ||
SchoolAuthContent( | ||
modifier = Modifier | ||
.padding(innerPadding) | ||
.padding(horizontal = 20.dp), | ||
viewModel = viewModel, | ||
state = viewState | ||
) | ||
if (viewState.isShowConditionBottomSheet) { | ||
EmailAuthBottomSheet(viewModel) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun EmailAuthBottomSheet(viewModel: SchoolAuthViewModel) { | ||
val conditionItems = remember { | ||
mutableStateListOf( | ||
EveryMealConditionAgreeDialogItem( | ||
title = "[필수] 이용 약관 동의", | ||
isAgreed = true, | ||
isEssential = true, | ||
), | ||
EveryMealConditionAgreeDialogItem( | ||
title = "[필수] 개인정보 수집 및 이용 동의", | ||
isAgreed = true, | ||
isEssential = true, | ||
), | ||
EveryMealConditionAgreeDialogItem( | ||
title = "[선택] 마케팅 정보 수집 동의", | ||
isAgreed = true, | ||
) | ||
) | ||
} | ||
|
||
EveryMealConditionAgreeDialog( | ||
onItemClicked = { | ||
conditionItems[it] = | ||
conditionItems[it].copy(isAgreed = !conditionItems[it].isAgreed) | ||
}, | ||
onNextButtonClicked = { | ||
if (conditionItems.filter { it.isEssential }.any { it.isAgreed }) { | ||
viewModel.setEvent(SchoolContract.Event.OnPostEmail) | ||
} | ||
}, | ||
onDismiss = {}, | ||
conditionItems = conditionItems | ||
) | ||
} | ||
|
||
@Composable | ||
fun SchoolAuthContent( | ||
modifier: Modifier = Modifier, | ||
viewModel: SchoolAuthViewModel, | ||
state: SchoolContract.State | ||
) { | ||
SchoolAuthPostEmailScreen( | ||
modifier = modifier, | ||
viewModel = viewModel, | ||
state = state, | ||
) | ||
} | ||
|
||
|
||
@Preview | ||
@Composable | ||
fun SchoolAuthScreenPreview() { | ||
SchoolAuthScreen() | ||
} |
65 changes: 65 additions & 0 deletions
65
...entation/src/main/java/com/everymeal/presentation/ui/signup/school/SchoolAuthViewModel.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,65 @@ | ||
package com.everymeal.presentation.ui.signup.school | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.everymeal.domain.model.auth.Email | ||
import com.everymeal.domain.usecase.auth.PostEmailUseCase | ||
import com.everymeal.presentation.base.BaseViewModel | ||
import kotlinx.coroutines.launch | ||
import retrofit2.HttpException | ||
import javax.inject.Inject | ||
|
||
class SchoolAuthViewModel @Inject constructor( | ||
private val postEmailUseCase: PostEmailUseCase | ||
) : | ||
BaseViewModel<SchoolContract.State, SchoolContract.Effect, SchoolContract.Event>(SchoolContract.State()) { | ||
|
||
companion object { | ||
private val EMAIL_REGEX = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+".toRegex() | ||
} | ||
|
||
override fun handleEvents(event: SchoolContract.Event) { | ||
when (event) { | ||
is SchoolContract.Event.OnEmailTextChanged -> { | ||
updateState { | ||
copy( | ||
isEmailError = isValidEmail(event.emailLink), | ||
emailLink = event.emailLink | ||
) | ||
} | ||
} | ||
|
||
is SchoolContract.Event.OnNextButtonClicked -> { | ||
updateState { | ||
copy(isShowConditionBottomSheet = true) | ||
} | ||
} | ||
|
||
is SchoolContract.Event.OnPostEmail -> { | ||
postEmail() | ||
} | ||
|
||
SchoolContract.Event.FailEmailVerification -> { | ||
sendEffect() | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun isValidEmail(email: String): Boolean { | ||
return EMAIL_REGEX.matches(email) | ||
} | ||
|
||
private fun postEmail() { | ||
viewModelScope.launch { | ||
postEmailUseCase(Email(viewState.value.emailLink)).onSuccess { | ||
updateState { | ||
copy(emailAuthToken = it) | ||
} | ||
}.onFailure { | ||
if (it is HttpException) { | ||
sendEffect({ SchoolContract.Effect.Error(it.code()) }) | ||
} | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
presentation/src/main/java/com/everymeal/presentation/ui/signup/school/SchoolContract.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,27 @@ | ||
package com.everymeal.presentation.ui.signup.school | ||
|
||
import com.everymeal.presentation.base.ViewEvent | ||
import com.everymeal.presentation.base.ViewSideEffect | ||
import com.everymeal.presentation.base.ViewState | ||
|
||
class SchoolContract { | ||
|
||
data class State( | ||
val schoolAuthScreenType: SchoolAuthScreenType = SchoolAuthScreenType.POST_EMAIL, | ||
val isShowConditionBottomSheet: Boolean = false, | ||
val isEmailError: Boolean = false, | ||
val emailLink: String = "", | ||
val emailAuthToken: String = "" | ||
) : ViewState | ||
|
||
sealed class Event : ViewEvent { | ||
data class OnEmailTextChanged(val emailLink: String) : Event() | ||
object OnNextButtonClicked : Event() | ||
object OnPostEmail : Event() | ||
object FailEmailVerification : Event() | ||
} | ||
|
||
sealed class Effect : ViewSideEffect { | ||
data class Error(val code: Int) : Effect() | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
.../main/java/com/everymeal/presentation/ui/signup/school/email/SchoolAuthPostEmailScreen.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,75 @@ | ||
package com.everymeal.presentation.ui.signup.school.email | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.everymeal.presentation.R | ||
import com.everymeal.presentation.components.EveryMealMainButton | ||
import com.everymeal.presentation.components.EveryMealTextField | ||
import com.everymeal.presentation.ui.signup.school.SchoolAuthScreenType | ||
import com.everymeal.presentation.ui.signup.school.SchoolAuthViewModel | ||
import com.everymeal.presentation.ui.signup.school.SchoolContract | ||
import com.everymeal.presentation.ui.theme.EveryMealTypography | ||
import com.everymeal.presentation.ui.theme.Gray100 | ||
import com.everymeal.presentation.ui.theme.Gray900 | ||
import com.everymeal.presentation.ui.theme.Main100 | ||
|
||
@Composable | ||
fun SchoolAuthPostEmailScreen( | ||
modifier: Modifier, | ||
state: SchoolContract.State, | ||
viewModel: SchoolAuthViewModel | ||
) { | ||
Column( | ||
modifier = modifier.padding(top = 48.dp) | ||
) { | ||
Text( | ||
text = when (state.schoolAuthScreenType) { | ||
SchoolAuthScreenType.POST_EMAIL -> stringResource(id = R.string.school_auth_content) | ||
SchoolAuthScreenType.VERIFY_TOKEN -> stringResource(id = R.string.email_token_verify_title) | ||
}, | ||
style = EveryMealTypography.Heading1, | ||
color = Gray900 | ||
) | ||
Spacer(modifier = Modifier.size(40.dp)) | ||
Text( | ||
text = when(state.schoolAuthScreenType) { | ||
SchoolAuthScreenType.POST_EMAIL -> stringResource(id = R.string.email) | ||
SchoolAuthScreenType.VERIFY_TOKEN -> stringResource(id = R.string.verify_token) | ||
}, | ||
style = EveryMealTypography.Body5, | ||
color = Gray100 | ||
) | ||
Spacer(modifier = Modifier.size(6.dp)) | ||
EveryMealTextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = state.emailLink, | ||
onValueChange = { | ||
viewModel.setEvent(SchoolContract.Event.OnEmailTextChanged(it)) | ||
}, | ||
supportingText = { | ||
if (state.isEmailError) { | ||
Text( | ||
text = stringResource(id = R.string.email_error), | ||
style = EveryMealTypography.Body5, | ||
color = Main100 | ||
) | ||
} | ||
} | ||
) | ||
Spacer(modifier = Modifier.weight(1f)) | ||
EveryMealMainButton( | ||
text = stringResource(id = R.string.next), | ||
onClick = { | ||
viewModel.setEvent(SchoolContract.Event.OnNextButtonClicked) | ||
}, | ||
) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
presentation/src/main/java/com/everymeal/presentation/ui/web/WebScreenContent.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,66 @@ | ||
package com.everymeal.presentation.ui.web | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import com.everymeal.presentation.R | ||
import com.google.accompanist.web.AccompanistWebChromeClient | ||
import com.google.accompanist.web.AccompanistWebViewClient | ||
import com.google.accompanist.web.WebView | ||
import com.google.accompanist.web.WebViewNavigator | ||
import com.google.accompanist.web.rememberWebViewState | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun WebScreenContent( | ||
url: String, | ||
staticTitle: String? = null, | ||
webViewNavigator: WebViewNavigator, | ||
onBackPressed: (() -> Unit)? = null, | ||
) { | ||
|
||
val webViewState = rememberWebViewState(url = url) | ||
|
||
Scaffold( | ||
topBar = { | ||
TopAppBar( | ||
title = { Text(text = staticTitle ?: (webViewState.pageTitle ?: "")) }, | ||
navigationIcon = { | ||
onBackPressed?.let { | ||
Image( | ||
modifier = Modifier.clickable { | ||
if (webViewNavigator.canGoBack) webViewNavigator.navigateBack() | ||
else onBackPressed() | ||
}, | ||
painter = painterResource(id = R.drawable.icon_arrow_back_mono), | ||
contentDescription = "back" | ||
) | ||
} | ||
} | ||
) | ||
} | ||
) { innerPadding -> | ||
WebView( | ||
state = webViewState, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(innerPadding), | ||
navigator = webViewNavigator, | ||
onCreated = { webView -> | ||
webView.settings.javaScriptEnabled = true | ||
}, | ||
client = remember { AccompanistWebViewClient() }, | ||
chromeClient = remember { AccompanistWebChromeClient() } | ||
) | ||
} | ||
|
||
} |
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