Skip to content

Commit 1c5a661

Browse files
authored
Merge pull request #117 from teamtuna/EMOTION-90
Emotion 90 달력 다이얼로그 추가
2 parents 485ec22 + bb4bb2e commit 1c5a661

File tree

1 file changed

+118
-54
lines changed

1 file changed

+118
-54
lines changed

presentation/src/main/java/com/teamtuna/emotionaldiary/compose/calendar/CalendarComposeApp.kt

+118-54
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.Row
1111
import androidx.compose.foundation.layout.RowScope
1212
import androidx.compose.foundation.layout.Spacer
13+
import androidx.compose.foundation.layout.fillMaxHeight
1314
import androidx.compose.foundation.layout.fillMaxWidth
1415
import androidx.compose.foundation.layout.height
1516
import androidx.compose.foundation.layout.padding
1617
import androidx.compose.foundation.layout.size
18+
import androidx.compose.foundation.layout.width
1719
import androidx.compose.foundation.shape.CornerSize
1820
import androidx.compose.foundation.shape.RoundedCornerShape
19-
import androidx.compose.material.AlertDialog
20-
import androidx.compose.material.Button
21+
import androidx.compose.material.Card
22+
import androidx.compose.material.MaterialTheme
2123
import androidx.compose.material.Text
2224
import androidx.compose.runtime.Composable
2325
import androidx.compose.runtime.getValue
@@ -29,12 +31,13 @@ import androidx.compose.ui.Modifier
2931
import androidx.compose.ui.draw.alpha
3032
import androidx.compose.ui.draw.clip
3133
import androidx.compose.ui.graphics.Color
32-
import androidx.compose.ui.platform.LocalContext
3334
import androidx.compose.ui.text.TextStyle
3435
import androidx.compose.ui.text.font.FontWeight
3536
import androidx.compose.ui.text.style.TextAlign
3637
import androidx.compose.ui.tooling.preview.Preview
3738
import androidx.compose.ui.unit.dp
39+
import androidx.compose.ui.unit.sp
40+
import androidx.compose.ui.window.Dialog
3841
import be.sigmadelta.calpose.Calpose
3942
import be.sigmadelta.calpose.WEIGHT_7DAY_WEEK
4043
import be.sigmadelta.calpose.model.CalposeActions
@@ -45,29 +48,39 @@ import be.sigmadelta.calpose.widgets.MaterialHeader
4548
import coil.compose.rememberImagePainter
4649
import coil.transform.CircleCropTransformation
4750
import com.google.accompanist.insets.ProvideWindowInsets
51+
import com.google.accompanist.insets.statusBarsHeight
4852
import com.teamtuna.emotionaldiary.compose.theme.EmotionalDiaryTheme
4953
import org.threeten.bp.DayOfWeek
5054
import org.threeten.bp.YearMonth
5155

5256
@Preview
5357
@Composable
5458
fun CalendarComposeApp() {
59+
val appBarColor = MaterialTheme.colors.surface.copy(alpha = 0.87f)
60+
5561
EmotionalDiaryTheme {
5662
ProvideWindowInsets {
5763
Column {
58-
Spacer(modifier = Modifier.height(100.dp))
64+
Spacer(
65+
modifier = Modifier
66+
.background(appBarColor)
67+
.fillMaxWidth()
68+
.statusBarsHeight()
69+
)
5970
MaterialPreview()
6071
}
6172
}
6273
}
6374
}
6475

