Skip to content

Commit 549cc05

Browse files
committed
✨ 그룹 생성 전 중복확인을 반드시 하도록 변경
1 parent b51019f commit 549cc05

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

presentation/src/main/java/com/whyranoid/presentation/community/group/create/CreateGroupFragment.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ internal class CreateGroupFragment :
3434
handleEvent(event)
3535
}
3636
}
37-
38-
viewLifecycleOwner.repeatWhenUiStarted {
39-
viewModel.rules.collect {
40-
println("테스트 $it")
41-
}
42-
}
4337
}
4438

4539
private fun handleEvent(event: Event) {
@@ -60,6 +54,22 @@ internal class CreateGroupFragment :
6054
).show()
6155
}
6256
}
57+
is Event.DuplicateCheckButtonClick -> {
58+
if (event.isDuplicatedGroupName) {
59+
Snackbar.make(
60+
binding.root,
61+
getString(R.string.text_duplicated_group_name),
62+
Snackbar.LENGTH_SHORT
63+
).show()
64+
} else {
65+
Snackbar.make(
66+
binding.root,
67+
getString(R.string.text_un_duplicated_group_name),
68+
Snackbar.LENGTH_SHORT
69+
).show()
70+
binding.etGroupName.isEnabled = false
71+
}
72+
}
6373
is Event.WarningButtonClick -> {
6474
Snackbar.make(
6575
binding.root,
@@ -106,7 +116,7 @@ internal class CreateGroupFragment :
106116
}
107117

108118
viewLifecycleOwner.repeatWhenUiStarted {
109-
viewModel.isButtonEnable.collect { isEnable ->
119+
viewModel.isGroupCreateButtonEnable.collect { isEnable ->
110120
if (isEnable) {
111121
binding.topAppBar.menu.setGroupVisible(R.id.ready_to_create, true)
112122
binding.topAppBar.menu.setGroupVisible(R.id.not_ready_to_create, false)

presentation/src/main/java/com/whyranoid/presentation/community/group/create/CreateGroupViewModel.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.whyranoid.presentation.community.group.create
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.whyranoid.domain.usecase.CheckIsDuplicatedGroupNameUseCase
56
import com.whyranoid.domain.usecase.CreateGroupUseCase
67
import dagger.hilt.android.lifecycle.HiltViewModel
78
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -17,7 +18,8 @@ import javax.inject.Inject
1718

1819
@HiltViewModel
1920
class CreateGroupViewModel @Inject constructor(
20-
private val createGroupUseCase: CreateGroupUseCase
21+
private val createGroupUseCase: CreateGroupUseCase,
22+
private val checkIsDuplicatedGroupNameUseCase: CheckIsDuplicatedGroupNameUseCase
2123
) : ViewModel() {
2224

2325
val groupName = MutableStateFlow<String?>(null)
@@ -30,6 +32,8 @@ class CreateGroupViewModel @Inject constructor(
3032
private val _eventFlow = MutableSharedFlow<Event>()
3133
val eventFlow = _eventFlow.asSharedFlow()
3234

35+
private val isNotDuplicate = MutableStateFlow(false)
36+
3337
fun onOpenDialogClicked() {
3438
_showDialog.value = true
3539
}
@@ -43,7 +47,7 @@ class CreateGroupViewModel @Inject constructor(
4347
_showDialog.value = false
4448
}
4549

46-
val isButtonEnable: StateFlow<Boolean>
50+
val isDoubleCheckButtonEnable: StateFlow<Boolean>
4751
get() = groupName.combine(groupIntroduce) { name, introduce ->
4852
name?.trim()?.isNotEmpty() ?: false && introduce?.trim()?.isNotEmpty() ?: false
4953
}.stateIn(
@@ -52,8 +56,25 @@ class CreateGroupViewModel @Inject constructor(
5256
started = SharingStarted.WhileSubscribed(5000)
5357
)
5458

55-
// TODO 그룹명 중복확인 로직
59+
val isGroupCreateButtonEnable: StateFlow<Boolean>
60+
get() = combine(
61+
isDoubleCheckButtonEnable,
62+
isNotDuplicate
63+
) { isDoubleCheckButtonEnable, isNotDuplicate ->
64+
isDoubleCheckButtonEnable && isNotDuplicate
65+
}.stateIn(
66+
scope = viewModelScope,
67+
initialValue = false,
68+
started = SharingStarted.WhileSubscribed(5000)
69+
)
70+
5671
fun onDuplicateCheckButtonClicked() {
72+
viewModelScope.launch {
73+
val isDuplicatedGroupName =
74+
checkIsDuplicatedGroupNameUseCase(groupName.value ?: "")
75+
emitEvent(Event.DuplicateCheckButtonClick(isDuplicatedGroupName))
76+
isNotDuplicate.value = isDuplicatedGroupName.not()
77+
}
5778
}
5879

5980
fun onAddRuleButtonClicked() {
@@ -75,6 +96,13 @@ class CreateGroupViewModel @Inject constructor(
7596
_eventFlow.emit(event.copy(isSuccess = false))
7697
}
7798
}
99+
is Event.DuplicateCheckButtonClick -> {
100+
if (event.isDuplicatedGroupName) {
101+
_eventFlow.emit(event.copy(isDuplicatedGroupName = true))
102+
} else {
103+
_eventFlow.emit(event)
104+
}
105+
}
78106
is Event.WarningButtonClick -> {
79107
_eventFlow.emit(event)
80108
}

presentation/src/main/java/com/whyranoid/presentation/community/group/create/Event.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ sealed class Event {
44
data class CreateGroupButtonClick(val isSuccess: Boolean = true) : Event()
55
object WarningButtonClick : Event()
66
object AddRuleButtonClick : Event()
7+
data class DuplicateCheckButtonClick(val isDuplicatedGroupName: Boolean = false) : Event()
78
}

presentation/src/main/res/layout/fragment_create_group.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
android:layout_width="wrap_content"
5959
android:layout_height="wrap_content"
6060
android:layout_margin="16dp"
61-
android:enabled="@{viewModel.isButtonEnable()}"
61+
android:enabled="@{viewModel.isDoubleCheckButtonEnable()}"
6262
android:onClick="@{() -> viewModel.onDuplicateCheckButtonClicked()}"
6363
android:text="@string/text_duplicate_check"
6464
app:layout_constraintBottom_toTopOf="@id/time_and_date_picker"

presentation/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@
8787
<string name="running_channel_name">활동 추적</string>
8888
<string name="running_channel_description">달리기 활동을 추적하는 알림 채널입니다.</string>
8989
<string name="text_join_group">그룹 가입하기</string>
90+
<string name="text_duplicated_group_name">중복된 그룹 이름입니다. 변경해주세요!</string>
91+
<string name="text_un_duplicated_group_name">사용 가능한 그룹 이름입니다!</string>
9092

9193
</resources>

0 commit comments

Comments
 (0)