diff --git a/app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt b/app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt index d04129b..5237563 100644 --- a/app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt +++ b/app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt @@ -1,8 +1,11 @@ package org.sopt.dosopttemplate.base +import android.content.Context +import android.graphics.Rect import android.os.Bundle import android.view.MotionEvent import android.view.inputmethod.InputMethodManager +import android.widget.EditText import androidx.activity.OnBackPressedCallback import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity @@ -31,8 +34,12 @@ abstract class BaseActivity( } private fun hideKeyboard() { - val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager - inputMethodManager.hideSoftInputFromWindow(currentFocus?.windowToken, 0) + val currentFocus = currentFocus + if (currentFocus is EditText) { + currentFocus.clearFocus() + val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0) + } } private fun initPressedBackBtn() { diff --git a/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpActivity.kt b/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpActivity.kt index 7eca584..eb75d5a 100644 --- a/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpActivity.kt +++ b/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpActivity.kt @@ -2,7 +2,6 @@ package org.sopt.dosopttemplate.presentation.signUp import android.content.Intent import android.os.Bundle -import android.util.Log import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint import org.sopt.dosopttemplate.R @@ -20,10 +19,36 @@ class SignUpActivity : BaseActivity(R.layout.activity_sig super.onCreate(savedInstanceState) binding.viewModel = viewModel + initSetSignUpErrorCondition() initSignUpBtnClickListener() initObserveSignUpEnabled() } + private fun initSetSignUpErrorCondition() { + checkUserNameValid() + checkPassWordValid() + } + + private fun checkUserNameValid() { + viewModel.username.observe(this) { + if (!viewModel.isUserNameValid()) { + binding.layoutSignUpID.error = MESSAGE_USERNAME_CONDITION + } else { + binding.layoutSignUpID.error = null + } + } + } + + private fun checkPassWordValid() { + viewModel.password.observe(this) { + if (!viewModel.isPassWordValid()) { + binding.layoutSignUpPW.error = MESSAGE_PASSWORD_CONDITION + } else { + binding.layoutSignUpPW.error = null + } + } + } + private fun initSignUpBtnClickListener() { binding.btnSignUpDoSignUp.setOnClickListener { if (viewModel.isSignUpValid()) { @@ -52,5 +77,8 @@ class SignUpActivity : BaseActivity(R.layout.activity_sig companion object { const val MESSAGE_SIGNUP_SUCCESS = "회원가입 성공" const val MESSAGE_SIGNUP_FAIL = "회원가입 실패: 모든 정보를 기입해야 합니다" + + const val MESSAGE_USERNAME_CONDITION = "영문, 숫자 포함 6-10글자" + const val MESSAGE_PASSWORD_CONDITION = "영문, 숫자, 특수문자 포함 6-12글자" } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpViewModel.kt b/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpViewModel.kt index 392d558..fd5e168 100644 --- a/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpViewModel.kt +++ b/app/src/main/java/org/sopt/dosopttemplate/presentation/signUp/SignUpViewModel.kt @@ -2,12 +2,14 @@ package org.sopt.dosopttemplate.presentation.signUp import android.util.Log import androidx.lifecycle.LiveData +import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import org.sopt.dosopttemplate.data.repository.AuthRepository +import java.util.regex.Pattern import javax.inject.Inject @HiltViewModel @@ -23,6 +25,13 @@ class SignUpViewModel @Inject constructor( private val _signUpEnabled = MutableLiveData() val signUpEnabled: LiveData = _signUpEnabled + val checkBtnEnabled = MediatorLiveData().apply { + addSource(username) { value = isSignUpValid() } + addSource(nickname) { value = isSignUpValid() } + addSource(password) { value = isSignUpValid() } + addSource(mbti) { value = isSignUpValid() } + } + fun isSignUpValid(): Boolean { return isUserNameValid() && isPassWordValid() @@ -30,11 +39,15 @@ class SignUpViewModel @Inject constructor( && !mbti.value.isNullOrBlank() } - private fun isUserNameValid(): Boolean = - username.value?.length in 6..10 && !username.value.isNullOrBlank() + fun isUserNameValid(): Boolean { + val usernameMatcher = USERNAME_PATTERN.matcher(username.value.orEmpty()) + return username.value.isNullOrBlank() || usernameMatcher.find() + } - private fun isPassWordValid(): Boolean = - password.value?.length in 8..12 && !password.value.isNullOrBlank() + fun isPassWordValid(): Boolean { + val passwordMatcher = PASSWORD_PATTERN.matcher(password.value.orEmpty()) + return password.value.isNullOrBlank() || passwordMatcher.find() + } fun doSignUp( username: String, @@ -55,4 +68,11 @@ class SignUpViewModel @Inject constructor( } } } + + companion object { + const val USERNAME_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z]).{6,10}\$" + const val PASSWORD_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^+\\-=]).{6,12}\$" + val USERNAME_PATTERN: Pattern = Pattern.compile(USERNAME_REGEX) + val PASSWORD_PATTERN: Pattern = Pattern.compile(PASSWORD_REGEX) + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/rect_storage_btn_active.xml b/app/src/main/res/drawable/rect_storage_btn_active.xml new file mode 100644 index 0000000..950b7df --- /dev/null +++ b/app/src/main/res/drawable/rect_storage_btn_active.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rect_storage_btn_inactive.xml b/app/src/main/res/drawable/rect_storage_btn_inactive.xml new file mode 100644 index 0000000..32cce45 --- /dev/null +++ b/app/src/main/res/drawable/rect_storage_btn_inactive.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index a692822..fda319d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -52,7 +52,7 @@ app:counterEnabled="true" app:counterMaxLength="10" app:endIconMode="clear_text" - app:endIconTint="@color/secondary_1"> + app:endIconTint="@color/gray_2"> -