Skip to content

Commit

Permalink
[Feature/#9] 조건 미충족시 경고문구 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Jun 2, 2023
1 parent 4ee8105 commit 5e03e88
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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(),
Expand All @@ -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)
Expand All @@ -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)
})


}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_id" />

<TextView
android:id="@+id/tv_id_warn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID 조건: 영문, 숫자가 포함되어야 하고 6~10글자 이내"
app:layout_constraintTop_toBottomOf="@id/et_id"
app:layout_constraintStart_toStartOf="@id/et_id"
android:textSize="8sp"
android:visibility="invisible"
android:textColor="@color/red_500"/>



<TextView
android:id="@+id/tv_password"
Expand All @@ -66,6 +78,17 @@
app:layout_constraintStart_toStartOf="@id/et_id"
app:layout_constraintTop_toBottomOf="@id/tv_password" />

<TextView
android:id="@+id/tv_pw_warn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password 조건: 영문, 숫자, 특수문자가 포함되어야 하고 6~12글자 이내"
app:layout_constraintTop_toBottomOf="@id/et_password"
app:layout_constraintStart_toStartOf="@id/et_password"
android:textSize="8sp"
android:visibility="invisible"
android:textColor="@color/red_500"/>

<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
Expand Down

0 comments on commit 5e03e88

Please sign in to comment.