SignUp 문자열 리소스화
회원가입 검증/오류 문구를 ko/en/ja 리소스로 통합 UI 메시지 클래스를 추가해 토스트·필드 에러를 리소스 기반으로 표시
This commit is contained in:
@@ -113,17 +113,18 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(ActivitySignupBinding
|
|||||||
binding.ivPrivacyPolicy.isSelected = it
|
binding.ivPrivacyPolicy.isSelected = it
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.signUpErrorLiveData.observe(this) {
|
viewModel.signUpErrorLiveData.observe(this) { error ->
|
||||||
Toast.makeText(applicationContext, it.message, Toast.LENGTH_LONG).show()
|
val message = resolveMessage(error.message) ?: return@observe
|
||||||
|
Toast.makeText(applicationContext, message, Toast.LENGTH_LONG).show()
|
||||||
|
|
||||||
when (it.errorProperty) {
|
when (error.errorProperty) {
|
||||||
"email" -> {
|
"email" -> {
|
||||||
binding.etEmail.error = it.message
|
binding.etEmail.error = message
|
||||||
binding.etEmail.requestFocus()
|
binding.etEmail.requestFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
"password" -> {
|
"password" -> {
|
||||||
binding.etPassword.error = it.message
|
binding.etPassword.error = message
|
||||||
binding.etPassword.requestFocus()
|
binding.etPassword.requestFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,8 +138,10 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(ActivitySignupBinding
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.toastLiveData.observe(this) {
|
viewModel.toastLiveData.observe(this) { message ->
|
||||||
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
resolveMessage(message)?.let {
|
||||||
|
Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,4 +153,12 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(ActivitySignupBinding
|
|||||||
)
|
)
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resolveMessage(message: SignUpUiMessage?): String? {
|
||||||
|
return when (message) {
|
||||||
|
is SignUpUiMessage.Text -> message.value
|
||||||
|
is SignUpUiMessage.Resource -> getString(message.resId)
|
||||||
|
null -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package kr.co.vividnext.sodalive.user.signup
|
package kr.co.vividnext.sodalive.user.signup
|
||||||
|
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@@ -8,3 +9,13 @@ data class SignUpError(
|
|||||||
@SerializedName("errorProperty") val errorProperty: String,
|
@SerializedName("errorProperty") val errorProperty: String,
|
||||||
@SerializedName("message") val message: String
|
@SerializedName("message") val message: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class SignUpUiError(
|
||||||
|
val errorProperty: String,
|
||||||
|
val message: SignUpUiMessage
|
||||||
|
)
|
||||||
|
|
||||||
|
sealed class SignUpUiMessage {
|
||||||
|
data class Resource(@StringRes val resId: Int) : SignUpUiMessage()
|
||||||
|
data class Text(val value: String) : SignUpUiMessage()
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import com.orhanobut.logger.Logger
|
import com.orhanobut.logger.Logger
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import kr.co.vividnext.sodalive.R
|
||||||
import kr.co.vividnext.sodalive.base.BaseViewModel
|
import kr.co.vividnext.sodalive.base.BaseViewModel
|
||||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||||
import kr.co.vividnext.sodalive.tracking.FirebaseTracking
|
import kr.co.vividnext.sodalive.tracking.FirebaseTracking
|
||||||
@@ -23,12 +24,12 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
val isAgreePrivacyPolicyLiveData: LiveData<Boolean>
|
val isAgreePrivacyPolicyLiveData: LiveData<Boolean>
|
||||||
get() = _isAgreePrivacyPolicyLiveData
|
get() = _isAgreePrivacyPolicyLiveData
|
||||||
|
|
||||||
private val _signUpErrorLiveData = MutableLiveData<SignUpError>()
|
private val _signUpErrorLiveData = MutableLiveData<SignUpUiError>()
|
||||||
val signUpErrorLiveData: LiveData<SignUpError>
|
val signUpErrorLiveData: LiveData<SignUpUiError>
|
||||||
get() = _signUpErrorLiveData
|
get() = _signUpErrorLiveData
|
||||||
|
|
||||||
private val _toastLiveData = MutableLiveData<String?>()
|
private val _toastLiveData = MutableLiveData<SignUpUiMessage?>()
|
||||||
val toastLiveData: LiveData<String?>
|
val toastLiveData: LiveData<SignUpUiMessage?>
|
||||||
get() = _toastLiveData
|
get() = _toastLiveData
|
||||||
|
|
||||||
private var _isLoading = MutableLiveData(false)
|
private var _isLoading = MutableLiveData(false)
|
||||||
@@ -63,20 +64,33 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
onSuccess(it.message)
|
onSuccess(it.message)
|
||||||
FirebaseTracking.signUp("email")
|
FirebaseTracking.signUp("email")
|
||||||
} else {
|
} else {
|
||||||
if (it.errorProperty != null && it.message != null) {
|
when {
|
||||||
|
it.errorProperty != null && it.message != null -> {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(it.errorProperty, it.message)
|
SignUpUiError(
|
||||||
|
it.errorProperty,
|
||||||
|
SignUpUiMessage.Text(it.message)
|
||||||
)
|
)
|
||||||
} else if (it.message != null) {
|
)
|
||||||
_toastLiveData.postValue(it.message)
|
}
|
||||||
} else {
|
|
||||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
it.message != null -> {
|
||||||
|
_toastLiveData.postValue(SignUpUiMessage.Text(it.message))
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
_toastLiveData.postValue(
|
||||||
|
SignUpUiMessage.Resource(R.string.common_error_unknown)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
it.message?.let { message -> Logger.e(message) }
|
it.message?.let { message -> Logger.e(message) }
|
||||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
_toastLiveData.postValue(
|
||||||
|
SignUpUiMessage.Resource(R.string.common_error_unknown)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -85,9 +99,9 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
private fun validation(): Boolean {
|
private fun validation(): Boolean {
|
||||||
if (email.isBlank()) {
|
if (email.isBlank()) {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(
|
SignUpUiError(
|
||||||
"email",
|
"email",
|
||||||
"이메일을 입력하세요."
|
SignUpUiMessage.Resource(R.string.signup_error_email_required)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,9 +110,9 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
|
|
||||||
if (password.isBlank()) {
|
if (password.isBlank()) {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(
|
SignUpUiError(
|
||||||
"password",
|
"password",
|
||||||
"비밀번호를 입력하세요."
|
SignUpUiMessage.Resource(R.string.signup_error_password_required)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -110,9 +124,9 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
!_isAgreeTermsOfServiceLiveData.value!!
|
!_isAgreeTermsOfServiceLiveData.value!!
|
||||||
) {
|
) {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(
|
SignUpUiError(
|
||||||
"",
|
"",
|
||||||
"약관에 동의하셔야 회원가입이 가능합니다."
|
SignUpUiMessage.Resource(R.string.signup_error_terms_required)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -121,9 +135,9 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
|
|
||||||
if (!PatternsCompat.EMAIL_ADDRESS.matcher(email).matches()) {
|
if (!PatternsCompat.EMAIL_ADDRESS.matcher(email).matches()) {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(
|
SignUpUiError(
|
||||||
"email",
|
"email",
|
||||||
"올바른 이메일을 입력해 주세요"
|
SignUpUiMessage.Resource(R.string.signup_error_email_invalid)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -137,9 +151,9 @@ class SignUpViewModel(private val repository: UserRepository) : BaseViewModel()
|
|||||||
.not()
|
.not()
|
||||||
) {
|
) {
|
||||||
_signUpErrorLiveData.postValue(
|
_signUpErrorLiveData.postValue(
|
||||||
SignUpError(
|
SignUpUiError(
|
||||||
"password",
|
"password",
|
||||||
"영문, 숫자 포함 8자 이상의 비밀번호를 입력해 주세요."
|
SignUpUiMessage.Resource(R.string.signup_error_password_rule)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,11 @@
|
|||||||
<string name="terms_of_service">Terms of Service</string>
|
<string name="terms_of_service">Terms of Service</string>
|
||||||
<string name="privacy_policy">Privacy Policy</string>
|
<string name="privacy_policy">Privacy Policy</string>
|
||||||
<string name="required_label">(Required)</string>
|
<string name="required_label">(Required)</string>
|
||||||
|
<string name="signup_error_email_required">Please enter your email.</string>
|
||||||
|
<string name="signup_error_password_required">Please enter your password.</string>
|
||||||
|
<string name="signup_error_terms_required">You must agree to the terms to sign up.</string>
|
||||||
|
<string name="signup_error_email_invalid">Please enter a valid email.</string>
|
||||||
|
<string name="signup_error_password_rule">Enter at least 8 characters with letters and numbers.</string>
|
||||||
<string name="login_error_email_required">Please enter your email.</string>
|
<string name="login_error_email_required">Please enter your email.</string>
|
||||||
<string name="login_error_password_required">Please enter your password.</string>
|
<string name="login_error_password_required">Please enter your password.</string>
|
||||||
<string name="login_google_failed">Could not sign in with Google. Please try again.</string>
|
<string name="login_google_failed">Could not sign in with Google. Please try again.</string>
|
||||||
|
|||||||
@@ -67,6 +67,11 @@
|
|||||||
<string name="terms_of_service">利用規約</string>
|
<string name="terms_of_service">利用規約</string>
|
||||||
<string name="privacy_policy">個人情報の収集・利用について</string>
|
<string name="privacy_policy">個人情報の収集・利用について</string>
|
||||||
<string name="required_label">(必須)</string>
|
<string name="required_label">(必須)</string>
|
||||||
|
<string name="signup_error_email_required">メールアドレスを入力してください。</string>
|
||||||
|
<string name="signup_error_password_required">パスワードを入力してください。</string>
|
||||||
|
<string name="signup_error_terms_required">利用規約に同意すると会員登録できます。</string>
|
||||||
|
<string name="signup_error_email_invalid">正しいメールアドレスを入力してください。</string>
|
||||||
|
<string name="signup_error_password_rule">英字と数字を含む8文字以上のパスワードを入力してください。</string>
|
||||||
<string name="login_error_email_required">メールアドレスを入力してください。</string>
|
<string name="login_error_email_required">メールアドレスを入力してください。</string>
|
||||||
<string name="login_error_password_required">パスワードを入力してください。</string>
|
<string name="login_error_password_required">パスワードを入力してください。</string>
|
||||||
<string name="login_google_failed">Googleでログインできませんでした。もう一度お試しください。</string>
|
<string name="login_google_failed">Googleでログインできませんでした。もう一度お試しください。</string>
|
||||||
|
|||||||
@@ -66,6 +66,11 @@
|
|||||||
<string name="terms_of_service">이용약관</string>
|
<string name="terms_of_service">이용약관</string>
|
||||||
<string name="privacy_policy">개인정보수집 및 이용동의</string>
|
<string name="privacy_policy">개인정보수집 및 이용동의</string>
|
||||||
<string name="required_label">(필수)</string>
|
<string name="required_label">(필수)</string>
|
||||||
|
<string name="signup_error_email_required">이메일을 입력하세요.</string>
|
||||||
|
<string name="signup_error_password_required">비밀번호를 입력하세요.</string>
|
||||||
|
<string name="signup_error_terms_required">약관에 동의하셔야 회원가입이 가능합니다.</string>
|
||||||
|
<string name="signup_error_email_invalid">올바른 이메일을 입력해 주세요.</string>
|
||||||
|
<string name="signup_error_password_rule">영문, 숫자 포함 8자 이상의 비밀번호를 입력해 주세요.</string>
|
||||||
<string name="login_error_email_required">이메일을 입력하세요.</string>
|
<string name="login_error_email_required">이메일을 입력하세요.</string>
|
||||||
<string name="login_error_password_required">비밀번호를 입력하세요.</string>
|
<string name="login_error_password_required">비밀번호를 입력하세요.</string>
|
||||||
<string name="login_google_failed">구글 로그인을 하지 못했습니다. 다시 시도해 주세요</string>
|
<string name="login_google_failed">구글 로그인을 하지 못했습니다. 다시 시도해 주세요</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user