Skip to content

Commit 31c874b

Browse files
committed
✨ 그룹 수정 시 이름 수정이 불가능하도록 변경
1 parent e09723f commit 31c874b

File tree

4 files changed

+4
-91
lines changed

4 files changed

+4
-91
lines changed

presentation/src/main/java/com/whyranoid/presentation/community/group/edit/EditGroupFragment.kt

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,6 @@ internal class EditGroupFragment :
5151
).show()
5252
}
5353
}
54-
is Event.DuplicateCheckButtonClick -> {
55-
if (event.isDuplicatedGroupName) {
56-
Snackbar.make(
57-
binding.root,
58-
getString(R.string.text_duplicated_group_name),
59-
Snackbar.LENGTH_SHORT
60-
).show()
61-
} else {
62-
Snackbar.make(
63-
binding.root,
64-
getString(R.string.text_un_duplicated_group_name),
65-
Snackbar.LENGTH_SHORT
66-
).show()
67-
binding.etGroupName.isEnabled = false
68-
}
69-
}
70-
is Event.WarningButtonClick -> {
71-
Snackbar.make(
72-
binding.root,
73-
getString(R.string.text_warning_create_group),
74-
Snackbar.LENGTH_SHORT
75-
).show()
76-
}
7754
}
7855
}
7956

@@ -83,34 +60,18 @@ internal class EditGroupFragment :
8360
handleEvent(event)
8461
}
8562
}
86-
87-
viewLifecycleOwner.repeatWhenUiStarted {
88-
viewModel.isGroupCreateButtonEnable.collect { isEnable ->
89-
if (isEnable) {
90-
binding.topAppBar.menu.setGroupVisible(R.id.ready_to_create, true)
91-
binding.topAppBar.menu.setGroupVisible(R.id.not_ready_to_create, false)
92-
} else {
93-
binding.topAppBar.menu.setGroupVisible(R.id.ready_to_create, false)
94-
binding.topAppBar.menu.setGroupVisible(R.id.not_ready_to_create, true)
95-
}
96-
}
97-
}
9863
}
9964

