Skip to content

Commit

Permalink
[Refactor] string 리소스 추가, toast message 함수 수정 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed May 23, 2024
1 parent 680a8b1 commit 1cbb5e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app/src/main/java/com/sopt/now/ui/signUp/SignUpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.sopt.now.R
import com.sopt.now.data.model.RequestSignUpDto
import com.sopt.now.databinding.ActivitySignUpBinding
import com.sopt.now.ui.signUp.viewModel.SignUpViewModel
Expand Down Expand Up @@ -41,7 +42,7 @@ class SignUpActivity : AppCompatActivity() {
binding.btnSignUp.setOnClickListener {
when {
isInputValid() -> viewModel.signUp(getSignUpRequestDto())
else -> showToastMessage("모든 정보를 입력해주세요.")
else -> showToastMessage(R.string.toast_sign_up_fail)
}
}
}
Expand All @@ -51,7 +52,6 @@ class SignUpActivity : AppCompatActivity() {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.signUpState.collect { signUpState ->
if (signUpState.message.isNotBlank()) {
showToastMessage(signUpState.message)
if (signUpState.isSuccess) {
handleValidInput()
}
Expand Down Expand Up @@ -86,9 +86,6 @@ class SignUpActivity : AppCompatActivity() {
private fun isPwValid(): Boolean {
val pwText = binding.edtSignUpPw.text.toString()
return pwText.isNotBlank() && pwText.length >= MIN_LENGTH_PASSWORD
&& Regex("^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[\$@!%*#?&.])[A-Za-z[0-9]\$@!%*#?&.]{8,20}\$").matches(
pwText
)
}

private fun isNicknameValid(): Boolean {
Expand All @@ -98,15 +95,15 @@ class SignUpActivity : AppCompatActivity() {

private fun isPhoneNumberValid(): Boolean {
val phoneNumberText = binding.edtSignUpPhoneNumber.text.toString()
return phoneNumberText.isNotBlank() && Regex("^010-\\d{4}-\\d{4}\$").matches(phoneNumberText)
return phoneNumberText.isNotBlank()
}

private fun handleValidInput() {
showToastMessage("회원가입이 완료되었습니다.")
showToastMessage(R.string.toast_sign_up_success)
finish()
}

private fun showToastMessage(text: String) {
private fun showToastMessage(text: Int) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<string name="home_friend_name">이름</string>
<string name="home_friend_description">소개</string>

<!-- toast message-->
<string name="toast_sign_up_fail">모든 정보를 입력해주세요.</string>
<string name="toast_sign_up_success">회원가입이 완료되었습니다.</string>
</resources>

0 comments on commit 1cbb5e0

Please sign in to comment.