mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
car toasts: match the message popup and stay up longer
A driver only glances at the screen, so short toasts now last 4 seconds and long ones 7. The card uses the popup's colours, which read better over a map.
This commit is contained in:
1 parent
006823232d
commit
179a51ea25
3 files changed
+10
-8
No files matched your search
@@ -4,6 +4,7 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -39,15 +40,15 @@ internal fun CarToastOverlay(modifier: Modifier = Modifier) {
|
||||
modifier
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
.widthIn(max = 560.dp)
|
||||
.clip(MaterialTheme.shapes.medium)
|
||||
.background(MaterialTheme.colorScheme.inverseSurface)
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHigh)
|
||||
.semantics { liveRegion = LiveRegionMode.Polite },
|
||||
) {
|
||||
Text(
|
||||
message.text,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp),
|
||||
color = MaterialTheme.colorScheme.inverseOnSurface,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 3,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
|
||||
@@ -17,7 +17,8 @@ internal object CarToasts {
|
||||
|
||||
fun show(owner: Any, text: String, duration: Int) {
|
||||
if (text.isBlank()) return
|
||||
val durationMs = if (duration == CarToast.LENGTH_LONG) 3_500L else 2_000L
|
||||
// Longer than a phone toast: the driver only glances at the screen now and then.
|
||||
val durationMs = if (duration == CarToast.LENGTH_LONG) 7_000L else 4_000L
|
||||
current.value = Message(owner, text, durationMs)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,10 @@ class CarToastsTest {
|
||||
fun unknownDurationsFallBackToShortRatherThanStayingVisible() {
|
||||
val owner = Any()
|
||||
CarToasts.show(owner, "Short", CarToast.LENGTH_SHORT)
|
||||
assertEquals(2_000L, CarToasts.message.value?.durationMs)
|
||||
assertEquals(4_000L, CarToasts.message.value?.durationMs)
|
||||
CarToasts.show(owner, "Long", CarToast.LENGTH_LONG)
|
||||
assertEquals(3_500L, CarToasts.message.value?.durationMs)
|
||||
assertEquals(7_000L, CarToasts.message.value?.durationMs)
|
||||
CarToasts.show(owner, "Unknown", Int.MAX_VALUE)
|
||||
assertEquals(2_000L, CarToasts.message.value?.durationMs)
|
||||
assertEquals(4_000L, CarToasts.message.value?.durationMs)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user