diff --git a/app/src/main/java/org/android/go/sopt/present/loginPage/SignUpActivity.kt b/app/src/main/java/org/android/go/sopt/present/loginPage/SignUpActivity.kt
index ce27db7..bda332d 100644
--- a/app/src/main/java/org/android/go/sopt/present/loginPage/SignUpActivity.kt
+++ b/app/src/main/java/org/android/go/sopt/present/loginPage/SignUpActivity.kt
@@ -1,14 +1,17 @@
package org.android.go.sopt.present.loginPage
import android.content.Intent
+import android.content.res.ColorStateList
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.view.MotionEvent
+import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import com.google.android.material.snackbar.Snackbar
import org.android.go.sopt.MainActivity
+import org.android.go.sopt.R
import org.android.go.sopt.RequestSignUpDto
import org.android.go.sopt.ResponseSignUpDto
import org.android.go.sopt.databinding.ActivitySignupBinding
@@ -18,6 +21,7 @@ import org.android.go.sopt.util.hideKeyboard
import org.android.go.sopt.util.makeToastMessage
import retrofit2.Call
import retrofit2.Response
+import java.util.regex.Pattern
import android.text.TextWatcher as TextWatcher
@@ -49,7 +53,7 @@ class SignUpActivity : AppCompatActivity() {
canClickButton()
binding.btnSignup.setOnClickListener {
if (binding.etId.text.length in 6..10 && binding.etPassword.text.length in 8..12) {
- with(binding){
+ with(binding) {
viewModel.signUp(
etId.text.toString(),
etPassword.text.toString(),
@@ -58,7 +62,7 @@ class SignUpActivity : AppCompatActivity() {
)
}
- viewModel.signUpResult.observe(this){
+ viewModel.signUpResult.observe(this) {
makeToastMessage("회원가입 성공")
val intent = Intent(this@SignUpActivity, LoginActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -79,27 +83,76 @@ class SignUpActivity : AppCompatActivity() {
private fun canClickButton() {
+ var correctId: Boolean = false
+ var correctPw: Boolean = false
+
with(binding) {
btnSignup.isEnabled = false
- val textWatcher: TextWatcher = object : TextWatcher {
+ etId.addTextChangedListener(object : TextWatcher {
+
+ val idPattern = "^(?=.*\\d)(?=.*[a-zA-Z]).{6,10}\$"
+
+
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
+
+
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
- if (etId.text.length in 6..10 && etPassword.text.length in 8..12) {
+
+ correctId = Pattern.matches(idPattern, etId.text)
+ if (!correctId) {
+ tvIdWarn.visibility = View.VISIBLE
+ correctId = false
+ etId.backgroundTintList = ColorStateList.valueOf(getColor(R.color.red_500))
+ } else {
+ tvIdWarn.visibility = View.GONE
+ correctId = true
+ etId.backgroundTintList = ColorStateList.valueOf(getColor(R.color.black))
+ }
+
+ }
+
+ override fun afterTextChanged(p0: Editable?) {
+ if (correctId && correctPw) {
btnSignup.isEnabled = true
}
}
+ })
+ etPassword.addTextChangedListener(object : TextWatcher {
+
+ val pwPattern = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[\$@\$!%*#?&]).{8,15}.\$"
+
+
+
+ override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
+
+ }
+
+ override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
+ correctPw = Pattern.matches(pwPattern, etPassword.text)
+ if (!correctPw) {
+ tvPwWarn.visibility = View.VISIBLE
+ correctPw = false
+ etPassword.backgroundTintList =
+ ColorStateList.valueOf(getColor(R.color.red_500))
+ } else {
+ tvPwWarn.visibility = View.GONE
+ correctPw = true
+ etPassword.backgroundTintList =
+ ColorStateList.valueOf(getColor(R.color.black))
+ }
+ }
+
override fun afterTextChanged(p0: Editable?) {
+ if (correctId && correctPw) {
+ btnSignup.isEnabled = true
+ }
}
- }
- etId.addTextChangedListener(textWatcher)
- etPassword.addTextChangedListener(textWatcher)
- etName.addTextChangedListener(textWatcher)
- etSpeciality.addTextChangedListener(textWatcher)
+ })
}
diff --git a/app/src/main/res/layout/activity_signup.xml b/app/src/main/res/layout/activity_signup.xml
index 4f757a1..b3768e1 100644
--- a/app/src/main/res/layout/activity_signup.xml
+++ b/app/src/main/res/layout/activity_signup.xml
@@ -42,6 +42,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_id" />
+
+
+
+
+