<lambda>null1 package com.android.systemui.shade.ui.composable
2 
3 import androidx.compose.material3.MaterialTheme
4 import androidx.compose.material3.Text
5 import androidx.compose.runtime.Composable
6 import androidx.compose.ui.Modifier
7 import androidx.compose.ui.layout.Layout
8 import androidx.lifecycle.compose.collectAsStateWithLifecycle
9 import com.android.systemui.shade.ui.composable.ShadeHeader.Colors.shadeHeaderText
10 import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
11 
12 @Composable
13 fun VariableDayDate(
14     viewModel: ShadeHeaderViewModel,
15     modifier: Modifier = Modifier,
16 ) {
17     val longerText = viewModel.longerDateText.collectAsStateWithLifecycle()
18     val shorterText = viewModel.shorterDateText.collectAsStateWithLifecycle()
19 
20     Layout(
21         contents =
22             listOf(
23                 {
24                     Text(
25                         text = longerText.value,
26                         style = MaterialTheme.typography.bodyMedium,
27                         color = MaterialTheme.colorScheme.shadeHeaderText,
28                         maxLines = 1,
29                     )
30                 },
31                 {
32                     Text(
33                         text = shorterText.value,
34                         style = MaterialTheme.typography.bodyMedium,
35                         color = MaterialTheme.colorScheme.shadeHeaderText,
36                         maxLines = 1,
37                     )
38                 },
39             ),
40         modifier = modifier,
41     ) { measureables, constraints ->
42         check(measureables.size == 2)
43         check(measureables[0].size == 1)
44         check(measureables[1].size == 1)
45 
46         val longerMeasurable = measureables[0][0]
47         val shorterMeasurable = measureables[1][0]
48 
49         val longerPlaceable = longerMeasurable.measure(constraints)
50         val shorterPlaceable = shorterMeasurable.measure(constraints)
51 
52         // If width < maxWidth (and not <=), we can assume that the text fits.
53         val placeable =
54             when {
55                 longerPlaceable.width < constraints.maxWidth &&
56                     longerPlaceable.height <= constraints.maxHeight -> longerPlaceable
57                 shorterPlaceable.width < constraints.maxWidth &&
58                     shorterPlaceable.height <= constraints.maxHeight -> shorterPlaceable
59                 else -> null
60             }
61 
62         layout(placeable?.width ?: 0, placeable?.height ?: 0) { placeable?.placeRelative(0, 0) }
63     }
64 }
65