@@ -10,14 +10,16 @@ import androidx.compose.foundation.layout.Column
10
10
import androidx.compose.foundation.layout.Row
11
11
import androidx.compose.foundation.layout.RowScope
12
12
import androidx.compose.foundation.layout.Spacer
13
+ import androidx.compose.foundation.layout.fillMaxHeight
13
14
import androidx.compose.foundation.layout.fillMaxWidth
14
15
import androidx.compose.foundation.layout.height
15
16
import androidx.compose.foundation.layout.padding
16
17
import androidx.compose.foundation.layout.size
18
+ import androidx.compose.foundation.layout.width
17
19
import androidx.compose.foundation.shape.CornerSize
18
20
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
21
23
import androidx.compose.material.Text
22
24
import androidx.compose.runtime.Composable
23
25
import androidx.compose.runtime.getValue
@@ -29,12 +31,13 @@ import androidx.compose.ui.Modifier
29
31
import androidx.compose.ui.draw.alpha
30
32
import androidx.compose.ui.draw.clip
31
33
import androidx.compose.ui.graphics.Color
32
- import androidx.compose.ui.platform.LocalContext
33
34
import androidx.compose.ui.text.TextStyle
34
35
import androidx.compose.ui.text.font.FontWeight
35
36
import androidx.compose.ui.text.style.TextAlign
36
37
import androidx.compose.ui.tooling.preview.Preview
37
38
import androidx.compose.ui.unit.dp
39
+ import androidx.compose.ui.unit.sp
40
+ import androidx.compose.ui.window.Dialog
38
41
import be.sigmadelta.calpose.Calpose
39
42
import be.sigmadelta.calpose.WEIGHT_7DAY_WEEK
40
43
import be.sigmadelta.calpose.model.CalposeActions
@@ -45,29 +48,39 @@ import be.sigmadelta.calpose.widgets.MaterialHeader
45
48
import coil.compose.rememberImagePainter
46
49
import coil.transform.CircleCropTransformation
47
50
import com.google.accompanist.insets.ProvideWindowInsets
51
+ import com.google.accompanist.insets.statusBarsHeight
48
52
import com.teamtuna.emotionaldiary.compose.theme.EmotionalDiaryTheme
49
53
import org.threeten.bp.DayOfWeek
50
54
import org.threeten.bp.YearMonth
51
55
52
56
@Preview
53
57
@Composable
54
58
fun CalendarComposeApp () {
59
+ val appBarColor = MaterialTheme .colors.surface.copy(alpha = 0.87f )
60
+
55
61
EmotionalDiaryTheme {
56
62
ProvideWindowInsets {
57
63
Column {
58
- Spacer (modifier = Modifier .height(100 .dp))
64
+ Spacer (
65
+ modifier = Modifier
66
+ .background(appBarColor)
67
+ .fillMaxWidth()
68
+ .statusBarsHeight()
69
+ )
59
70
MaterialPreview ()
60
71
}
61
72
}
62
73
}
63
74
}
64
75
65
- @Preview(" MaterialPreview" )
66
76
@Composable
67
77
fun MaterialPreview () {
68
78
var month by remember { mutableStateOf(YearMonth .now()) }
69
79
var selectionSet by remember { mutableStateOf(setOf<CalposeDate >()) }
70
80
val (showDialog, setShowDialog) = remember { mutableStateOf(false ) }
81
+ var currentDate by remember {
82
+ mutableStateOf(CalposeDate (- 1 , DayOfWeek .MONDAY , YearMonth .now()))
83
+ }
71
84
72
85
MaterialCalendar (
73
86
month = month,
@@ -76,15 +89,27 @@ fun MaterialPreview() {
76
89
onClickedPreviousMonth = { month = month.minusMonths(1 ) },
77
90
onClickedNextMonth = { month = month.plusMonths(1 ) },
78
91
),
79
- onSelected = {
80
- selectionSet = mutableSetOf (it).apply {
92
+ onSelected = { calPoseDate ->
93
+ selectionSet = mutableSetOf (calPoseDate).apply {
94
+ currentDate = calPoseDate
81
95
setShowDialog(true )
82
96
addAll(selectionSet)
83
97
}
84
98
}
85
99
)
86
100
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
+ )
88
113
}
89
114
90
115
@Composable
@@ -106,6 +131,7 @@ fun MaterialCalendar(
106
131
day = { dayDate, todayDate ->
107
132
Day (
108
133
dayDate = dayDate,
134
+ todayDate = todayDate,
109
135
selectionSet = selectionSet,
110
136
onSelected = onSelected
111
137
)
@@ -139,32 +165,35 @@ fun HeaderDayRow(
139
165
@Composable
140
166
fun RowScope.Day (
141
167
dayDate : CalposeDate ,
168
+ todayDate : CalposeDate ,
142
169
selectionSet : Set <CalposeDate >,
143
170
onSelected : (CalposeDate ) -> Unit
144
171
) {
172
+ val isToday = todayDate == dayDate
145
173
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
+ }
148
179
149
180
val widget: @Composable () -> Unit = {
150
181
EmotionDay (
151
182
text = dayDate.day.toString(),
152
- modifier = Modifier
153
- .padding(4 .dp)
154
- .weight(weight)
155
- .fillMaxWidth(),
156
183
style = TextStyle (
157
184
color = when {
158
- isSelected -> Color .White
185
+ isSelected || isToday -> Color .White
159
186
else -> Color .Black
160
187
},
161
- fontWeight = if (isSelected) FontWeight .Bold else FontWeight .Normal
188
+ fontWeight = if (isSelected || isToday ) FontWeight .Bold else FontWeight .Normal
162
189
)
163
190
)
164
191
}
165
192
166
193
Column (
167
- modifier = Modifier .weight(WEIGHT_7DAY_WEEK ),
194
+ modifier = Modifier
195
+ .weight(WEIGHT_7DAY_WEEK )
196
+ .padding(4 .dp),
168
197
verticalArrangement = Arrangement .Center ,
169
198
horizontalAlignment = Alignment .CenterHorizontally
170
199
) {
@@ -200,21 +229,19 @@ fun RowScope.PriorMonthDay(
200
229
@Composable
201
230
fun EmotionDay (
202
231
text : String ,
203
- modifier : Modifier = Modifier .padding(4.dp),
204
232
style : TextStyle = TextStyle ()
205
233
) {
206
- val ctx = LocalContext .current
207
- val maxSize = 50 .dp
208
234
val url = " https://upload.wikimedia.org/wikipedia/commons/thumb/" +
209
235
" e/e6/Noto_Emoji_KitKat_263a.svg/1200px-Noto_Emoji_KitKat_263a.svg.png"
210
236
211
237
Column (
212
238
verticalArrangement = Arrangement .Center ,
213
- horizontalAlignment = Alignment .CenterHorizontally
214
239
) {
215
240
Text (
216
241
text,
217
- modifier = modifier,
242
+ Modifier
243
+ .padding(4 .dp)
244
+ .fillMaxWidth(),
218
245
textAlign = TextAlign .Center ,
219
246
style = style
220
247
)
@@ -227,48 +254,85 @@ fun EmotionDay(
227
254
),
228
255
contentDescription = null ,
229
256
modifier = Modifier
230
- .weight( WEIGHT_7DAY_WEEK )
231
- .size(maxSize )
257
+ .fillMaxWidth( )
258
+ .fillMaxHeight( )
232
259
)
233
260
}
234
261
}
235
262
236
263
@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)
261
296
) {
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
+ }
263
329
}
264
- },
265
- text = {
266
- Text (" This is a text on the dialog" )
267
- },
268
- )
330
+ }
331
+ }
269
332
}
270
333
}
271
334
272
335
const val lightGrey = 0xa0bdbdbd
336
+ const val todayColor = 0xFF30cf5a
273
337
const val primaryAccent = 0xFF4db6ac
274
338
const val primaryAccentLight = 0xFF82e9de
0 commit comments