mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
car toasts: take turns instead of replacing each other
A new toast waits until the one on screen has had 2 seconds. Repeats restart the visible toast, and a burst keeps only the newest three waiting.
This commit is contained in:
1 parent
75dfaa3013
commit
23f12884da
3 files changed
+75
-9
No files matched your search
@@ -13,15 +13,30 @@ class CarToastsTest {
|
||||
@Before
|
||||
@After
|
||||
fun clearToast() {
|
||||
CarToasts.message.value?.let(CarToasts::dismiss)
|
||||
while (true) CarToasts.message.value?.let(CarToasts::dismiss) ?: break
|
||||
}
|
||||
|
||||
@Test
|
||||
fun expiredToastCannotDismissItsReplacement() {
|
||||
fun aNewToastWaitsForTheOneOnScreen() {
|
||||
val owner = Any()
|
||||
CarToasts.show(owner, "First", CarToast.LENGTH_SHORT)
|
||||
val first = requireNotNull(CarToasts.message.value)
|
||||
CarToasts.show(owner, "Second", CarToast.LENGTH_LONG)
|
||||
|
||||
assertSame(first, CarToasts.message.value)
|
||||
assertEquals(1, CarToasts.waiting.value)
|
||||
CarToasts.dismiss(first)
|
||||
assertEquals("Second", CarToasts.message.value?.text)
|
||||
assertEquals(0, CarToasts.waiting.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun expiredTimerCannotDismissItsReplacement() {
|
||||
val owner = Any()
|
||||
CarToasts.show(owner, "First", CarToast.LENGTH_SHORT)
|
||||
val first = requireNotNull(CarToasts.message.value)
|
||||
CarToasts.show(owner, "Second", CarToast.LENGTH_LONG)
|
||||
CarToasts.dismiss(first)
|
||||
val second = requireNotNull(CarToasts.message.value)
|
||||
|
||||
CarToasts.dismiss(first)
|
||||
@@ -39,6 +54,7 @@ class CarToastsTest {
|
||||
val repeated = requireNotNull(CarToasts.message.value)
|
||||
|
||||
assertNotSame(first, repeated)
|
||||
assertEquals(0, CarToasts.waiting.value)
|
||||
CarToasts.dismiss(first)
|
||||
assertSame(repeated, CarToasts.message.value)
|
||||
}
|
||||
@@ -49,14 +65,24 @@ class CarToastsTest {
|
||||
val browse = Any()
|
||||
CarToasts.show(nav, "Route saved", CarToast.LENGTH_SHORT)
|
||||
CarToasts.show(browse, "Added to playlist", CarToast.LENGTH_SHORT)
|
||||
val latest = CarToasts.message.value
|
||||
|
||||
CarToasts.clear(nav)
|
||||
assertSame(latest, CarToasts.message.value)
|
||||
assertEquals("Added to playlist", CarToasts.message.value?.text)
|
||||
CarToasts.clear(browse)
|
||||
assertNull(CarToasts.message.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aBurstKeepsOnlyTheNewestFewWaiting() {
|
||||
val owner = Any()
|
||||
listOf("1", "2", "3", "4", "5", "6").forEach { CarToasts.show(owner, it, CarToast.LENGTH_SHORT) }
|
||||
|
||||
assertEquals("1", CarToasts.message.value?.text)
|
||||
assertEquals(3, CarToasts.waiting.value)
|
||||
CarToasts.message.value?.let(CarToasts::dismiss)
|
||||
assertEquals("4", CarToasts.message.value?.text)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blankRequestsDoNotReplaceAVisibleMessage() {
|
||||
val owner = Any()
|
||||
@@ -65,6 +91,7 @@ class CarToastsTest {
|
||||
|
||||
CarToasts.show(owner, " \n\t", CarToast.LENGTH_LONG)
|
||||
assertSame(visible, CarToasts.message.value)
|
||||
assertEquals(0, CarToasts.waiting.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,8 +99,10 @@ class CarToastsTest {
|
||||
val owner = Any()
|
||||
CarToasts.show(owner, "Short", CarToast.LENGTH_SHORT)
|
||||
assertEquals(4_000L, CarToasts.message.value?.durationMs)
|
||||
CarToasts.message.value?.let(CarToasts::dismiss)
|
||||
CarToasts.show(owner, "Long", CarToast.LENGTH_LONG)
|
||||
assertEquals(7_000L, CarToasts.message.value?.durationMs)
|
||||
CarToasts.message.value?.let(CarToasts::dismiss)
|
||||
CarToasts.show(owner, "Unknown", Int.MAX_VALUE)
|
||||
assertEquals(4_000L, CarToasts.message.value?.durationMs)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user