Skip to content

Commit d3f1530

Browse files
committed
✨ 규칙을 고르고 그룹을 생성하는 기능 추가
1 parent fbe2216 commit d3f1530

File tree

8 files changed

+92
-13
lines changed

8 files changed

+92
-13
lines changed

data/src/main/java/com/whyranoid/data/group/GroupDataSource.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ class GroupDataSource @Inject constructor(
9595
}
9696

9797
// TODO Rule 추가
98-
suspend fun createGroup(groupName: String, introduce: String, uid: String): Boolean {
98+
suspend fun createGroup(
99+
groupName: String,
100+
introduce: String,
101+
rules: List<String>,
102+
uid: String
103+
): Boolean {
99104
return suspendCancellableCoroutine { cancellableContinuation ->
100105
val newGroupId = UUID.randomUUID().toString()
101106
db.collection(GROUPS_COLLECTION)
@@ -107,7 +112,7 @@ class GroupDataSource @Inject constructor(
107112
introduce = introduce,
108113
leaderId = uid,
109114
membersId = listOf(uid),
110-
rules = emptyList()
115+
rules = rules
111116
)
112117
).addOnSuccessListener {
113118
cancellableContinuation.resume(true)

data/src/main/java/com/whyranoid/data/group/GroupRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GroupRepositoryImpl @Inject constructor(
4646
groupNotificationDataSource.notifyRunningStart(uid, groupIdList)
4747
}
4848

49-
override suspend fun createGroup(groupName: String, introduce: String, uid: String): Boolean {
50-
return groupDataSource.createGroup(groupName, introduce, uid)
49+
override suspend fun createGroup(groupName: String, introduce: String, rules: List<String>, uid: String): Boolean {
50+
return groupDataSource.createGroup(groupName, introduce, rules, uid)
5151
}
5252
}

domain/src/main/java/com/whyranoid/domain/repository/GroupRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ interface GroupRepository {
3131
suspend fun notifyRunningStart(uid: String, groupIdList: List<String>)
3232

3333
// 그룹 생성하기
34-
suspend fun createGroup(groupName: String, introduce: String, uid: String): Boolean
34+
suspend fun createGroup(groupName: String, introduce: String, rules: List<String>, uid: String): Boolean
3535
}

domain/src/main/java/com/whyranoid/domain/usecase/CreateGroupUseCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CreateGroupUseCase @Inject constructor(
77
private val groupRepository: GroupRepository
88
) {
99
// TODO AccountRepository에서 uid를 가져와야함.
10-
suspend operator fun invoke(groupName: String, introduce: String): Boolean {
11-
return groupRepository.createGroup(groupName, introduce, uid = "hsjeon")
10+
suspend operator fun invoke(groupName: String, introduce: String, rules: List<String>): Boolean {
11+
return groupRepository.createGroup(groupName, introduce, rules = rules, uid = "hsjeon")
1212
}
1313
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package com.whyranoid.presentation.community.group
22

33
import android.os.Bundle
44
import android.view.View
5+
import androidx.compose.material.MaterialTheme
6+
import androidx.compose.runtime.collectAsState
7+
import androidx.compose.runtime.getValue
8+
import androidx.compose.ui.platform.ViewCompositionStrategy
59
import androidx.fragment.app.viewModels
610
import androidx.navigation.fragment.findNavController
711
import com.google.android.material.snackbar.Snackbar
812
import com.whyranoid.presentation.R
913
import com.whyranoid.presentation.base.BaseFragment
14+
import com.whyranoid.presentation.compose.RulePicker
1015
import com.whyranoid.presentation.databinding.FragmentCreateGroupBinding
1116
import com.whyranoid.presentation.util.repeatWhenUiStarted
1217
import dagger.hilt.android.AndroidEntryPoint
@@ -30,6 +35,12 @@ internal class CreateGroupFragment :
3035
handleEvent(event)
3136
}
3237
}
38+
39+
repeatWhenUiStarted {
40+
viewModel.rules.collect {
41+
println("테스트 $it")
42+
}
43+
}
3344
}
3445

3546
private fun handleEvent(event: Event) {
@@ -57,6 +68,20 @@ internal class CreateGroupFragment :
5768
Snackbar.LENGTH_SHORT
5869
).show()
5970
}
71+
is Event.AddRuleButtonClick -> {
72+
binding.composeView.apply {
73+
setViewCompositionStrategy(
74+
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
75+
)
76+
viewModel.onOpenDialogClicked()
77+
setContent {
78+
val showDialogState: Boolean by viewModel.showDialog.collectAsState()
79+
MaterialTheme {
80+
RulePicker(showDialogState, viewModel)
81+
}
82+
}
83+
}
84+
}
6085
}
6186
}
6287

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
99
import kotlinx.coroutines.flow.SharingStarted
1010
import kotlinx.coroutines.flow.StateFlow
1111
import kotlinx.coroutines.flow.asSharedFlow
12+
import kotlinx.coroutines.flow.asStateFlow
1213
import kotlinx.coroutines.flow.combine
1314
import kotlinx.coroutines.flow.stateIn
1415
import kotlinx.coroutines.launch
@@ -21,10 +22,27 @@ class CreateGroupViewModel @Inject constructor(
2122

2223
val groupName = MutableStateFlow<String?>(null)
2324
val groupIntroduce = MutableStateFlow<String?>(null)
25+
val rules = MutableStateFlow<List<String>>(emptyList())
26+
27+
private val _showDialog = MutableStateFlow(false)
28+
val showDialog: StateFlow<Boolean> = _showDialog.asStateFlow()
2429

2530
private val _eventFlow = MutableSharedFlow<Event>()
2631
val eventFlow = _eventFlow.asSharedFlow()
2732

33+
fun onOpenDialogClicked() {
34+
_showDialog.value = true
35+
}
36+
37+
fun onDialogConfirm(date: String, hour: String, minute: String) {
38+
rules.value = rules.value + listOf("$date-$hour-$minute")
39+
_showDialog.value = false
40+
}
41+
42+
fun onDialogDismiss() {
43+
_showDialog.value = false
44+
}
45+
2846
val isButtonEnable: StateFlow<Boolean>
2947
get() = groupName.combine(groupIntroduce) { name, introduce ->
3048
name?.trim()?.isNotEmpty() ?: false && introduce?.trim()?.isNotEmpty() ?: false
@@ -35,7 +53,11 @@ class CreateGroupViewModel @Inject constructor(
3553
)
3654

3755
// TODO 그룹명 중복확인 로직
38-
fun onButtonClicked() {
56+
fun onDuplicateCheckButtonClicked() {
57+
}
58+
59+
fun onAddRuleButtonClicked() {
60+
emitEvent(Event.AddRuleButtonClick)
3961
}
4062

4163
fun emitEvent(event: Event) {
@@ -44,7 +66,8 @@ class CreateGroupViewModel @Inject constructor(
4466
is Event.CreateGroupButtonClick -> {
4567
val isCreateGroupSuccess = createGroupUseCase(
4668
groupName.value ?: "",
47-
groupIntroduce.value ?: ""
69+
groupIntroduce.value ?: "",
70+
rules.value
4871
)
4972
if (isCreateGroupSuccess) {
5073
_eventFlow.emit(event)
@@ -55,6 +78,9 @@ class CreateGroupViewModel @Inject constructor(
5578
is Event.WarningButtonClick -> {
5679
_eventFlow.emit(event)
5780
}
81+
is Event.AddRuleButtonClick -> {
82+
_eventFlow.emit(event)
83+
}
5884
}
5985
}
6086
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package com.whyranoid.presentation.community.group
33
sealed class Event {
44
data class CreateGroupButtonClick(val isSuccess: Boolean = true) : Event()
55
object WarningButtonClick : Event()
6+
object AddRuleButtonClick : Event()
67
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,36 @@
6060
android:layout_height="wrap_content"
6161
android:layout_margin="16dp"
6262
android:enabled="@{viewModel.isButtonEnable()}"
63-
android:onClick="@{() -> viewModel.onButtonClicked()}"
63+
android:onClick="@{() -> viewModel.onDuplicateCheckButtonClicked()}"
6464
android:text="@string/text_duplicate_check"
6565
app:layout_constraintBottom_toTopOf="@id/time_and_date_picker"
6666
app:layout_constraintEnd_toEndOf="parent"
6767
app:layout_constraintTop_toBottomOf="@id/app_bar" />
6868

69-
<!-- TODO 요일, 시간 피커 추가 -->
7069
<TextView
7170
android:id="@+id/time_and_date_picker"
71+
style="@style/MoGakRunText.Bold.Medium"
7272
android:layout_width="0dp"
7373
android:layout_height="70dp"
7474
android:layout_margin="16dp"
7575
android:background="@color/mogakrun_secondary_dark"
76-
app:layout_constraintEnd_toEndOf="parent"
76+
android:gravity="center_vertical"
77+
android:text="@{viewModel.rules.toString()}"
78+
app:layout_constraintEnd_toStartOf="@id/btn_select_rule"
7779
app:layout_constraintStart_toStartOf="parent"
7880
app:layout_constraintTop_toBottomOf="@id/text_input_layout_group_name"
79-
tools:text="피커가 들어갈 자리입니다~" />
81+
tools:text="규칙들 들어갈 자리입니다~" />
82+
83+
<com.google.android.material.button.MaterialButton
84+
android:id="@+id/btn_select_rule"
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:layout_margin="16dp"
88+
android:onClick="@{() -> viewModel.onAddRuleButtonClicked()}"
89+
android:text="@string/text_select_rule"
90+
app:layout_constraintBottom_toTopOf="@id/text_input_layout_group_introduce"
91+
app:layout_constraintEnd_toEndOf="parent"
92+
app:layout_constraintTop_toBottomOf="@id/text_input_layout_group_name" />
8093

8194
<com.google.android.material.textfield.TextInputLayout
8295
android:id="@+id/text_input_layout_group_introduce"
@@ -106,6 +119,15 @@
106119

107120
</com.google.android.material.textfield.TextInputLayout>
108121

122+
<androidx.compose.ui.platform.ComposeView
123+
android:id="@+id/compose_view"
124+
android:layout_width="0dp"
125+
android:layout_height="0dp"
126+
app:layout_constraintBottom_toBottomOf="parent"
127+
app:layout_constraintEnd_toEndOf="parent"
128+
app:layout_constraintStart_toStartOf="parent"
129+
app:layout_constraintTop_toTopOf="parent" />
130+
109131

110132
</androidx.constraintlayout.widget.ConstraintLayout>
111133
</layout>

0 commit comments

Comments
 (0)