Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class UserInfoActivity :

force = intent.getBooleanExtra("force", false)

binding.btnCheckNickname.isEnabled = false
binding.btnCheckNicknameDuplication.isEnabled = false
binding.btnComplete.isEnabled = false

lifecycleScope.launch {
userInfoViewModel.uiState.collectLatest {
binding.etChNickname.setText(it.nickname)
userInfoViewModel.uiState.collectLatest { it ->
if (binding.etChNickname.text.toString() != it.nickname) {
binding.etChNickname.setText(it.nickname)
binding.etChNickname.setSelection(it.nickname.length) // 커서 끝으로 이동
}
binding.tvCollege.text = it.selectedCollege.collegeName
binding.tvDepartment.text = it.selectedDepartment.departmentName
}
Expand All @@ -61,7 +64,7 @@ class UserInfoActivity :
val isValidLength = nicknameLength in 2..8
val isNicknameChanged = inputNickname != userInfoViewModel.uiState.value.originalNickname

binding.btnCheckNickname.isEnabled = isValidLength && isNicknameChanged
binding.btnCheckNicknameDuplication.isEnabled = isValidLength && isNicknameChanged
binding.btnComplete.isEnabled = false

if (!isValidLength && inputNickname.isNotEmpty()) {
Expand All @@ -71,15 +74,13 @@ class UserInfoActivity :
} else {
binding.tvNickname28.setTextColor(getColor(R.color.gray600))
}

userInfoViewModel.updateNickname(inputNickname)
}

override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun afterTextChanged(p0: Editable?) {}
})

setOnCheckNicknameClickListener()
setOnCheckNicknameDuplicationClickListener()
setCollegeDepartmentClickListener()
collectButtonEnableState()
collectUIState()
Expand All @@ -97,8 +98,8 @@ class UserInfoActivity :
}
}

private fun setOnCheckNicknameClickListener() {
binding.btnCheckNickname.setOnClickListener {
private fun setOnCheckNicknameDuplicationClickListener() {
binding.btnCheckNicknameDuplication.setOnClickListener {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

이 클릭 리스너 내에서 uiState를 구독하는 로직(110-126행)은 개선이 필요해 보입니다. 클릭할 때마다 새로운 collectLatest 코루틴을 시작하는 것은 안티패턴이며, 여러 구독으로 인해 비효율적이고 예측 불가능한 동작을 유발할 수 있습니다.

이 Activity에 이미 여러 uiState 구독이 존재하므로(onCreate, collectButtonEnableState, collectUIState), 모든 UI 업데이트를 처리하는 단일 구독으로 통합하는 것을 강력히 권장합니다.

닉네임 중복 확인 결과와 같은 일회성 이벤트를 처리하기 위해서는 ViewModel에서 SharedFlow를 사용하는 패턴을 고려해볼 수 있습니다. 이렇게 하면 UI 로직이 더 명확해지고 관리하기 쉬워집니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 해당 액티비티에 uistate 도입 리팩토링 때 같이 수정하겠씁니다!

userInfoViewModel.checkNickname(inputNickname)

// 닉네임 중복 확인 후 UI 상태 업데이트 로직
Expand All @@ -108,7 +109,7 @@ class UserInfoActivity :
lifecycleScope.launch {
userInfoViewModel.uiState.collectLatest {
if (it.isEnableName) {
binding.btnCheckNickname.isEnabled = false // 중복확인 비활성화
binding.btnCheckNicknameDuplication.isEnabled = false // 중복확인 비활성화
binding.btnComplete.isEnabled = true // 저장하기 활성화
binding.tvNickname28.text = getString(R.string.set_nickname_able)
binding.etChNickname.setBackgroundResource(R.drawable.shape_text_field_small)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UserInfoViewModel @Inject constructor(
fun checkNickname(inputNickname: String) {
viewModelScope.launch {
validateUserNameUseCase(inputNickname).onStart {
_uiState.update { it.copy(loading = true) }
_uiState.update { it.copy(loading = true, nickname = inputNickname) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xml 안에 id 변경으로 인한 수정 말고는 이 수정이 다 인거죵?!

}.onCompletion {
_uiState.update { it.copy(loading = false) }
}.catch { e ->
Expand All @@ -76,15 +76,13 @@ class UserInfoViewModel @Inject constructor(
isEnableName = true,
toastMessage = "사용가능한 닉네임 입니다.",
isNicknameChecked = true,
nickname = inputNickname,
)
}
} else {
_uiState.update {
it.copy(
isEnableName = false,
toastMessage = "이미 사용 중인 닉네임 입니다.",
nickname = inputNickname,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_user_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
app:layout_constraintTop_toBottomOf="@+id/tv_ch_nickname" />

<Button
android:id="@+id/btn_check_nickname"
android:id="@+id/btn_check_nickname_duplication"
style="@style/Button2"
android:layout_width="wrap_content"
android:layout_height="52dp"
Expand Down