65-
@Preview("MaterialPreview")
6676
@Composable
6777
fun MaterialPreview() {
6878
var month by remember { mutableStateOf(YearMonth.now()) }
6979
var selectionSet by remember { mutableStateOf(setOf<CalposeDate>()) }
7080
val (showDialog, setShowDialog) = remember { mutableStateOf(false) }
81+
var currentDate by remember {
82+
mutableStateOf(CalposeDate(-1, DayOfWeek.MONDAY, YearMonth.now()))
83+
}
7184

7285
MaterialCalendar(
7386
month = month,
@@ -76,15 +89,27 @@ fun MaterialPreview() {
7689
onClickedPreviousMonth = { month = month.minusMonths(1) },
7790
onClickedNextMonth = { month = month.plusMonths(1) },
7891
),
79-
onSelected = {
80-
selectionSet = mutableSetOf(it).apply {
92+
onSelected = { calPoseDate ->
93+
selectionSet = mutableSetOf(calPoseDate).apply {
94+
currentDate = calPoseDate
8195
setShowDialog(true)
8296
addAll(selectionSet)
8397
}
8498
}
8599
)
86100

87-
EmotionDialog(showDialog, setShowDialog)
101+
EmotionListDialog(
102+
showDialog,
103+
setShowDialog,
104+
currentDate,
105+
onDismiss = {
106+
// dialog 없어진 후 작업이 필요할 경
107+
},
108+
onEmotionClick = { calposeDate, emotionId ->
109+
// newIntent 작업한 곳으로 보내기
110+
// 날짜, emotion Id 값이 보내져아함
111+
}
112+
)
88113
}
89114

90115
@Composable
@@ -106,6 +131,7 @@ fun MaterialCalendar(
106131
day = { dayDate, todayDate ->
107132
Day(
108133
dayDate = dayDate,
134+
todayDate = todayDate,
109135
selectionSet = selectionSet,
110136
onSelected = onSelected
111137
)
@@ -139,32 +165,35 @@ fun HeaderDayRow(
139165
@Composable
140166
fun RowScope.Day(
141167
dayDate: CalposeDate,
168+
todayDate: CalposeDate,
142169
selectionSet: Set<CalposeDate>,
143170
onSelected: (CalposeDate) -> Unit
144171
) {
172+
val isToday = todayDate == dayDate
145173
val isSelected = selectionSet.contains(dayDate)
146-
val weight = WEIGHT_7DAY_WEEK
147-
val bgColor = if (isSelected) Color(primaryAccent) else Color.Transparent
174+
val bgColor = when {
175+
isSelected -> Color(primaryAccent)
176+
isToday -> Color(todayColor)
177+
else -> Color.Transparent
178+
}
148179

149180
val widget: @Composable () -> Unit = {
150181
EmotionDay(
151182
text = dayDate.day.toString(),
152-
modifier = Modifier
153-
.padding(4.dp)
154-
.weight(weight)
155-
.fillMaxWidth(),
156183
style = TextStyle(
157184
color = when {
158-
isSelected -> Color.White
185+
isSelected || isToday -> Color.White
159186
else -> Color.Black
160187
},
161-
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
188+
fontWeight = if (isSelected || isToday) FontWeight.Bold else FontWeight.Normal
162189
)
163190
)
164191
}
165192

166193
Column(
167-
modifier = Modifier.weight(WEIGHT_7DAY_WEEK),
194+
modifier = Modifier
195+
.weight(WEIGHT_7DAY_WEEK)
196+
.padding(4.dp),
168197
verticalArrangement = Arrangement.Center,
169198
horizontalAlignment = Alignment.CenterHorizontally
170199
) {
@@ -200,21 +229,19 @@ fun RowScope.PriorMonthDay(
200229
@Composable
201230
fun EmotionDay(
202231
text: String,
203-
modifier: Modifier = Modifier.padding(4.dp),
204232
style: TextStyle = TextStyle()
205233
) {
206-
val ctx = LocalContext.current
207-
val maxSize = 50.dp
208234
val url = "https://upload.wikimedia.org/wikipedia/commons/thumb/" +
209235
"e/e6/Noto_Emoji_KitKat_263a.svg/1200px-Noto_Emoji_KitKat_263a.svg.png"
210236

211237
Column(
212238
verticalArrangement = Arrangement.Center,
213-
horizontalAlignment = Alignment.CenterHorizontally
214239
) {
215240
Text(
216241
text,
217-
modifier = modifier,
242+
Modifier
243+
.padding(4.dp)
244+
.fillMaxWidth(),
218245
textAlign = TextAlign.Center,
219246
style = style
220247
)
@@ -227,48 +254,85 @@ fun EmotionDay(
227254
),
228255
contentDescription = null,
229256
modifier = Modifier
230-
.weight(WEIGHT_7DAY_WEEK)
231-
.size(maxSize)
257+
.fillMaxWidth()
258+
.fillMaxHeight()
232259
)
233260
}
234261
}
235262

236263
@Composable
237-
fun EmotionDialog(showDialog: Boolean, setShowDialog: (Boolean) -> Unit) {
238-
if (showDialog) {
239-
AlertDialog(
240-
onDismissRequest = {
241-
},
242-
title = {
243-
Text("Title")
244-
},
245-
confirmButton = {
246-
Button(
247-
onClick = {
248-
// Change the state to close the dialog
249-
setShowDialog(false)
250-
},
251-
) {
252-
Text("Confirm")
253-
}
254-
},
255-
dismissButton = {
256-
Button(
257-
onClick = {
258-
// Change the state to close the dialog
259-
setShowDialog(false)
260-
},
264+
private fun EmotionListDialog(
265+
showDialog: Boolean,
266+
setShowDialog: (Boolean) -> Unit,
267+
currentDate: CalposeDate,
268+
onDismiss: () -> Unit,
269+
onEmotionClick: (CalposeDate, Int) -> Unit,
270+
) {
271+
val url = "https://upload.wikimedia.org/wikipedia/commons/thumb/" +
272+
"e/e6/Noto_Emoji_KitKat_263a.svg/1200px-Noto_Emoji_KitKat_263a.svg.png"
273+
274+
var emotion by remember { mutableStateOf(-1) }
275+
276+
if (!showDialog || currentDate.day == -1)
277+
return
278+
279+
Dialog(onDismissRequest = onDismiss) {
280+
Card(
281+
elevation = 8.dp,
282+
shape = RoundedCornerShape(12.dp)
283+
) {
284+
Column(modifier = Modifier.padding(8.dp)) {
285+
286+
Text(
287+
text = "Select Emotion",
288+
fontWeight = FontWeight.Bold,
289+
fontSize = 20.sp,
290+
modifier = Modifier.padding(8.dp)
291+
)
292+
Spacer(modifier = Modifier.height(8.dp))
293+
294+
Column(
295+
modifier = Modifier.padding(16.dp)
261296
) {
262-
Text("Dismiss")
297+
// TODO 정의된 emotion 개수에 맞게 적절하게 배치되도록 수정하기 (dialog height, emotion item size)
298+
for (i in 0 until 2) {
299+
Row(
300+
modifier = Modifier.padding(8.dp)
301+
) {
302+
for (j in 0 until 4) {
303+
Box(
304+
Modifier.clickable(
305+
onClick = {
306+
onEmotionClick(currentDate, emotion)
307+
setShowDialog(false)
308+
}
309+
)
310+
) {
311+
Image(
312+
painter = rememberImagePainter(
313+
data = url,
314+
builder = {
315+
transformations(CircleCropTransformation())
316+
}
317+
),
318+
contentDescription = null,
319+
modifier = Modifier
320+
.width(50.dp)
321+
.height(50.dp)
322+
)
323+
}
324+
Spacer(modifier = Modifier.width(16.dp))
325+
}
326+
Spacer(modifier = Modifier.height(16.dp))
327+
}
328+
}
263329
}
264-
},
265-
text = {
266-
Text("This is a text on the dialog")
267-
},
268-
)
330+
}
331+
}
269332
}
270333
}
271334

272335
const val lightGrey = 0xa0bdbdbd
336+
const val todayColor = 0xFF30cf5a
273337
const val primaryAccent = 0xFF4db6ac
274338
const val primaryAccentLight = 0xFF82e9de

0 commit comments

Comments
 (0)