Skip to content

Commit f0b2e77

Browse files
committed
update UI
1 parent 431256b commit f0b2e77

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

app/src/main/java/com/hoc081098/datastoresample/ui/MainScreen.kt

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,34 @@ import androidx.compose.foundation.layout.requiredWidth
1818
import androidx.compose.foundation.layout.width
1919
import androidx.compose.foundation.layout.wrapContentWidth
2020
import androidx.compose.foundation.lazy.LazyColumn
21-
import androidx.compose.foundation.lazy.items
21+
import androidx.compose.foundation.lazy.itemsIndexed
2222
import androidx.compose.foundation.selection.toggleable
2323
import androidx.compose.foundation.shape.RoundedCornerShape
2424
import androidx.compose.material.Checkbox
2525
import androidx.compose.material.CircularProgressIndicator
2626
import androidx.compose.material.Divider
2727
import androidx.compose.material.Icon
28+
import androidx.compose.material.IconToggleButton
2829
import androidx.compose.material.LocalContentColor
2930
import androidx.compose.material.MaterialTheme
3031
import androidx.compose.material.Scaffold
3132
import androidx.compose.material.Surface
32-
import androidx.compose.material.Switch
3333
import androidx.compose.material.Text
3434
import androidx.compose.material.TopAppBar
3535
import androidx.compose.material.icons.Icons
3636
import androidx.compose.material.icons.filled.Check
3737
import androidx.compose.material.icons.filled.DateRange
38+
import androidx.compose.material.icons.filled.LightMode
3839
import androidx.compose.material.icons.filled.Reorder
3940
import androidx.compose.material.icons.filled.Sort
41+
import androidx.compose.material.icons.outlined.LightMode
4042
import androidx.compose.runtime.Composable
4143
import androidx.compose.ui.Alignment
4244
import androidx.compose.ui.Modifier
4345
import androidx.compose.ui.graphics.Color
4446
import androidx.compose.ui.graphics.Shape
47+
import androidx.compose.ui.semantics.onClick
48+
import androidx.compose.ui.semantics.semantics
4549
import androidx.compose.ui.unit.dp
4650
import com.hoc081098.datastoresample.domain.model.SortOrder
4751
import 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
179202
fun 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

Comments
 (0)