FindPassword 문자열 리소스화
비밀번호 재설정 안내/버튼/토스트를 ko/en/ja 리소스로 추가 UI 메시지 클래스로 리소스 기반 토스트 처리
This commit is contained in:
@@ -7,6 +7,7 @@ import android.widget.Toast
|
||||
import com.jakewharton.rxbinding4.widget.textChanges
|
||||
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.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityFindPasswordBinding
|
||||
@@ -27,7 +28,7 @@ class FindPasswordActivity : BaseActivity<ActivityFindPasswordBinding>(
|
||||
|
||||
override fun setupView() {
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
binding.toolbar.tvBack.text = "비밀번호 재설정"
|
||||
binding.toolbar.tvBack.text = getString(R.string.title_find_password)
|
||||
binding.toolbar.tvBack.setOnClickListener { finish() }
|
||||
|
||||
binding.tvServiceCenter.setOnClickListener {
|
||||
@@ -52,8 +53,13 @@ class FindPasswordActivity : BaseActivity<ActivityFindPasswordBinding>(
|
||||
}
|
||||
)
|
||||
|
||||
viewModel.toastLiveData.observe(this) {
|
||||
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
||||
viewModel.toastLiveData.observe(this) { message ->
|
||||
val text = when (message) {
|
||||
is FindPasswordUiMessage.Text -> message.value
|
||||
is FindPasswordUiMessage.Resource -> getString(message.resId)
|
||||
null -> null
|
||||
}
|
||||
text?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
||||
viewModel.isLoading.observe(this) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package kr.co.vividnext.sodalive.user.find_password
|
||||
|
||||
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.user.UserRepository
|
||||
|
||||
@@ -16,13 +18,15 @@ class FindPasswordViewModel(private val repository: UserRepository) : BaseViewMo
|
||||
val isLoading: LiveData<Boolean>
|
||||
get() = _isLoading
|
||||
|
||||
private val _toastLiveData = MutableLiveData<String?>()
|
||||
val toastLiveData: LiveData<String?>
|
||||
private val _toastLiveData = MutableLiveData<FindPasswordUiMessage?>()
|
||||
val toastLiveData: LiveData<FindPasswordUiMessage?>
|
||||
get() = _toastLiveData
|
||||
|
||||
fun findPassword(onSuccess: () -> Unit) {
|
||||
if (email.isBlank()) {
|
||||
_toastLiveData.postValue("이메일을 입력하세요.")
|
||||
_toastLiveData.postValue(
|
||||
FindPasswordUiMessage.Resource(R.string.login_error_email_required)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,25 +41,30 @@ class FindPasswordViewModel(private val repository: UserRepository) : BaseViewMo
|
||||
_isLoading.value = false
|
||||
if (it.success) {
|
||||
_toastLiveData.postValue(
|
||||
"임시 비밀번호가 입력하신 이메일로 발송되었습니다. 이메일을 확인해 주세요."
|
||||
FindPasswordUiMessage.Resource(R.string.find_password_success)
|
||||
)
|
||||
onSuccess()
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
_toastLiveData.postValue(
|
||||
it.message?.let { message ->
|
||||
FindPasswordUiMessage.Text(message)
|
||||
} ?: FindPasswordUiMessage.Resource(R.string.common_error_unknown)
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
_toastLiveData.postValue(
|
||||
FindPasswordUiMessage.Resource(R.string.common_error_unknown)
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class FindPasswordUiMessage {
|
||||
data class Resource(@StringRes val resId: Int) : FindPasswordUiMessage()
|
||||
data class Text(val value: String) : FindPasswordUiMessage()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user