Skip to content
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

week6: 6차 필수과제 진행 (xml) #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/src/main/java/com/sopt/now/ui/signIn/SignInActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
setupViewModel()
setupSignInButtonListener()
observeSignInResult()
observeWeekSixthHomework()
setupNavigateToSignUpListener()
}

Expand All @@ -34,6 +35,7 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
private fun setupSignInButtonListener() {
binding.viewSignInButton.setOnClickListener {
performSignIn()
finishHomework()
}
}

Expand All @@ -44,6 +46,10 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
signInViewModel.performSignIn(SignInRequest(inputUsername, inputPassword))
}

private fun finishHomework() {
signInViewModel.finishHomework()
}

private fun observeSignInResult() {
signInViewModel.signInMessage.observe(this) { message ->
if (message.split("/")[0] == SignInViewModel.SUCCESS_SIGN_IN) {
Expand All @@ -66,6 +72,18 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
finish()
}

private fun observeWeekSixthHomework() {
signInViewModel.isWeekSixthHomeworkFinished.observe(this) { isWeekSixthHomeworkFinished ->
if (isWeekSixthHomeworkFinished) {
Toast.makeText(
this,
getString(R.string.finish_week_sixth_homework),
Toast.LENGTH_SHORT,
).show()
}
}
}

private fun setupNavigateToSignUpListener() {
binding.viewSignInSignUpButton.setOnClickListener {
val intent = SignUpActivity.newIntent(this)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/sopt/now/ui/signIn/SignInViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class SignInViewModel : ViewModel() {
private val _signInMessage = MutableLiveData<String>()
val signInMessage: LiveData<String> = _signInMessage

private val _isWeekSixthHomeworkFinished = MutableLiveData<Boolean>(false)
val isWeekSixthHomeworkFinished: LiveData<Boolean> = _isWeekSixthHomeworkFinished

fun performSignIn(request: SignInRequest) {
viewModelScope.launch {
runCatching {
Expand All @@ -32,6 +35,10 @@ class SignInViewModel : ViewModel() {
}
}

fun finishHomework() {
_isWeekSixthHomeworkFinished.value = true
}

companion object {
const val SUCCESS_SIGN_IN = "SUCCESS"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<!-- SignInActivity -->
<string name="success_sign_in">로그인에 성공하셨습니다!</string>
<string name="finish_week_sixth_homework">6주차 과제 완료!</string>

<!-- SignUpActivity -->
<string name="success_sign_up">%s번째 회원님 환영합니다!</string>
Expand Down