@@ -6,35 +6,33 @@ import androidx.compose.foundation.layout.Column
6
6
import androidx.compose.foundation.layout.PaddingValues
7
7
import androidx.compose.foundation.layout.Row
8
8
import androidx.compose.foundation.layout.Spacer
9
- import androidx.compose.foundation.layout.fillMaxHeight
10
9
import androidx.compose.foundation.layout.padding
11
10
import androidx.compose.foundation.layout.preferredSize
12
11
import androidx.compose.foundation.layout.width
13
12
import androidx.compose.foundation.lazy.LazyColumn
14
13
import androidx.compose.foundation.lazy.items
15
14
import androidx.compose.material.Checkbox
15
+ import androidx.compose.material.CircularProgressIndicator
16
16
import androidx.compose.material.Divider
17
17
import androidx.compose.material.MaterialTheme
18
18
import androidx.compose.material.Scaffold
19
19
import androidx.compose.material.Text
20
20
import androidx.compose.material.TopAppBar
21
21
import androidx.compose.runtime.Composable
22
- import androidx.compose.runtime.getValue
23
22
import androidx.compose.ui.Modifier
24
23
import androidx.compose.ui.res.painterResource
25
24
import androidx.compose.ui.tooling.preview.Preview
26
25
import androidx.compose.ui.unit.dp
27
- import androidx.lifecycle.viewmodel.compose.viewModel
28
- import com.hoc081098.datastoresample.Locator
29
26
import com.hoc081098.datastoresample.R
27
+ import com.hoc081098.datastoresample.domain.FilteredSortedTasks
30
28
import com.hoc081098.datastoresample.domain.Task
31
29
import com.hoc081098.datastoresample.ui.theme.DataStoreSampleTheme
32
30
33
31
@Composable
34
- fun MainScreen () {
35
- val viewModel = viewModel< MainViewModel >(factory = Locator .mainViewModelFactory)
36
- val state by viewModel.state
37
-
32
+ fun MainScreen (
33
+ state : FilteredSortedTasks ? ,
34
+ changeShowCompleted : ( Boolean ) -> Unit ,
35
+ ) {
38
36
Scaffold (
39
37
topBar = {
40
38
TopAppBar (
@@ -44,22 +42,26 @@ fun MainScreen() {
44
42
)
45
43
}
46
44
) {
47
- Column {
48
- // MainTasksList(state.tasks)
45
+ if (state == null ) {
46
+ CircularProgressIndicator ()
47
+ } else {
48
+ Column {
49
+ MainTasksList (state.tasks)
49
50
50
- Row (modifier = Modifier .padding(all = 32 .dp).wraps ) {
51
- Image (
52
- painter = painterResource(id = R .drawable.ic_baseline_filter_list_24),
53
- contentDescription = null ,
54
- modifier = Modifier .preferredSize(24 .dp),
55
- )
51
+ Row (modifier = Modifier .padding(all = 32 .dp)) {
52
+ Image (
53
+ painter = painterResource(id = R .drawable.ic_baseline_filter_list_24),
54
+ contentDescription = null ,
55
+ modifier = Modifier .preferredSize(24 .dp),
56
+ )
56
57
57
- Spacer (modifier = Modifier .width(16 .dp))
58
+ Spacer (modifier = Modifier .width(16 .dp))
58
59
59
- Checkbox (
60
- checked = state.showCompleted,
61
- onCheckedChange = { viewModel.changeShowCompleted(it) }
62
- )
60
+ Checkbox (
61
+ checked = state.showCompleted,
62
+ onCheckedChange = { changeShowCompleted(it) }
63
+ )
64
+ }
63
65
}
64
66
}
65
67
}
@@ -98,82 +100,10 @@ fun TaskRow(task: Task) {
98
100
@Preview
99
101
@Composable
100
102
fun MainScreenPreview () {
101
- /* val simpleDateFormat = SimpleDateFormat("dd-MM-yyyy", Locale.getDefault())
102
- fun parseDate(date: String? = null): Date = date?.let(simpleDateFormat::parse) ?: Date()
103
- val tasks = listOf(
104
- Task(
105
- name = "Complete graduate project",
106
- deadline = parseDate("25-12-2020"),
107
- priority = TaskPriority.HIGH,
108
- ),
109
- Task(
110
- name = "Learning Jetpack Compose",
111
- deadline = parseDate("01-01-2021"),
112
- priority = TaskPriority.MEDIUM,
113
- ),
114
- Task(
115
- name = "Learning NestJs",
116
- deadline = parseDate("02-01-2021"),
117
- priority = TaskPriority.LOW,
118
- ),
119
- Task(
120
- name = "Learn about Polymer",
121
- deadline = parseDate("10-10-2020"),
122
- priority = TaskPriority.LOW,
123
- ),
124
- Task(
125
- name = "Learning Functional programming with Λrrow",
126
- deadline = parseDate("01-01-2022"),
127
- priority = TaskPriority.MEDIUM,
128
- ),
129
- Task(
130
- name = "Learning Functional programming with Bow Swift",
131
- deadline = parseDate("01-01-2022"),
132
- priority = TaskPriority.MEDIUM,
133
- ),
134
- Task(
135
- name = "Understand how to migrate to DataStore",
136
- deadline = parseDate(),
137
- priority = TaskPriority.HIGH,
138
- ),
139
- Task(
140
- name = "Complete graduate project",
141
- deadline = parseDate("25-12-2020"),
142
- priority = TaskPriority.HIGH,
143
- ),
144
- Task(
145
- name = "Learning Jetpack Compose",
146
- deadline = parseDate("01-01-2021"),
147
- priority = TaskPriority.MEDIUM,
148
- ),
149
- Task(
150
- name = "Learning NestJs",
151
- deadline = parseDate("02-01-2021"),
152
- priority = TaskPriority.LOW,
153
- ),
154
- Task(
155
- name = "Learn about Polymer",
156
- deadline = parseDate("10-10-2020"),
157
- priority = TaskPriority.LOW,
158
- ),
159
- Task(
160
- name = "Learning Functional programming with Λrrow",
161
- deadline = parseDate("01-01-2022"),
162
- priority = TaskPriority.MEDIUM,
163
- ),
164
- Task(
165
- name = "Learning Functional programming with Bow Swift",
166
- deadline = parseDate("01-01-2022"),
167
- priority = TaskPriority.MEDIUM,
168
- ),
169
- Task(
170
- name = "Understand how to migrate to DataStore",
171
- deadline = parseDate(),
172
- priority = TaskPriority.HIGH,
173
- )
174
- )*/
175
-
176
103
DataStoreSampleTheme {
177
- MainScreen ()
104
+ MainScreen (
105
+ null ,
106
+ {},
107
+ )
178
108
}
179
109
}
0 commit comments