10065
private fun setupMenu() {
10166
with(binding.topAppBar) {
10267
inflateMenu(R.menu.create_group_menu)
103-
68+
menu.setGroupVisible(R.id.ready_to_create, true)
10469
setOnMenuItemClickListener { menuItem ->
10570
when (menuItem.itemId) {
10671
R.id.create_group_button -> {
10772
viewModel.emitEvent(Event.EditGroupButtonClick())
10873
true
10974
}
110-
R.id.warning_about_create_group_button -> {
111-
viewModel.emitEvent(Event.WarningButtonClick)
112-
true
113-
}
11475
else -> {
11576
false
11677
}

presentation/src/main/java/com/whyranoid/presentation/community/group/edit/EditGroupViewModel.kt

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@ import androidx.lifecycle.SavedStateHandle
44
import androidx.lifecycle.ViewModel
55
import androidx.lifecycle.viewModelScope
66
import com.whyranoid.domain.model.toRule
7-
import com.whyranoid.domain.usecase.CheckIsDuplicatedGroupNameUseCase
87
import com.whyranoid.domain.usecase.UpdateGroupInfoUseCase
98
import com.whyranoid.presentation.model.GroupInfoUiModel
109
import dagger.hilt.android.lifecycle.HiltViewModel
1110
import kotlinx.coroutines.flow.MutableSharedFlow
1211
import kotlinx.coroutines.flow.MutableStateFlow
13-
import kotlinx.coroutines.flow.SharingStarted
14-
import kotlinx.coroutines.flow.StateFlow
1512
import kotlinx.coroutines.flow.asSharedFlow
16-
import kotlinx.coroutines.flow.combine
17-
import kotlinx.coroutines.flow.stateIn
1813
import kotlinx.coroutines.launch
1914
import javax.inject.Inject
2015

2116
@HiltViewModel
2217
class EditGroupViewModel @Inject constructor(
2318
private val updateGroupInfoUseCase: UpdateGroupInfoUseCase,
24-
private val checkIsDuplicatedGroupNameUseCase: CheckIsDuplicatedGroupNameUseCase,
2519
stateHandle: SavedStateHandle
2620
) : ViewModel() {
2721

@@ -34,55 +28,16 @@ class EditGroupViewModel @Inject constructor(
3428
private val _eventFlow = MutableSharedFlow<Event>()
3529
val eventFlow = _eventFlow.asSharedFlow()
3630

37-
private val isNotDuplicate = MutableStateFlow(false)
38-
39-
val isDoubleCheckButtonEnable: StateFlow<Boolean>
40-
get() = groupName.combine(groupIntroduce) { name, introduce ->
41-
name.trim().isNotEmpty() && introduce.trim().isNotEmpty()
42-
}.stateIn(
43-
scope = viewModelScope,
44-
initialValue = false,
45-
started = SharingStarted.WhileSubscribed(5000)
46-
)
47-
48-
val isGroupCreateButtonEnable: StateFlow<Boolean>
49-
get() = combine(
50-
isDoubleCheckButtonEnable,
51-
isNotDuplicate
52-
) { isDoubleCheckButtonEnable, isNotDuplicate ->
53-
isDoubleCheckButtonEnable && isNotDuplicate
54-
}.stateIn(
55-
scope = viewModelScope,
56-
initialValue = false,
57-
started = SharingStarted.WhileSubscribed(5000)
58-
)
59-
60-
fun onDuplicateCheckButtonClicked() {
61-
viewModelScope.launch {
62-
val isDuplicatedGroupName = checkIsDuplicatedGroupNameUseCase(groupName.value)
63-
emitEvent(Event.DuplicateCheckButtonClick(isDuplicatedGroupName))
64-
isNotDuplicate.value = isDuplicatedGroupName.not()
65-
}
66-
}
67-
6831
fun onAddRuleButtonClicked() {
6932
emitEvent(Event.AddRuleButtonClick)
7033
}
7134

7235
fun emitEvent(event: Event) {
7336
viewModelScope.launch {
7437
when (event) {
75-
is Event.AddRuleButtonClick,
76-
Event.WarningButtonClick -> {
38+
is Event.AddRuleButtonClick -> {
7739
_eventFlow.emit(event)
7840
}
79-
is Event.DuplicateCheckButtonClick -> {
80-
if (event.isDuplicatedGroupName) {
81-
_eventFlow.emit(event.copy(isDuplicatedGroupName = true))
82-
} else {
83-
_eventFlow.emit(event)
84-
}
85-
}
8641
// TODO : 성공 여부에 따른 분기처리
8742
is Event.EditGroupButtonClick -> {
8843
viewModelScope.launch {
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.whyranoid.presentation.community.group.edit
22

3-
// TODO : create와 거의 동일함..
43
sealed class Event {
54
data class EditGroupButtonClick(val isSuccess: Boolean = true) : Event()
6-
object WarningButtonClick : Event()
75
object AddRuleButtonClick : Event()
8-
data class DuplicateCheckButtonClick(val isDuplicatedGroupName: Boolean = false) : Event()
96
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
android:layout_width="match_parent"
4848
android:layout_height="wrap_content"
4949
android:background="@color/mogakrun_secondary"
50+
android:enabled="false"
5051
android:hint="@string/text_group_name"
5152
android:maxLength="20"
5253
android:text="@={viewModel.groupName}"
@@ -59,8 +60,7 @@
5960
android:layout_width="wrap_content"
6061
android:layout_height="wrap_content"
6162
android:layout_margin="16dp"
62-
android:enabled="@{viewModel.isDoubleCheckButtonEnable()}"
63-
android:onClick="@{() -> viewModel.onDuplicateCheckButtonClicked()}"
63+
android:visibility="invisible"
6464
android:text="@string/text_duplicate_check"
6565
app:layout_constraintBottom_toTopOf="@id/time_and_date_picker"
6666
app:layout_constraintEnd_toEndOf="parent"

0 commit comments

Comments
 (0)