Skip to content

Commit

Permalink
[Feature/#9] 조건 미충족시 경고문구 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeun5744 committed Jun 28, 2023
1 parent 6dbc0f5 commit 82149f5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.android.go.sopt.present.loginPage

import android.content.Intent
import android.content.res.ColorStateList
import android.os.Bundle
import android.text.Editable
import android.view.MotionEvent
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.viewModels
import org.android.go.sopt.MainActivity
import org.android.go.sopt.R
import org.android.go.sopt.RequestSignUpDto
import org.android.go.sopt.databinding.ActivitySignupBinding
import org.android.go.sopt.present.viewModel.LoginPageViewModel
import org.android.go.sopt.util.ViewModelFactory
import org.android.go.sopt.util.hideKeyboard
import org.android.go.sopt.util.makeToastMessage
import java.util.regex.Pattern
import android.text.TextWatcher as TextWatcher

class SignUpActivity : AppCompatActivity() {
Expand Down Expand Up @@ -76,27 +79,66 @@ 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) {
btnSignup.isEnabled = true
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}.\$"

etId.addTextChangedListener(textWatcher)
etPassword.addTextChangedListener(textWatcher)
etName.addTextChangedListener(textWatcher)
etSpeciality.addTextChangedListener(textWatcher)
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
}
}
})
}
}
}
14 changes: 7 additions & 7 deletions app/src/main/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@
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:textColor="@color/red_500"
android:textSize="8sp"
android:visibility="invisible"
android:textColor="@color/red_500"/>

app:layout_constraintStart_toStartOf="@id/et_id"
app:layout_constraintTop_toBottomOf="@id/et_id" />


<TextView
Expand Down Expand Up @@ -83,11 +82,12 @@
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:textColor="@color/red_500"
android:textSize="8sp"
android:visibility="invisible"
android:textColor="@color/red_500"/>
app:layout_constraintStart_toStartOf="@id/et_password"
app:layout_constraintTop_toBottomOf="@id/et_password" />


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

0 comments on commit 82149f5

Please sign in to comment.