Skip to content
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

Feature/week6 essential #17

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_

initOnClickListener()
initSignUpStateObserver()
initSignUpFormsObserver()
}

private fun initOnClickListener() {
Expand All @@ -39,6 +40,16 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_
}
}

private fun initSignUpFormsObserver() {
viewModel.id.observe(this) { _ ->
viewModel.updateIsMeetCriteria()
}
viewModel.password.observe(this) { _ ->
viewModel.updateIsMeetCriteria()
viewModel.updatePasswordMeetCriteria()
}
}

private fun signUp() {
toast(SIGN_UP_SUCCEED)
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class SignUpViewModel @Inject constructor(
val password: MutableLiveData<String> = MutableLiveData()
val nickname: MutableLiveData<String> = MutableLiveData()
val mbti: MutableLiveData<String> = MutableLiveData()
private val _isPasswordMeetCriteria: MutableLiveData<Boolean> = MutableLiveData()
val isPasswordMeetCriteria: LiveData<Boolean> = _isPasswordMeetCriteria
private val _isMeetCriteria: MutableLiveData<Boolean> = MutableLiveData(false)
val isMeetCriteria: LiveData<Boolean> = _isMeetCriteria
Comment on lines +23 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν•˜λ‚˜λŠ” μ΄ˆκΈ°κ°’μ„ μ„€μ •ν•˜κ³  ν•˜λ‚˜λŠ” μ•ˆν–ˆλŠ”λ° μ–΄λ–€ κΈ°μ€€μœΌλ‘œ μ„ νƒν•˜μ‹œλŠ” κ±΄κ°€μš”??
μ €λŠ” μ „λΆ€λ‹€ μ΄ˆκΈ°κ°’ 없이 μ‚¬μš©ν•˜λŠ” 편인데 μ–΄λŠκ²Œ 더 쒋은지 κΆκΈˆν•©λ‹ˆλ‹€!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이뢀뢄 κΆκΈˆν•©λ‹ˆλ‹€!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄ˆκΈ°κ°’μ„ μ„€μ •ν•˜κ²Œ 되면 화면에 λ“€μ–΄κ°„ μˆœκ°„λΆ€ν„° 경고문이 뜨기 λ•Œλ¬Έμž…λ‹ˆλ‹€!
아무것도 μ•„λ‹Œ μƒνƒœ, μ‹€νŒ¨ν•œ μƒνƒœ, μ„±κ³΅ν•œ μƒνƒœ μ„Έ 가지가 ν•„μš”ν–ˆκΈ° λ•Œλ¬Έμ— μ΄ˆκΈ°κ°’ 섀정을 해주지 μ•Šμ•˜μŠ΅λ‹ˆλ‹€.
κ·Έλ•Œ κ·Έλ•Œ 상황에 따라 λ‹€λ₯΄κ²Œ μ„€μ •ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€ :)

private val _signUpState = MutableLiveData<Boolean>()
val signUpState: LiveData<Boolean> = _signUpState

Expand All @@ -40,33 +44,36 @@ class SignUpViewModel @Inject constructor(
}
}

