@@ -9,6 +9,7 @@ import androidx.compose.animation.core.tween
9
9
import androidx.compose.foundation.background
10
10
import androidx.compose.foundation.layout.Arrangement
11
11
import androidx.compose.foundation.layout.Box
12
+ import androidx.compose.foundation.layout.BoxWithConstraints
12
13
import androidx.compose.foundation.layout.Column
13
14
import androidx.compose.foundation.layout.Row
14
15
import androidx.compose.foundation.layout.fillMaxSize
@@ -27,7 +28,9 @@ import androidx.compose.runtime.Composable
27
28
import androidx.compose.runtime.getValue
28
29
import androidx.compose.ui.Alignment
29
30
import androidx.compose.ui.Modifier
31
+ import androidx.compose.ui.graphics.Color
30
32
import androidx.compose.ui.text.TextStyle
33
+ import androidx.compose.ui.unit.TextUnit
31
34
import androidx.compose.ui.unit.dp
32
35
import androidx.compose.ui.unit.sp
33
36
import com.jdamcd.arrivals.Arrival
@@ -64,23 +67,28 @@ private fun Loading() {
64
67
@Composable
65
68
private fun Data (state : ArrivalsState .Data , onClickRefresh : () -> Unit ) {
66
69
Column {
67
- Column (
68
- modifier = Modifier
69
- .padding(top = 20 .dp, bottom = 8 .dp, start = 32 .dp, end = 32 .dp)
70
- .weight(1f )
71
- .fillMaxWidth(),
72
- verticalArrangement = Arrangement .SpaceEvenly
70
+ BoxWithConstraints (
71
+ modifier = Modifier .weight(1f )
72
+ .padding(top = 16 .dp, bottom = 8 .dp, start = 32 .dp, end = 32 .dp)
73
73
) {
74
- state.result.arrivals.forEach {
75
- ArrivalRow (it)
74
+ val rowHeight = maxHeight / 3
75
+ val textSize = (rowHeight * textScale).value.sp
76
+
77
+ Column (
78
+ modifier = Modifier .fillMaxSize(),
79
+ verticalArrangement = Arrangement .SpaceEvenly
80
+ ) {
81
+ state.result.arrivals.forEach {
82
+ ArrivalRow (it, textSize)
83
+ }
76
84
}
77
85
}
78
86
Row (
79
87
modifier = Modifier
80
88
.background(color = Footer )
81
89
.padding(start = 32 .dp, end = 28 .dp)
82
90
.fillMaxWidth()
83
- .height(70 .dp ),
91
+ .height(footerHeight ),
84
92
horizontalArrangement = Arrangement .SpaceBetween ,
85
93
verticalAlignment = Alignment .CenterVertically
86
94
) {
@@ -121,46 +129,52 @@ private fun Data(state: ArrivalsState.Data, onClickRefresh: () -> Unit) {
121
129
122
130
@Composable
123
131
fun Error (message : String ) {
124
- Column (
125
- modifier = Modifier
126
- .padding(32 .dp)
127
- .fillMaxWidth(),
128
- verticalArrangement = Arrangement .spacedBy(32 .dp)
132
+ BoxWithConstraints (
133
+ modifier = Modifier .fillMaxSize()
134
+ .padding(top = 16 .dp, bottom = 8 .dp, start = 32 .dp, end = 32 .dp)
129
135
) {
130
- LedText (message)
136
+ val rowHeight = (maxHeight - footerHeight) / 3 // Match text size in Data composable
137
+ val textSize = (rowHeight * textScale).value.sp
138
+
139
+ Column (
140
+ modifier = Modifier .fillMaxSize(),
141
+ verticalArrangement = Arrangement .SpaceEvenly
142
+ ) {
143
+ LedText (message, textSize)
144
+ }
131
145
}
132
146
}
133
147
134
148
@Composable
135
- fun ArrivalRow (arrival : Arrival ) {
149
+ fun ArrivalRow (arrival : Arrival , textSize : TextUnit ) {
136
150
Row (
137
151
horizontalArrangement = Arrangement .SpaceBetween ,
138
152
modifier = Modifier .fillMaxWidth()
139
153
) {
140
- LedText (arrival.destination)
154
+ LedText (arrival.destination, textSize )
141
155
if (arrival.secondsToStop < 60 ) {
142
- FlashingLedText (arrival.time)
156
+ FlashingLedText (arrival.time, textSize )
143
157
} else {
144
- LedText (arrival.time)
158
+ LedText (arrival.time, textSize )
145
159
}
146
160
}
147
161
}
148
162
149
163
@Composable
150
- fun LedText (string : String ) {
164
+ fun LedText (string : String , textSize : TextUnit , color : Color = LedYellow ) {
151
165
Text (
152
166
text = string,
153
- color = LedYellow ,
167
+ color = color ,
154
168
maxLines = 1 ,
155
169
style = TextStyle (
156
170
fontFamily = LurFontFamily ,
157
- fontSize = 58 .sp
171
+ fontSize = textSize
158
172
)
159
173
)
160
174
}
161
175
162
176
@Composable
163
- fun FlashingLedText (string : String ) {
177
+ fun FlashingLedText (string : String , textSize : TextUnit ) {
164
178
val infiniteTransition = rememberInfiniteTransition()
165
179
val alpha by infiniteTransition.animateFloat(
166
180
initialValue = 0f ,
@@ -170,13 +184,8 @@ fun FlashingLedText(string: String) {
170
184
repeatMode = RepeatMode .Reverse
171
185
)
172
186
)
173
- Text (
174
- text = string,
175
- color = LedYellow .copy(alpha = alpha),
176
- maxLines = 1 ,
177
- style = TextStyle (
178
- fontFamily = LurFontFamily ,
179
- fontSize = 58 .sp
180
- )
181
- )
187
+ LedText (string, textSize, LedYellow .copy(alpha = alpha))
182
188
}
189
+
190
+ private val textScale = 0.6f
191
+ private val footerHeight = 70 .dp
0 commit comments