-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT/seminar6] 필수과제 #13
base: develop
Are you sure you want to change the base?
Changes from all commits
daceca8
ee87c03
ec02747
536fbd3
8d66e74
725efa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package org.sopt.dosopttemplate.presentation.signUp | |
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.viewModels | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import org.sopt.dosopttemplate.R | ||
|
@@ -20,10 +19,36 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig | |
super.onCreate(savedInstanceState) | ||
binding.viewModel = viewModel | ||
|
||
initSetSignUpErrorCondition() | ||
initSignUpBtnClickListener() | ||
initObserveSignUpEnabled() | ||
} | ||
|
||
private fun initSetSignUpErrorCondition() { | ||
checkUserNameValid() | ||
checkPassWordValid() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 함수를 또 묶어서 사용하는 건 생각도 못하고 따로 따로 함수만 만들어놨는데..! 저도 한 번 이렇게 해봐야겠어용!! |
||
private fun checkUserNameValid() { | ||
viewModel.username.observe(this) { | ||
if (!viewModel.isUserNameValid()) { | ||
binding.layoutSignUpID.error = MESSAGE_USERNAME_CONDITION | ||
} else { | ||
binding.layoutSignUpID.error = null | ||
} | ||
} | ||
} | ||
|
||
private fun checkPassWordValid() { | ||
viewModel.password.observe(this) { | ||
if (!viewModel.isPassWordValid()) { | ||
binding.layoutSignUpPW.error = MESSAGE_PASSWORD_CONDITION | ||
} else { | ||
binding.layoutSignUpPW.error = null | ||
} | ||
} | ||
} | ||
|
||
private fun initSignUpBtnClickListener() { | ||
binding.btnSignUpDoSignUp.setOnClickListener { | ||
if (viewModel.isSignUpValid()) { | ||
|
@@ -52,5 +77,8 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig | |
companion object { | ||
const val MESSAGE_SIGNUP_SUCCESS = "회원가입 성공" | ||
const val MESSAGE_SIGNUP_FAIL = "회원가입 실패: 모든 정보를 기입해야 합니다" | ||
|
||
const val MESSAGE_USERNAME_CONDITION = "영문, 숫자 포함 6-10글자" | ||
const val MESSAGE_PASSWORD_CONDITION = "영문, 숫자, 특수문자 포함 6-12글자" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ package org.sopt.dosopttemplate.presentation.signUp | |
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MediatorLiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import org.sopt.dosopttemplate.data.repository.AuthRepository | ||
import java.util.regex.Pattern | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
|
@@ -23,18 +25,29 @@ class SignUpViewModel @Inject constructor( | |
private val _signUpEnabled = MutableLiveData<Boolean>() | ||
val signUpEnabled: LiveData<Boolean> = _signUpEnabled | ||
|
||
val checkBtnEnabled = MediatorLiveData<Boolean>().apply { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MediatorLiveData 는 처음 보네요.. 여러 개의 LiveData를 결합해서 관리한다... 좋은 정보 얻고갑니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MediatorLiveData 사용 너무 좋아요~!! |
||
addSource(username) { value = isSignUpValid() } | ||
addSource(nickname) { value = isSignUpValid() } | ||
addSource(password) { value = isSignUpValid() } | ||
addSource(mbti) { value = isSignUpValid() } | ||
} | ||
|
||
fun isSignUpValid(): Boolean { | ||
return isUserNameValid() | ||
&& isPassWordValid() | ||
&& !nickname.value.isNullOrBlank() | ||
&& !mbti.value.isNullOrBlank() | ||
} | ||
|
||
private fun isUserNameValid(): Boolean = | ||
username.value?.length in 6..10 && !username.value.isNullOrBlank() | ||
fun isUserNameValid(): Boolean { | ||
val usernameMatcher = USERNAME_PATTERN.matcher(username.value.orEmpty()) | ||
return username.value.isNullOrBlank() || usernameMatcher.find() | ||
} | ||
|
||
private fun isPassWordValid(): Boolean = | ||
password.value?.length in 8..12 && !password.value.isNullOrBlank() | ||
fun isPassWordValid(): Boolean { | ||
val passwordMatcher = PASSWORD_PATTERN.matcher(password.value.orEmpty()) | ||
return password.value.isNullOrBlank() || passwordMatcher.find() | ||
} | ||
|
||
fun doSignUp( | ||
username: String, | ||
|
@@ -55,4 +68,11 @@ class SignUpViewModel @Inject constructor( | |
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val USERNAME_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z]).{6,10}\$" | ||
const val PASSWORD_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^+\\-=]).{6,12}\$" | ||
val USERNAME_PATTERN: Pattern = Pattern.compile(USERNAME_REGEX) | ||
val PASSWORD_PATTERN: Pattern = Pattern.compile(PASSWORD_REGEX) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<solid android:color="@color/blue_5"/> | ||
<corners android:radius="5dp"/> | ||
</shape> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<solid android:color="@color/gray_2"/> | ||
<corners android:radius="5dp"/> | ||
</shape> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 👍