Skip to content

Commit

Permalink
#86 fix : 기본 회원가입 이메일 관련 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
BENDENG1 committed Dec 13, 2023
1 parent 7493fd5 commit 1bd3429
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.avengers.nibobnebob.presentation.util.Constants.FILTER_NEW
import com.avengers.nibobnebob.presentation.util.Constants.FILTER_OLD
import com.avengers.nibobnebob.presentation.util.Constants.FILTER_WORST
import com.avengers.nibobnebob.presentation.util.LoginType
import com.google.android.material.textfield.TextInputLayout

// signup
@BindingAdapter("helperMessage")
Expand All @@ -38,6 +37,24 @@ fun bindHelpMessage(tv: TextView, inputState: InputState) = with(tv) {
}
}

//signup
@BindingAdapter("emailValidation")
fun bindEmailValidationr(tv: TextView, inputState: InputState) = with(tv) {
when (inputState) {
is InputState.Success -> {
setTextColor(ContextCompat.getColor(context, R.color.nn_dark6))
}

is InputState.Error -> {
setTextColor(ContextCompat.getColor(context, R.color.nn_dark6))
}

is InputState.Empty -> {
setTextColor(ContextCompat.getColor(context, R.color.nn_dark2))
}
}
}

@SuppressLint("SetTextI18n")
@BindingAdapter("textLength", "textLimit")
fun bindTextLength(tv: TextView, text: String, limit: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ data class BasicSignupUiState(
val isEmailNotEmpty: Boolean = true
)

sealed class BasicSignupEvents{
sealed class BasicSignupEvents {
data object NavigateToBack : BasicSignupEvents()
data class NavigateToDetailSignup(
val provider: String,
val email: String,
val password: String,
) : BasicSignupEvents()
data class ShowSnackMessage(val msg: String): BasicSignupEvents()

data class ShowSnackMessage(val msg: String) : BasicSignupEvents()
}

@HiltViewModel
class BasicSignupViewModel @Inject constructor(
private val getEmailValidationUseCase: GetEmailValidationUseCase
) : ViewModel(){
) : ViewModel() {

private val _uiState = MutableStateFlow(BasicSignupUiState())
val uiState: StateFlow<BasicSignupUiState> = _uiState.asStateFlow()
Expand All @@ -54,29 +55,38 @@ class BasicSignupViewModel @Inject constructor(
private val emailValidation = MutableStateFlow(false)
private val passwordValidation = MutableStateFlow(false)

val isDataReady = combine(emailValidation, passwordValidation){ emailValidation, passwordValidation ->
emailValidation && passwordValidation
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(),
false
)
val isDataReady =
combine(emailValidation, passwordValidation) { emailValidation, passwordValidation ->
emailValidation && passwordValidation
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(),
false
)

init{
init {
observeEmail()
observePasswordCheck()
}

private fun observeEmail(){
private fun observeEmail() {
email.onEach {
if(ValidationUtil.checkEmail(it)){
if (ValidationUtil.checkEmail(it)) {
_uiState.update { state ->
emailValidation.value = false
state.copy(
isEmailNotEmpty = it.isNotBlank(),
emailState = InputState.Empty
)
}
} else if (it.isEmpty()) {
_uiState.update { state ->
emailValidation.value = false
state.copy(
isEmailNotEmpty = false,
emailState = InputState.Error("이메일을 입력해주세요.")
)
}
} else {
_uiState.update { state ->
emailValidation.value = false
Expand All @@ -89,11 +99,11 @@ class BasicSignupViewModel @Inject constructor(
}.launchIn(viewModelScope)
}

private fun observePasswordCheck(){
private fun observePasswordCheck() {

password.onEach {
if(it.isNotBlank()){
if(it == passwordCheck.value){
if (it.isNotBlank()) {
if (it == passwordCheck.value) {
passwordValidation.value = true
_uiState.update { state ->
state.copy(
Expand All @@ -112,8 +122,8 @@ class BasicSignupViewModel @Inject constructor(
}.launchIn(viewModelScope)

passwordCheck.onEach {
if(it.isNotBlank()){
if(it == password.value){
if (it.isNotBlank()) {
if (it == password.value) {
passwordValidation.value = true
_uiState.update { state ->
state.copy(
Expand All @@ -132,11 +142,11 @@ class BasicSignupViewModel @Inject constructor(
}.launchIn(viewModelScope)
}

fun checkEmail(){
fun checkEmail() {
getEmailValidationUseCase(email.value).onEach {
when(it){
when (it) {
is BaseState.Success -> {
if(it.data.isExist){
if (it.data.isExist) {
emailValidation.value = false
_uiState.update { state ->
state.copy(
Expand All @@ -152,6 +162,7 @@ class BasicSignupViewModel @Inject constructor(
}
}
}

is BaseState.Error -> {
emailValidation.value = false
_events.emit(BasicSignupEvents.ShowSnackMessage(it.message))
Expand All @@ -160,19 +171,21 @@ class BasicSignupViewModel @Inject constructor(
}.launchIn(viewModelScope)
}

fun navigateToBack(){
fun navigateToBack() {
viewModelScope.launch {
_events.emit(BasicSignupEvents.NavigateToBack)
}
}

fun navigateToDetailSignup(){
fun navigateToDetailSignup() {
viewModelScope.launch {
_events.emit(BasicSignupEvents.NavigateToDetailSignup(
provider = "site",
email = email.value,
password = password.value,
))
_events.emit(
BasicSignupEvents.NavigateToDetailSignup(
provider = "site",
email = email.value,
password = password.value,
)
)
}
}
}
21 changes: 10 additions & 11 deletions Aos/app/src/main/res/layout/fragment_basic_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="기본 정보 입력"
android:text="@string/input_basic_information"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_back"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -56,7 +56,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="이메일"
android:text="@string/email"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_toolbar" />

Expand All @@ -76,7 +76,7 @@
style="@style/TextSmallRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="이메일"
android:hint="@string/email"
android:text="@={vm.email}" />

</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -95,16 +95,15 @@

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_email_duplication_check"
style="@style/TextSmallBold"
style="@style/TextMediumBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:enabled="@{vm.uiState.isEmailNotEmpty}"
android:minHeight="0dp"
android:onClick="@{() -> vm.checkEmail()}"
android:text="이메일 중복확인"
android:textColor="@color/selector_nick_check_text"
app:layout_constraintBottom_toBottomOf="@id/tv_email_helper_text"
android:text="@string/check_email_duplicate"
app:emailValidation="@{vm.uiState.emailState}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_email_helper_text" />

Expand All @@ -114,7 +113,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="비밀번호"
android:text="@string/password"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_email_helper_text" />

Expand All @@ -133,7 +132,7 @@
style="@style/TextSmallRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="비밀번호"
android:hint="@string/password"
android:inputType="textPassword"
android:text="@={vm.password}" />

Expand All @@ -155,7 +154,7 @@
style="@style/TextSmallRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="비밀번호 확인"
android:hint="@string/check_password"
android:inputType="textPassword"
android:text="@={vm.passwordCheck}" />

Expand Down Expand Up @@ -183,7 +182,7 @@
android:background="@drawable/selector_next_btn"
android:enabled="@{vm.isDataReady()}"
android:onClick="@{() -> vm.navigateToDetailSignup()}"
android:text="다음"
android:text="@string/next"
android:textColor="@color/selector_next_btn_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
4 changes: 4 additions & 0 deletions Aos/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<string name="phone_number_empty">전화번호 없음</string>
<string name="no_recommend_restaurant">\n\n추천드릴 음식점이 존재하지 않습니다.\n\n</string>
<string name="add_photo_option">(선택) 사진 등록</string>
<string name="check_email_duplicate">이메일 중복확인</string>
<string name="next">다음</string>
<string name="input_basic_information">기본 정보 입력</string>
<string name="check_password">비밀번호 확인</string>

<string-array name="location_list">
<item>강남구</item>
Expand Down

0 comments on commit 1bd3429

Please sign in to comment.