fun isSignUpAvailable(): Boolean {
if (isSignUpFormsBlank()) return false
return isSignUpFormsMatch()
fun updatePasswordMeetCriteria() {
_isPasswordMeetCriteria.value = isPasswordRegexMatch()
}

private fun isSignUpFormsMatch() =
(isIdLengthSuitable() && isPassWordLengthSuitable() && isNickNameRegexMatch() && isMBTIRegexMatch() && isMbtiInEnum())
fun updateIsMeetCriteria() {
_isMeetCriteria.value = isSignUpAvailable()
}

fun isSignUpAvailable() =
(isIdRegexMatch() && isPasswordRegexMatch() && isSignUpFormsBlank() && isMbtiInEnum())

private fun isMbtiInEnum(): Boolean {
return Mbti.values().any { it.name == mbti.value }
}

private fun isSignUpFormsBlank() =
listOf(id.value, password.value, nickname.value, mbti.value).any { it.isNullOrBlank() }
private fun isSignUpFormsBlank() = !(listOf(id.value, password.value, nickname.value, mbti.value).any { it.isNullOrBlank() })

private fun isIdLengthSuitable() = id.value?.length in 6..10
private fun isPassWordLengthSuitable() = password.value?.length in 8..12
private fun isNickNameRegexMatch(): Boolean {
return nickname.value?.let { SIGNUP_REGEX.matcher(it).find() } ?: false
private fun isIdRegexMatch(): Boolean {
return id.value?.let { ID_REGEX.matcher(it).find() } ?: false
}

private fun isMBTIRegexMatch(): Boolean {
return mbti.value?.let { SIGNUP_REGEX.matcher(it).find() } ?: false
private fun isPasswordRegexMatch(): Boolean {
return password.value?.let { PASSWORD_REGEX.matcher(it).find() } ?: false
}

companion object {
private const val SIGNUP_PATTERN = """^\S+$"""
val SIGNUP_REGEX: Pattern = Pattern.compile(SIGNUP_PATTERN)
private const val ID_PATTERN = """^[a-zA-Z0-9]{6,10}${'$'}"""
private const val PASSWORD_PATTERN =
"""^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#${'$'}%^&*(),.?":{}|<>]).{6,12}${'$'}"""
val ID_REGEX: Pattern = Pattern.compile(ID_PATTERN)
val PASSWORD_REGEX: Pattern = Pattern.compile(PASSWORD_PATTERN)
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_sign_up.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:backgroundTint="@{vm.isPasswordMeetCriteria != null &amp;&amp; vm.isPasswordMeetCriteria == false ? @color/red : @color/black}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ°λ°”λ§ˆμŠ€ν„°μ΄μ‹ κ°€

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이방법이 μ°Έ 쒋은데 가독성을 λ–¨κ΅¬λŠ” 뢀문인거 κ°™μ•„μš” γ…  저도 이번 κ³Όμ œλŠ” 데바λ₯Ό ν™œμš©ν•΄μ•Ό ν•΄μ„œ μ‚¬μš©ν•˜μ˜€λŠ”λ° ν‰μ†Œμ—λ„ μ• μš©ν•˜μ‹œλ‚˜μš”?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 μ‹μœΌλ‘œ κ°’ 변경에 즉각즉각 λ°”λ€ŒλŠ” λΆ€λΆ„μ—” μ• μš©ν•˜λŠ” 것 κ°™μ•„μš”

android:hint="@string/password_hint"
android:inputType="textPassword"
android:text="@={vm.password}"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="@id/tv_sign_up_id"
app:layout_constraintTop_toBottomOf="@id/tv_sign_up_password" />

<TextView
android:id="@+id/tv_sign_up_password_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/sign_up_password_error"
android:textColor="@color/red"
android:textSize="13sp"
android:visibility="@{vm.isPasswordMeetCriteria != null &amp;&amp; vm.isPasswordMeetCriteria == false ? View.VISIBLE : View.INVISIBLE}"
app:layout_constraintStart_toStartOf="@id/tv_sign_up_id"
Comment on lines +83 to +84

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ ‡κ²Œ κ°€μ‹œμ„± μ„€μ •ν•  수 μžˆκ΅°μš”/,... μ˜€λŠ˜λ„ λ°°μ›Œκ°‘λ‹ˆλ‹€ 졜고 πŸ‘πŸ‘

app:layout_constraintTop_toBottomOf="@id/et_sign_up_password" />

<TextView
android:id="@+id/tv_sign_up_nickname"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -120,7 +133,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:backgroundTint="@{vm.isMeetCriteria == true ? @color/baby_blue : @color/gray}"
android:clickable="@{vm.isMeetCriteria == true ? true : false}"
Comment on lines +136 to +137
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backgroundTintμ—μ„œ 3ν•­ μ—°μ‚°μž ν™œμš© λ©‹μ§€λ„€μš”!!
근데 clickable은 3ν•­μ—°μ‚°μžκ°€ μ•„λ‹ˆλΌ λ°”λ‘œ vm.isMeetCriteria 써도 될것 같기도 ν•©λ‹ˆλ‹€ γ…Žγ…Ž

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

클릭은 κ·Έλƒ₯ vm.isMeetCriteria λ₯Ό μ•ˆμ“°κ³  μ €λ ‡κ²Œ ν•˜μ‹ μ΄μœ κ°€ μžˆλ‚˜μš₯>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ—†μŠ΅λ‹ˆλ‹€ γ…Ž.. λ°”κΏ€κ²Œμš”πŸ‘πŸ»

android:text="@string/sign_up_btn"
android:textColor="@color/white"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="red">#FFD1180B</color>
<color name="gray">#FFD3D3D3</color>
<color name="baby_blue">#FFA1CAF1</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<!-- sign up-->
<string name="sign_up_nickname_hint">λ‹‰λ„€μž„μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”</string>
<string name="sign_up_mbti_hint">MBTIλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”</string>
<string name="sign_up_password_error">λΉ„λ°€λ²ˆν˜ΈλŠ” 영문,숫자,특수문자λ₯Ό λͺ¨λ‘ ν¬ν•¨ν•œ 6~12κΈ€μž μ΄λ‚΄μž…λ‹ˆλ‹€.</string>

<!-- search -->
<string name="search_content">Search ν™”λ©΄μž…λ‹ˆλ‹€</string>
Expand Down