@@ -2,16 +2,19 @@ package com.hoc081098.datastoresample.ui
2
2
3
3
import androidx.compose.animation.AnimatedVisibility
4
4
import androidx.compose.animation.ExperimentalAnimationApi
5
+ import androidx.compose.foundation.background
5
6
import androidx.compose.foundation.layout.Arrangement
6
7
import androidx.compose.foundation.layout.Box
7
8
import androidx.compose.foundation.layout.Column
8
- import androidx.compose.foundation.layout.PaddingValues
9
9
import androidx.compose.foundation.layout.Row
10
10
import androidx.compose.foundation.layout.Spacer
11
11
import androidx.compose.foundation.layout.fillMaxHeight
12
+ import androidx.compose.foundation.layout.fillMaxSize
12
13
import androidx.compose.foundation.layout.fillMaxWidth
13
14
import androidx.compose.foundation.layout.height
14
15
import androidx.compose.foundation.layout.padding
16
+ import androidx.compose.foundation.layout.requiredHeight
17
+ import androidx.compose.foundation.layout.requiredWidth
15
18
import androidx.compose.foundation.layout.width
16
19
import androidx.compose.foundation.layout.wrapContentWidth
17
20
import androidx.compose.foundation.lazy.LazyColumn
@@ -31,18 +34,22 @@ import androidx.compose.material.Text
31
34
import androidx.compose.material.TopAppBar
32
35
import androidx.compose.material.icons.Icons
33
36
import androidx.compose.material.icons.filled.Check
37
+ import androidx.compose.material.icons.filled.DateRange
34
38
import androidx.compose.material.icons.filled.Reorder
35
39
import androidx.compose.material.icons.filled.Sort
36
40
import androidx.compose.runtime.Composable
37
41
import androidx.compose.ui.Alignment
38
42
import androidx.compose.ui.Modifier
43
+ import androidx.compose.ui.graphics.Color
39
44
import androidx.compose.ui.graphics.Shape
40
- import androidx.compose.ui.tooling.preview.Preview
41
45
import androidx.compose.ui.unit.dp
42
- import com.hoc081098.datastoresample.domain.usecase.FilteredSortedTasks
43
46
import com.hoc081098.datastoresample.domain.model.SortOrder
44
47
import com.hoc081098.datastoresample.domain.model.Task
45
- import com.hoc081098.datastoresample.ui.theme.DataStoreSampleTheme
48
+ import com.hoc081098.datastoresample.domain.model.TaskPriority
49
+ import com.hoc081098.datastoresample.domain.model.TaskPriority.*
50
+ import com.hoc081098.datastoresample.domain.usecase.FilteredSortedTasks
51
+ import java.text.SimpleDateFormat
52
+ import java.util.*
46
53
47
54
@Composable
48
55
fun MainScreen (
@@ -67,7 +74,7 @@ fun MainScreen(
67
74
}
68
75
)
69
76
},
70
- ) {
77
+ ) { innerPadding ->
71
78
if (state == null ) {
72
79
Column (
73
80
modifier = Modifier
@@ -84,7 +91,10 @@ fun MainScreen(
84
91
.fillMaxHeight()
85
92
.fillMaxWidth(),
86
93
) {
87
- MainTasksList (state.tasks, Modifier .weight(1f ))
94
+ MainTasksList (state.tasks,
95
+ Modifier
96
+ .weight(1f )
97
+ .padding(innerPadding))
88
98
89
99
Row (modifier = Modifier .padding(all = 16 .dp)) {
90
100
Icon (
@@ -145,7 +155,6 @@ fun MainScreen(
145
155
fun MainTasksList (tasks : List <Task >, modifier : Modifier = Modifier ) {
146
156
LazyColumn (
147
157
modifier = modifier,
148
- contentPadding = PaddingValues (all = 8 .dp)
149
158
) {
150
159
items(tasks) { task ->
151
160
TaskRow (task = task)
@@ -156,20 +165,57 @@ fun MainTasksList(tasks: List<Task>, modifier: Modifier = Modifier) {
156
165
}
157
166
}
158
167
168
+ private val TaskPriority .color: Color
169
+ get() {
170
+ return when (this ) {
171
+ HIGH -> Color .Red .copy(alpha = 0.8f )
172
+ MEDIUM -> Color .Magenta .copy(alpha = 0.8f )
173
+ LOW -> Color .Green .copy(alpha = 0.8f )
174
+ }
175
+ }
176
+ private val dateFormat = SimpleDateFormat (" MMM dd, yyyy" , Locale .US )
177
+
159
178
@Composable
160
179
fun TaskRow (task : Task ) {
180
+ val bgColor = if (task.completed) {
181
+ LocalContentColor .current.copy(alpha = 0.1f )
182
+ } else {
183
+ Color .Unspecified
184
+ }
185
+
161
186
Column (
162
187
verticalArrangement = Arrangement .SpaceBetween ,
163
- modifier = Modifier .padding(all = 12 .dp)
188
+ modifier = Modifier
189
+ .fillMaxSize()
190
+ .background(bgColor)
191
+ .padding(all = 12 .dp)
164
192
) {
165
193
Text (
166
194
text = task.name,
167
195
style = MaterialTheme .typography.subtitle1,
168
196
)
197
+ Spacer (modifier = Modifier .requiredHeight(8 .dp))
169
198
Text (
170
- text = " Priority: ${task.priority.name} " ,
171
- style = MaterialTheme .typography.subtitle2,
199
+ text = " Priority ${task.priority.name} " ,
200
+ style = MaterialTheme .typography.subtitle2.copy(
201
+ color = task.priority.color
202
+ ),
172
203
)
204
+ Spacer (modifier = Modifier .requiredHeight(8 .dp))
205
+ Row (
206
+ verticalAlignment = Alignment .CenterVertically
207
+ ) {
208
+ Icon (
209
+ imageVector = Icons .Default .DateRange ,
210
+ contentDescription = null ,
211
+ tint = LocalContentColor .current.copy(alpha = 0.5f ),
212
+ )
213
+ Spacer (modifier = Modifier .requiredWidth(8 .dp))
214
+ Text (
215
+ dateFormat.format(task.deadline),
216
+ style = MaterialTheme .typography.caption,
217
+ )
218
+ }
173
219
}
174
220
}
175
221
@@ -222,17 +268,29 @@ fun SortChip(
222
268
}
223
269
}
224
270
225
- @Preview
226
- @Composable
227
- fun MainScreenPreview () {
228
- DataStoreSampleTheme {
229
- MainScreen (
230
- state = null ,
231
- changeShowCompleted = {},
232
- enableSortByDeadline = {},
233
- enableSortByPriority = {},
234
- lightTheme = false ,
235
- changeTheme = {}
236
- )
237
- }
238
- }
271
+ // @Preview
272
+ // @Composable
273
+ // fun MainScreenPreview() {
274
+ // DataStoreSampleTheme {
275
+ // MainScreen(
276
+ // state = null,
277
+ // changeShowCompleted = {},
278
+ // enableSortByDeadline = {},
279
+ // enableSortByPriority = {},
280
+ // lightTheme = false,
281
+ // changeTheme = {}
282
+ // )
283
+ // }
284
+ // }
285
+ //
286
+ // @Preview
287
+ // @Composable
288
+ // fun TaskRowPreview() {
289
+ // TaskRow(
290
+ // task = Task(
291
+ // name = "Complete graduate project",
292
+ // deadline = Date(),
293
+ // priority = HIGH,
294
+ // ),
295
+ // )
296
+ // }
0 commit comments