@@ -18,30 +18,34 @@ import androidx.compose.foundation.layout.requiredWidth
18
18
import androidx.compose.foundation.layout.width
19
19
import androidx.compose.foundation.layout.wrapContentWidth
20
20
import androidx.compose.foundation.lazy.LazyColumn
21
- import androidx.compose.foundation.lazy.items
21
+ import androidx.compose.foundation.lazy.itemsIndexed
22
22
import androidx.compose.foundation.selection.toggleable
23
23
import androidx.compose.foundation.shape.RoundedCornerShape
24
24
import androidx.compose.material.Checkbox
25
25
import androidx.compose.material.CircularProgressIndicator
26
26
import androidx.compose.material.Divider
27
27
import androidx.compose.material.Icon
28
+ import androidx.compose.material.IconToggleButton
28
29
import androidx.compose.material.LocalContentColor
29
30
import androidx.compose.material.MaterialTheme
30
31
import androidx.compose.material.Scaffold
31
32
import androidx.compose.material.Surface
32
- import androidx.compose.material.Switch
33
33
import androidx.compose.material.Text
34
34
import androidx.compose.material.TopAppBar
35
35
import androidx.compose.material.icons.Icons
36
36
import androidx.compose.material.icons.filled.Check
37
37
import androidx.compose.material.icons.filled.DateRange
38
+ import androidx.compose.material.icons.filled.LightMode
38
39
import androidx.compose.material.icons.filled.Reorder
39
40
import androidx.compose.material.icons.filled.Sort
41
+ import androidx.compose.material.icons.outlined.LightMode
40
42
import androidx.compose.runtime.Composable
41
43
import androidx.compose.ui.Alignment
42
44
import androidx.compose.ui.Modifier
43
45
import androidx.compose.ui.graphics.Color
44
46
import androidx.compose.ui.graphics.Shape
47
+ import androidx.compose.ui.semantics.onClick
48
+ import androidx.compose.ui.semantics.semantics
45
49
import androidx.compose.ui.unit.dp
46
50
import com.hoc081098.datastoresample.domain.model.SortOrder
47
51
import com.hoc081098.datastoresample.domain.model.Task
@@ -67,10 +71,27 @@ fun MainScreen(
67
71
Text (text = " Jetpack DataStore sample" )
68
72
},
69
73
actions = {
70
- Switch (
74
+ IconToggleButton (
71
75
checked = lightTheme,
72
76
onCheckedChange = changeTheme,
73
- )
77
+ modifier = Modifier .semantics {
78
+ // Use a custom click label that accessibility services can communicate to the user.
79
+ // We only want to override the label, not the actual action, so for the action we pass null.
80
+ onClick(
81
+ label = if (lightTheme) " To dark mode" else " To night mode" ,
82
+ action = null
83
+ )
84
+ }
85
+ ) {
86
+ Icon (
87
+ imageVector = if (lightTheme) {
88
+ Icons .Filled .LightMode
89
+ } else {
90
+ Icons .Outlined .LightMode
91
+ },
92
+ contentDescription = null , // handled by click label of parent
93
+ )
94
+ }
74
95
}
75
96
)
76
97
},
@@ -156,11 +177,13 @@ fun MainTasksList(tasks: List<Task>, modifier: Modifier = Modifier) {
156
177
LazyColumn (
157
178
modifier = modifier,
158
179
) {
159
- items (tasks) { task ->
180
+ itemsIndexed (tasks) { index, task ->
160
181
TaskRow (task = task)
161
- Divider (
162
- thickness = 0.7 .dp
163
- )
182
+ if (index < tasks.lastIndex) {
183
+ Divider (
184
+ thickness = 0.7 .dp
185
+ )
186
+ }
164
187
}
165
188
}
166
189
}
@@ -178,7 +201,7 @@ private val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.US)
178
201
@Composable
179
202
fun TaskRow (task : Task ) {
180
203
val bgColor = if (task.completed) {
181
- LocalContentColor .current.copy(alpha = 0.1f )
204
+ LocalContentColor .current.copy(alpha = 0.07f )
182
205
} else {
183
206
Color .Unspecified
184
207
}
0 commit comments