diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt index afd027d8..c5fc8ca7 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt @@ -24,10 +24,18 @@ class NicknameInputActivity: BaseActivity({ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + initView() initClickListener() initObserver() } + private fun initView() { + binding.etProfileEditNickname.backgroundTintList = getColorStateList( + this@NicknameInputActivity, + com.depromeet.designsystem.R.color.color_gray_200 + ) + } + private fun initClickListener() = with(binding) { ivBack.setOnClickListener { finish() @@ -53,7 +61,7 @@ class NicknameInputActivity: BaseActivity({ etProfileEditNickname.setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_DONE) { if (etProfileEditNickname.text.isNotEmpty()) { - //Todo : 서버 API 연동 및 닉네임 중복 검사 + signUpViewModel.checkDuplicateNickname(etProfileEditNickname.text.toString()) } true } else { @@ -66,13 +74,7 @@ class NicknameInputActivity: BaseActivity({ } tvNicknameNextBtn.setOnClickListener { - //Todo : 서버 API 연동 및 닉네임 중복 검사 - //임시로 응원하는 팀 선택 화면으로 이동 - Intent(this@NicknameInputActivity, TeamSelectActivity::class.java).apply { - putExtra("nickname", etProfileEditNickname.text.toString()) - putExtra("kakaoToken", intent.getStringExtra("kakaoToken")) - startActivity(this) - } + signUpViewModel.checkDuplicateNickname(etProfileEditNickname.text.toString()) } } @@ -87,6 +89,13 @@ class NicknameInputActivity: BaseActivity({ clNicknameInputWarning.visibility = View.GONE updateButtonEnabled(true) } + NicknameInputState.NICKNAME_SUCCESS -> { + Intent(this@NicknameInputActivity, TeamSelectActivity::class.java).apply { + putExtra("nickname", etProfileEditNickname.text.toString()) + putExtra("kakaoToken", intent.getStringExtra("kakaoToken")) + startActivity(this) + } + } NicknameInputState.INVALID_LENGTH -> { clNicknameInputWarning.visibility = View.VISIBLE tvNicknameWarning.text = getString(R.string.profile_edit_error_length) diff --git a/presentation/src/main/java/com/dpm/presentation/login/viewmodel/NicknameInputViewModel.kt b/presentation/src/main/java/com/dpm/presentation/login/viewmodel/NicknameInputViewModel.kt index f89da75a..24b13822 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/viewmodel/NicknameInputViewModel.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/viewmodel/NicknameInputViewModel.kt @@ -1,15 +1,18 @@ package com.dpm.presentation.login.viewmodel import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.dpm.domain.repository.HomeRepository import com.dpm.presentation.extension.NICKNAME_PATTERN import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class NicknameInputViewModel @Inject constructor( - + private val homeRepository: HomeRepository, ) : ViewModel() { private val _nicknameInputState = MutableStateFlow(NicknameInputState.EMPTY) @@ -27,8 +30,20 @@ class NicknameInputViewModel @Inject constructor( !nickname.matches(Regex(NICKNAME_PATTERN)) -> _nicknameInputState.tryEmit( NicknameInputState.INVALID_CHARACTER ) - else -> _nicknameInputState.tryEmit(NicknameInputState.VALID) + else -> { _nicknameInputState.tryEmit(NicknameInputState.VALID) } } _currentNickName.tryEmit(nickname) } + + fun checkDuplicateNickname(nickname: String) { + viewModelScope.launch { + homeRepository.getDuplicateNickname(nickname) + .onSuccess { + _nicknameInputState.tryEmit(NicknameInputState.NICKNAME_SUCCESS) + } + .onFailure { + _nicknameInputState.tryEmit(NicknameInputState.DUPLICATE) + } + } + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/viewmodel/SignUpViewModel.kt b/presentation/src/main/java/com/dpm/presentation/login/viewmodel/SignUpViewModel.kt index 7122de5f..a4817650 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/viewmodel/SignUpViewModel.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/viewmodel/SignUpViewModel.kt @@ -97,5 +97,6 @@ enum class NicknameInputState { VALID, INVALID_LENGTH, INVALID_CHARACTER, - DUPLICATE + DUPLICATE, + NICKNAME_SUCCESS } \ No newline at end of file