Login 입력 오류 문구 리소스화

이메일·비밀번호 미입력 안내를 ko/en/ja 리소스로 추가

토스트 메시지를 리소스 기반 메시지 클래스로 전달
This commit is contained in:
2025-12-01 13:56:14 +09:00
parent 4d1e859bbf
commit 7e74bd1e4d
5 changed files with 46 additions and 30 deletions

View File

@@ -190,8 +190,13 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>(ActivityLoginBinding::i
}
)
viewModel.toastLiveData.observe(this) {
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
viewModel.toastLiveData.observe(this) { message ->
val text = when (message) {
is LoginUiMessage.Text -> message.value
is LoginUiMessage.Resource -> getString(message.resId)
null -> null
}
text?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
}
viewModel.isLoading.observe(this) {

View File

@@ -1,10 +1,12 @@
package kr.co.vividnext.sodalive.user.login
import androidx.annotation.StringRes
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.orhanobut.logger.Logger
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.user.UserRepository
@@ -14,8 +16,8 @@ class LoginViewModel(private val repository: UserRepository) : BaseViewModel() {
var email = ""
var password = ""
private val _toastLiveData = MutableLiveData<String?>()
val toastLiveData: LiveData<String?>
private val _toastLiveData = MutableLiveData<LoginUiMessage?>()
val toastLiveData: LiveData<LoginUiMessage?>
get() = _toastLiveData
private var _isLoading = MutableLiveData(false)
@@ -45,20 +47,18 @@ class LoginViewModel(private val repository: UserRepository) : BaseViewModel() {
SharedPreferenceManager.nickname = it.data.nickname
SharedPreferenceManager.profileImage = it.data.profileImage
onSuccess()
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
it.message?.let { message ->
LoginUiMessage.Text(message)
} ?: LoginUiMessage.Resource(R.string.common_error_unknown)
)
}
}
},
{
_isLoading.value = false
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
_toastLiveData.postValue(LoginUiMessage.Resource(R.string.common_error_unknown))
}
)
)
@@ -87,20 +87,18 @@ class LoginViewModel(private val repository: UserRepository) : BaseViewModel() {
SharedPreferenceManager.nickname = it.data.nickname
SharedPreferenceManager.profileImage = it.data.profileImage
onSuccess()
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
it.message?.let { message ->
LoginUiMessage.Text(message)
} ?: LoginUiMessage.Resource(R.string.common_error_unknown)
)
}
}
},
{
_isLoading.value = false
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
_toastLiveData.postValue(LoginUiMessage.Resource(R.string.common_error_unknown))
}
)
)
@@ -108,12 +106,16 @@ class LoginViewModel(private val repository: UserRepository) : BaseViewModel() {
fun login(onSuccess: (String?) -> Unit) {
if (email.isBlank()) {
_toastLiveData.postValue("이메일을 입력하세요.")
_toastLiveData.postValue(
LoginUiMessage.Resource(R.string.login_error_email_required)
)
return
}
if (password.isBlank()) {
_toastLiveData.postValue("비밃번호를 입력하세요.")
_toastLiveData.postValue(
LoginUiMessage.Resource(R.string.login_error_password_required)
)
return
}
@@ -133,22 +135,25 @@ class LoginViewModel(private val repository: UserRepository) : BaseViewModel() {
SharedPreferenceManager.nickname = it.data.nickname
SharedPreferenceManager.profileImage = it.data.profileImage
onSuccess(it.message)
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
it.message?.let { message ->
LoginUiMessage.Text(message)
} ?: LoginUiMessage.Resource(R.string.common_error_unknown)
)
}
}
},
{
_isLoading.value = false
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
_toastLiveData.postValue(LoginUiMessage.Resource(R.string.common_error_unknown))
}
)
)
}
}
sealed class LoginUiMessage {
data class Resource(@StringRes val resId: Int) : LoginUiMessage()
data class Text(val value: String) : LoginUiMessage()
}

View File

@@ -67,6 +67,8 @@
<string name="terms_of_service">Terms of Service</string>
<string name="privacy_policy">Privacy Policy</string>
<string name="required_label">(Required)</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_google_failed">Could not sign in with Google. Please try again.</string>
<string name="login_failed">Could not sign in. Please try again.</string>
<string name="login_kakao_failed">Could not sign in with Kakao. Please try again.</string>

View File

@@ -67,6 +67,8 @@
<string name="terms_of_service">利用規約</string>
<string name="privacy_policy">個人情報の収集・利用について</string>
<string name="required_label">(必須)</string>
<string name="login_error_email_required">メールアドレスを入力してください。</string>
<string name="login_error_password_required">パスワードを入力してください。</string>
<string name="login_google_failed">Googleでログインできませんでした。もう一度お試しください。</string>
<string name="login_failed">ログインできませんでした。もう一度お試しください。</string>
<string name="login_kakao_failed">Kakaoアカウントでログインできませんでした。もう一度お試しください。</string>

View File

@@ -66,6 +66,8 @@
<string name="terms_of_service">이용약관</string>
<string name="privacy_policy">개인정보수집 및 이용동의</string>
<string name="required_label">(필수)</string>
<string name="login_error_email_required">이메일을 입력하세요.</string>
<string name="login_error_password_required">비밀번호를 입력하세요.</string>
<string name="login_google_failed">구글 로그인을 하지 못했습니다. 다시 시도해 주세요</string>
<string name="login_failed">로그인을 하지 못했습니다. 다시 시도해 주세요</string>
<string name="login_kakao_failed">카카오 계정으로 로그인 하지 못했습니다. 다시 시도해 주세요</string>