-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6주차 과제] 서버 통신 심화 #11
Changes from 15 commits
2e8058d
2248aa7
b266e26
592554e
5a84a35
d39751d
ff461d7
21eee1e
2e98d37
d74edf4
12250ef
f2514b9
f3e888c
3388720
74238bf
e300307
2283def
fc2aa58
d1a9608
31eb6f0
f6389f1
d5d77e8
d9051c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.android.go.sopt.presentation.main.mypage | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import org.android.go.sopt.data.entity.User | ||
import org.android.go.sopt.util.PreferenceManager | ||
|
||
class MyPageViewModel : ViewModel() { | ||
private val preferenceManager = PreferenceManager() | ||
private val _signedUpUser = MutableLiveData<User>() | ||
val signedUpUser: User? | ||
get() = _signedUpUser.value | ||
|
||
init { | ||
getSignedUpUser() | ||
} | ||
|
||
private fun getSignedUpUser() { | ||
_signedUpUser.value = preferenceManager.signedUpUser | ||
} | ||
|
||
fun logout() { | ||
preferenceManager.loginState = false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,13 @@ package org.android.go.sopt.presentation.signup | |
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import androidx.core.widget.addTextChangedListener | ||
import org.android.go.sopt.R | ||
import org.android.go.sopt.util.binding.BindingActivity | ||
import org.android.go.sopt.databinding.ActivitySignUpBinding | ||
import org.android.go.sopt.presentation.login.LoginActivity | ||
import org.android.go.sopt.util.code.CODE_DUPLICATED_ID | ||
import org.android.go.sopt.util.code.CODE_INCORRECT_INPUT | ||
import org.android.go.sopt.util.code.CODE_INVALID_INPUT | ||
import org.android.go.sopt.util.extension.hideKeyboard | ||
import org.android.go.sopt.util.extension.showSnackbar | ||
|
@@ -24,10 +22,60 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_ | |
binding.vm = viewModel | ||
|
||
initRootLayoutClickListener() | ||
initEditTextChangedListeners() | ||
initEditTextChangedListener() | ||
initSignUpStateObserver() | ||
} | ||
|
||
private fun initEditTextChangedListener() { | ||
binding.etId.addTextChangedListener { | ||
if (!viewModel.isValidId()) { | ||
binding.tilId.error = getString(R.string.sign_up_id_helper_text) | ||
deactivateSignUpButton() | ||
} else { | ||
binding.tilId.error = null | ||
if (viewModel.isValidInput()) activateSignUpButton() | ||
} | ||
} | ||
|
||
binding.etPw.addTextChangedListener { | ||
if (!viewModel.isValidPw()) { | ||
binding.tilPw.error = getString(R.string.sign_up_pw_helper_text) | ||
deactivateSignUpButton() | ||
} else { | ||
binding.tilPw.error = null | ||
if (viewModel.isValidInput()) activateSignUpButton() | ||
} | ||
} | ||
|
||
binding.etName.addTextChangedListener { | ||
if (viewModel.isNotBlankName()) { | ||
binding.tilName.error = null | ||
if (viewModel.isValidInput()) activateSignUpButton() | ||
} else { | ||
binding.tilName.error = getString(R.string.sign_up_required_input_err) | ||
deactivateSignUpButton() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TextChangedListener를 설정할 때 유사한 로직이 반복되고 있는데, InputEditText와 Boolean 타입의 조건을 인자로 받는 함수를 만들어 사용할 수도 있을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 한개로 합칠수 있을거 같습니다 |
||
|
||
binding.etHobby.addTextChangedListener { | ||
if (viewModel.isNotBlankHobby()) { | ||
binding.tilHobby.error = null | ||
if (viewModel.isValidInput()) activateSignUpButton() | ||
} else { | ||
binding.tilHobby.error = getString(R.string.sign_up_required_input_err) | ||
deactivateSignUpButton() | ||
} | ||
} | ||
} | ||
|
||
private fun activateSignUpButton() { | ||
binding.btnSignUp.isEnabled = true | ||
} | ||
|
||
private fun deactivateSignUpButton() { | ||
binding.btnSignUp.isEnabled = false | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 데이터바인딩이나 바인딩 어댑터를 활용하여 처리하면 코드를 좀 줄일 수 있을 것 같습니다! |
||
|
||
private fun initSignUpStateObserver() { | ||
viewModel.signUpState.observe(this) { state -> | ||
when (state) { | ||
|
@@ -38,10 +86,6 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_ | |
binding.root, | ||
getString(R.string.invalid_input_error_msg) | ||
) | ||
CODE_INCORRECT_INPUT -> showSnackbar( | ||
binding.root, | ||
getString(R.string.incorrect_input_error_msg) | ||
) | ||
CODE_DUPLICATED_ID -> showSnackbar( | ||
binding.root, | ||
getString(R.string.id_duplicate_error_msg) | ||
|
@@ -63,40 +107,16 @@ class SignUpActivity : BindingActivity<ActivitySignUpBinding>(R.layout.activity_ | |
private fun initRootLayoutClickListener() { | ||
binding.root.setOnClickListener { | ||
hideKeyboard() | ||
focusOutEditText() | ||
} | ||
} | ||
|
||
private fun initEditTextChangedListeners() { | ||
binding.etId.addTextChangedListener { | ||
if (!viewModel.isValidId()) { | ||
binding.tvIdLimitError.visibility = View.VISIBLE | ||
} else { | ||
binding.tvIdLimitError.visibility = View.INVISIBLE | ||
} | ||
} | ||
|
||
binding.etPw.addTextChangedListener { | ||
if (!viewModel.isValidPw()) { | ||
binding.tvPwLimitError.visibility = View.VISIBLE | ||
} else { | ||
binding.tvPwLimitError.visibility = View.INVISIBLE | ||
} | ||
} | ||
|
||
binding.etName.addTextChangedListener { | ||
if (viewModel.name.isEmpty()) { | ||
binding.tvNameEmptyError.visibility = View.VISIBLE | ||
} else { | ||
binding.tvNameEmptyError.visibility = View.INVISIBLE | ||
} | ||
} | ||
|
||
binding.etHobby.addTextChangedListener { | ||
if (viewModel.hobby.isEmpty()) { | ||
binding.tvHobbyEmptyError.visibility = View.VISIBLE | ||
} else { | ||
binding.tvHobbyEmptyError.visibility = View.INVISIBLE | ||
} | ||
private fun focusOutEditText() { | ||
with(binding) { | ||
etId.clearFocus() | ||
etPw.clearFocus() | ||
etName.clearFocus() | ||
etHobby.clearFocus() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure인 경우에도 LoadingDialog를 dismiss 해주는 것이 좋을 것 같습니다!