@@ -18,30 +18,34 @@ import androidx.compose.foundation.layout.requiredWidth
1818import androidx.compose.foundation.layout.width
1919import androidx.compose.foundation.layout.wrapContentWidth
2020import androidx.compose.foundation.lazy.LazyColumn
21- import androidx.compose.foundation.lazy.items
21+ import androidx.compose.foundation.lazy.itemsIndexed
2222import androidx.compose.foundation.selection.toggleable
2323import androidx.compose.foundation.shape.RoundedCornerShape
2424import androidx.compose.material.Checkbox
2525import androidx.compose.material.CircularProgressIndicator
2626import androidx.compose.material.Divider
2727import androidx.compose.material.Icon
28+ import androidx.compose.material.IconToggleButton
2829import androidx.compose.material.LocalContentColor
2930import androidx.compose.material.MaterialTheme
3031import androidx.compose.material.Scaffold
3132import androidx.compose.material.Surface
32- import androidx.compose.material.Switch
3333import androidx.compose.material.Text
3434import androidx.compose.material.TopAppBar
3535import androidx.compose.material.icons.Icons
3636import androidx.compose.material.icons.filled.Check
3737import androidx.compose.material.icons.filled.DateRange
38+ import androidx.compose.material.icons.filled.LightMode
3839import androidx.compose.material.icons.filled.Reorder
3940import androidx.compose.material.icons.filled.Sort
41+ import androidx.compose.material.icons.outlined.LightMode
4042import androidx.compose.runtime.Composable
4143import androidx.compose.ui.Alignment
4244import androidx.compose.ui.Modifier
4345import androidx.compose.ui.graphics.Color
4446import androidx.compose.ui.graphics.Shape
47+ import androidx.compose.ui.semantics.onClick
48+ import androidx.compose.ui.semantics.semantics
4549import androidx.compose.ui.unit.dp
4650import com.hoc081098.datastoresample.domain.model.SortOrder
4751import com.hoc081098.datastoresample.domain.model.Task
@@ -67,10 +71,27 @@ fun MainScreen(
6771 Text (text = " Jetpack DataStore sample" )
6872 },
6973 actions = {
70- Switch (
74+ IconToggleButton (
7175 checked = lightTheme,
7276 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+ }
7495 }
7596 )
7697 },
@@ -156,11 +177,13 @@ fun MainTasksList(tasks: List<Task>, modifier: Modifier = Modifier) {
156177 LazyColumn (
157178 modifier = modifier,
158179 ) {
159- items (tasks) { task ->
180+ itemsIndexed (tasks) { index, task ->
160181 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+ }
164187 }
165188 }
166189}
@@ -178,7 +201,7 @@ private val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.US)
178201@Composable
179202fun TaskRow (task : Task ) {
180203 val bgColor = if (task.completed) {
181- LocalContentColor .current.copy(alpha = 0.1f )
204+ LocalContentColor .current.copy(alpha = 0.07f )
182205 } else {
183206 Color .Unspecified
184207 }
0 commit comments