Skip to content

Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.

Logged-out page, snackbar and chip badge for a TV that revokes this phone

jesse-agent-2320b1508b115b0
diff --git a/NOTICE b/NOTICE
index 129c269..180069b 100644
--- a/NOTICE
+++ b/NOTICE
@@ -35,7 +35,8 @@ The access warning, Who has access and Remove all other access use those
of "shield", "gpp_good", "gpp_maybe", "lock_reset", "smartphone", "lan",
"laptop", "desktop_windows" and "help_outline"; the Connected devices card
those of "bluetooth", "headphones", "keyboard", "mouse", "sports_esports",
-"usb", "speaker" and "settings_input_hdmi".
+"usb", "speaker" and "settings_input_hdmi". The logged-out page and the
+logged-out badge on a TV's chip use that of "logout".
--------------------------------------------------------------------------------
Store badges in docs/badges/ (README only, not in the app)
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index da528ba..f7c252c 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -26,6 +26,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
+import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.core.content.ContextCompat
@@ -41,6 +42,8 @@ import app.tellyscope.adb.Connector
import app.tellyscope.adb.StatsProfile
import app.tellyscope.data.AdbDeviceSource
import app.tellyscope.data.AndroidPhoneStorage
+import app.tellyscope.data.Device
+import app.tellyscope.data.DeviceState
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.FoldBook
import app.tellyscope.data.KeyHaptics
@@ -48,24 +51,31 @@ import app.tellyscope.data.UpdateCheck
import app.tellyscope.ui.AccessActions
import app.tellyscope.ui.AccessScreen
import app.tellyscope.ui.AdvancedScreen
+import app.tellyscope.ui.ConnectScreen
import app.tellyscope.ui.Copy
import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceTabsScreen
import app.tellyscope.ui.Done
+import app.tellyscope.ui.LoggedOutScreen
import app.tellyscope.ui.PermissionScreen
import app.tellyscope.ui.RemoteActions
import app.tellyscope.ui.RemoteScreen
import app.tellyscope.ui.ReportKind
import app.tellyscope.ui.ReportScreen
+import app.tellyscope.ui.RowState
import app.tellyscope.ui.ScanScreen
import app.tellyscope.ui.SettingsScreen
import app.tellyscope.ui.TellyscopeViewModel
import app.tellyscope.ui.UpdateDialog
import app.tellyscope.ui.WelcomeScreen
+import app.tellyscope.ui.brands
+import app.tellyscope.ui.connectTitle
+import app.tellyscope.ui.name
import app.tellyscope.ui.theme.TellyscopeTheme
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
+import kotlinx.coroutines.launch
import java.io.File
class MainActivity : ComponentActivity() {
@@ -175,6 +185,9 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
var debloat by rememberSaveable { mutableStateOf(false) }
var settings by rememberSaveable { mutableStateOf(false) }
var access by rememberSaveable { mutableStateOf(false) }
+ // Connect again from the logged-out page: which TV, and since when, for its Allow screen.
+ var rejoinId by rememberSaveable { mutableStateOf<String?>(null) }
+ var rejoinSince by rememberSaveable { mutableStateOf(0L) }
// "*/*": file managers label .apks and .xapk bundles inconsistently, so a narrower type would grey them out.
val pickApp = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { vm.pickedApp(it) }
@@ -190,9 +203,19 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { vm.checkForUpdate() }
Snackbars(snackbar, vm.done, vm.notice, vm::doneShown, vm::noticeShown) { vm.undo(it.entry, it.deviceId) }
+ LoggedOutSnackbars(snackbar, { state.devices }, { state.selectedId }, onView = vm::select)
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
- LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; debloat = false; settings = false; access = false }
+ LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; debloat = false; settings = false; access = false; rejoinId = null }
+ // Logged out mid-screen: the page takes over, and the TV comes back on Overview once allowed again.
+ val loggedOutAt = state.selected?.loggedOutAt
+ LaunchedEffect(loggedOutAt) { if (loggedOutAt != null) { remote = false; advanced = false; debloat = false; settings = false; access = false } }
+ // The Allow screen while the TV is asked; allowed lands on Overview, a Deny there is a plain refusal (its card).
+ val rejoining = state.selected?.takeIf { it.id == rejoinId && it.state == DeviceState.Waiting }
+ LaunchedEffect(state.selected?.state, loggedOutAt) {
+ val st = state.selected?.state
+ if (st == DeviceState.Online || (st == DeviceState.NotAllowed && loggedOutAt == null)) rejoinId = null
+ }
if (state.selected == null || adding) {
BackHandler(enabled = adding) { adding = false }
@@ -211,6 +234,37 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
} else if (state.report != null) {
BackHandler { vm.closeReport() }
state.report?.let { ReportScreen(it, onOpened = vm::reportOpened, close = vm::closeReport) }
+ } else if (rejoining != null) {
+ val cancel = { vm.cancelReconnect(rejoining.id); rejoinId = null }
+ BackHandler(onBack = cancel)
+ ConnectScreen(
+ hit = rejoining.hit,
+ row = RowState.Waiting(rejoinSince),
+ now = state.now,
+ brand = brands.first(),
+ phoneKey = remember { Connector.fingerprint() },
+ onCode = {},
+ onPair = {},
+ onRetry = { vm.reconnect(rejoining.id) },
+ onBack = cancel,
+ title = connectTitle(rejoining),
+ )
+ } else if (state.selected != null && loggedOutAt != null) {
+ val selected = state.selected!!
+ // Back to TVs: another remembered TV, online ones first, else the scan list.
+ val back = {
+ val other = state.devices.filter { it.id != selected.id }
+ val next = other.firstOrNull { it.state == DeviceState.Online } ?: other.firstOrNull()
+ if (next != null) vm.select(next.id) else { adding = true; vm.rescan() }
+ }
+ BackHandler(onBack = back)
+ LoggedOutScreen(
+ device = selected,
+ loggedOutAt = loggedOutAt,
+ now = state.now,
+ onConnect = { rejoinId = selected.id; rejoinSince = System.currentTimeMillis(); vm.reconnect(selected.id) },
+ onBack = back,
+ )
} else if (remote) {
BackHandler { remote = false }
DisposableEffect(Unit) { onDispose { vm.closeRemote() } }
@@ -352,6 +406,29 @@ internal fun Snackbars(
}
}
+/**
+ * A TV logged out while another one is on screen gets one snackbar; View opens its logged-out page.
+ * TVs already logged out at launch get none, their chip badge says it. Read through [devices] and
+ * [selectedId] so the watch outlives each change instead of restarting and cancelling its snackbar.
+ */
+@Composable
+internal fun LoggedOutSnackbars(host: SnackbarHostState, devices: () -> List<Device>, selectedId: () -> String?, onView: (String) -> Unit) {
+ LaunchedEffect(host) {
+ var seen: Set<String>? = null
+ snapshotFlow { devices().filter { it.loggedOutAt != null } }.collect { out ->
+ val ids = out.map { it.id }.toSet()
+ val fresh = seen?.let { before -> out.filter { it.id !in before && it.id != selectedId() } }.orEmpty()
+ seen = ids
+ fresh.forEach { d ->
+ launch {
+ val result = host.showSnackbar(Copy.loggedOutOf(name(d)), actionLabel = "View", duration = SnackbarDuration.Long)
+ if (result == SnackbarResult.ActionPerformed) onView(d.id)
+ }
+ }
+ }
+ }
+}
+
/** The Wi-Fi panel over the app on Android 10+, else the full Wi-Fi settings. */
private fun Context.openWifiSettings() {
val panel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Settings.Panel.ACTION_WIFI else Settings.ACTION_WIFI_SETTINGS
diff --git a/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt b/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt
index b23886b..6f65eec 100644
--- a/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt
@@ -58,6 +58,7 @@ import app.tellyscope.ui.theme.StatNumber
* One TV, one thing at a time: the pairing code, the Allow box on the TV, or why it didn't answer.
* Opened from a found TV's Connect; a successful connect leaves for that TV's Overview on its own.
* [phoneKey] is this phone's fingerprint, shown so it can be checked against the TV's box.
+ * [title] heads a remembered TV by its nickname; a found one goes by its network name.
*/
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
@@ -71,6 +72,7 @@ fun ConnectScreen(
onPair: () -> Unit,
onRetry: () -> Unit,
onBack: () -> Unit,
+ title: String? = null,
) {
Scaffold(
topBar = {
@@ -117,7 +119,7 @@ fun ConnectScreen(
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Icon(DeviceIcons.Tv, null, Modifier.size(18.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
Text(
- listOfNotNull(hit.hostname ?: "Android device", hit.maker).distinct().joinToString(" · "),
+ title ?: listOfNotNull(hit.hostname ?: "Android device", hit.maker).distinct().joinToString(" · "),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index f69622d..a94b105 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -208,6 +208,25 @@ object Copy {
const val WRONG_CODE = "That code didn't work. Check the 6 digits on the TV and try again."
const val UNREACHABLE = "The TV didn't answer. Check it's on and on the same Wi-Fi as this phone, then try again."
const val PAIR_INSTEAD = "The TV didn't let this phone in yet. Pair it once with the code from the TV."
+ const val LOGGED_OUT = "You were logged out"
+ const val LOGGED_OUT_WHY =
+ "The TV removed this phone's access. Tellyscope disconnected and stopped asking, so nothing pops up on the TV until you connect again."
+ val LOGGED_OUT_CAUSES = listOf(
+ "Revoke USB debugging authorisations was chosen on the TV.",
+ "Remove all other access was used from another phone, or from another Tellyscope build on this phone.",
+ )
+ fun loggedOutOf(name: String) = "Logged out of $name"
+
+ /** When the TV took the access back, on the logged-out page. */
+ fun loggedOutAt(at: Long, now: Long): String {
+ val days = ((now - at) / 86_400_000).coerceAtLeast(0)
+ return when {
+ now - at < 5 * 60_000 -> "Logged out just now"
+ days == 0L -> "Logged out today, " + SimpleDateFormat("HH:mm", Locale.getDefault()).format(Date(at))
+ days == 1L -> "Logged out yesterday"
+ else -> "Logged out $days days ago"
+ }
+ }
data class Health(val ok: Boolean, val text: String)
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt b/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt
index 0149efa..0132924 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
-// Tv, Stick and WifiOff are the Material Icons "tv", "settings_input_hdmi" and "wifi_off" (Apache-2.0), see NOTICE.
+// Tv, Stick, WifiOff and Logout are the Material Icons "tv", "settings_input_hdmi", "wifi_off" and "logout" (Apache-2.0), see NOTICE.
package app.tellyscope.ui
@@ -38,11 +38,15 @@ object DeviceIcons {
"M2 3.05L5.07 6.1C3.6 6.82 2.22 7.78 1 9l1.99 2c1.24-1.24 2.67-2.16 4.2-2.77l2.24 2.24C7.81 10.89 6.27 11.73 5 13v.01L6.99 15" +
"c1.36-1.36 3.14-2.04 4.92-2.06L18.98 20l1.27-1.26L3.29 1.79 2 3.05zM9 17l3 3 3-3c-1.65-1.66-4.34-1.66-6 0z"
+ private const val LOGOUT =
+ "M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"
+
val Tv = icon("Tv", TV)
val FireTv = icon("FireTv", FIRE_TV)
val Stick = icon("Stick", STICK)
val Projector = icon("Projector", PROJECTOR)
val WifiOff = icon("WifiOff", WIFI_OFF)
+ val Logout = icon("Logout", LOGOUT)
fun of(kind: DeviceKind) = when (kind) {
DeviceKind.Tv -> Tv
diff --git a/app/src/main/java/app/tellyscope/ui/LoggedOutScreen.kt b/app/src/main/java/app/tellyscope/ui/LoggedOutScreen.kt
new file mode 100644
index 0000000..3d58127
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/LoggedOutScreen.kt
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.navigationBarsPadding
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material3.Button
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import app.tellyscope.data.Device
+
+/** "Projector · XGIMI": the TV's name and maker, as the connect and logged-out pages head them. */
+internal fun connectTitle(d: Device) = listOfNotNull(name(d), d.manufacturer ?: d.hit.maker).distinct().joinToString(" · ")
+
+/**
+ * A TV that had allowed this phone took the access back, so Tellyscope stopped asking. Laid out like
+ * "No answer from the TV"; the same page whether it happened on screen or the app was opened later,
+ * only the time line differs. Connect again leads to the Allow screen; the nickname is kept.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun LoggedOutScreen(device: Device, loggedOutAt: Long, now: Long, onConnect: () -> Unit, onBack: () -> Unit) {
+ Scaffold(
+ topBar = {
+ TopAppBar(
+ title = {},
+ navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } },
+ )
+ },
+ bottomBar = {
+ Row(
+ Modifier.fillMaxWidth().navigationBarsPadding().padding(16.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ TextButton(onClick = onBack) { Text("Back to TVs") }
+ Button(onClick = onConnect) { Text("Connect again") }
+ }
+ },
+ ) { pad ->
+ Column(
+ Modifier.fillMaxSize().padding(pad).verticalScroll(rememberScrollState()).padding(horizontal = 24.dp, vertical = 8.dp),
+ verticalArrangement = Arrangement.spacedBy(20.dp),
+ ) {
+ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ Icon(DeviceIcons.Tv, null, Modifier.size(18.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(connectTitle(device), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ Surface(Modifier.size(64.dp), shape = CircleShape, color = MaterialTheme.colorScheme.errorContainer) {
+ Box(contentAlignment = Alignment.Center) {
+ Icon(DeviceIcons.Logout, null, Modifier.size(32.dp), tint = MaterialTheme.colorScheme.onErrorContainer)
+ }
+ }
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(Copy.LOGGED_OUT, style = MaterialTheme.typography.headlineMedium)
+ Text(Copy.LOGGED_OUT_WHY, style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(Copy.loggedOutAt(loggedOutAt, now), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text("Why this can happen", style = MaterialTheme.typography.titleSmall)
+ Copy.LOGGED_OUT_CAUSES.forEach { Text("• $it", style = MaterialTheme.typography.bodyMedium) }
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/ui/TvHeader.kt b/app/src/main/java/app/tellyscope/ui/TvHeader.kt
index a3ff281..ea903e8 100644
--- a/app/src/main/java/app/tellyscope/ui/TvHeader.kt
+++ b/app/src/main/java/app/tellyscope/ui/TvHeader.kt
@@ -257,7 +257,14 @@ internal fun HeroMorphOverlay(device: Device, morph: HeroMorph, collapse: () ->
}
}
-/** One chip per TV to switch, offline ones dimmed, then "+ Device" as the last chip. */
+@Composable
+private fun LoggedOutBadge() {
+ Box(Modifier.size(14.dp).clip(CircleShape).background(MaterialTheme.colorScheme.error), contentAlignment = Alignment.Center) {
+ Icon(DeviceIcons.Logout, contentDescription = Copy.LOGGED_OUT, Modifier.size(10.dp), tint = MaterialTheme.colorScheme.onError)
+ }
+}
+
+/** One chip per TV to switch, offline ones dimmed (logged-out ones badged instead), then "+ Device" as the last chip. */
@Composable
private fun TvChips(state: UiState, actions: DeviceActions) {
FlowRow(
@@ -273,10 +280,13 @@ private fun TvChips(state: UiState, actions: DeviceActions) {
leadingIcon = {
Box {
Icon(DeviceIcons.of(deviceKind(d)), contentDescription = deviceKind(d).word(), Modifier.size(18.dp))
- Box(Modifier.align(Alignment.BottomEnd).offset(x = 3.dp, y = 3.dp)) { StateDot(d.state) }
+ Box(Modifier.align(Alignment.BottomEnd).offset(x = 3.dp, y = 3.dp)) {
+ // A logged-out TV keeps its badge, so the logout can still be found from another TV.
+ if (d.loggedOutAt != null) LoggedOutBadge() else StateDot(d.state)
+ }
}
},
- modifier = if (d.state == DeviceState.Online) Modifier else Modifier.alpha(0.6f),
+ modifier = if (d.state == DeviceState.Online || d.loggedOutAt != null) Modifier else Modifier.alpha(0.6f),
)
}
// Adding a TV sits with the TVs, as the last chip.
diff --git a/app/src/test/java/app/tellyscope/LoggedOutTest.kt b/app/src/test/java/app/tellyscope/LoggedOutTest.kt
new file mode 100644
index 0000000..95c12b1
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/LoggedOutTest.kt
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.ui.test.junit4.v2.createComposeRule
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.performClick
+import app.tellyscope.data.Device
+import app.tellyscope.data.DeviceState
+import app.tellyscope.data.ScanHit
+import app.tellyscope.data.ScanKind
+import app.tellyscope.ui.Copy
+import app.tellyscope.ui.LoggedOutScreen
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [35])
+class LoggedOutTest {
+ @get:Rule val compose = createComposeRule()
+
+ private fun tv(id: String, nickname: String, loggedOutAt: Long? = null) = Device(
+ id, ScanHit(id, 5555, ScanKind.Classic, id, null), if (loggedOutAt != null) DeviceState.NotAllowed else DeviceState.Online,
+ null, "XGIMI", null, 0L, nickname = nickname, loggedOutAt = loggedOutAt,
+ )
+
+ private val devices = mutableStateOf(listOf(tv("projector", "Projector"), tv("kitchen", "Kitchen")))
+ private var viewed: String? = null
+
+ private fun watch(selected: String) {
+ // The snackbar times out on the test clock, so step it by hand.
+ compose.mainClock.autoAdvance = false
+ compose.setContent {
+ val host = remember { SnackbarHostState() }
+ LoggedOutSnackbars(host, { devices.value }, { selected }, onView = { viewed = it })
+ SnackbarHost(host)
+ }
+ compose.mainClock.advanceTimeBy(100)
+ }
+
+ @Test fun anotherTvLoggingOutSaysSoAndViewOpensIt() {
+ watch(selected = "kitchen")
+ devices.value = listOf(tv("projector", "Projector", loggedOutAt = 1L), tv("kitchen", "Kitchen"))
+ compose.mainClock.advanceTimeBy(1_000)
+ compose.onNodeWithText(Copy.loggedOutOf("Projector")).assertExists()
+ compose.onNodeWithText("View").performClick()
+ compose.mainClock.advanceTimeBy(1_000)
+ assertEquals("projector", viewed)
+ }
+
+ @Test fun theTvOnScreenGetsThePageNotASnackbar() {
+ watch(selected = "projector")
+ devices.value = listOf(tv("projector", "Projector", loggedOutAt = 1L), tv("kitchen", "Kitchen"))
+ compose.mainClock.advanceTimeBy(1_000)
+ compose.onNodeWithText(Copy.loggedOutOf("Projector")).assertDoesNotExist()
+ }
+
+ @Test fun alreadyLoggedOutAtLaunchGetsNoSnackbar() {
+ devices.value = listOf(tv("projector", "Projector", loggedOutAt = 1L), tv("kitchen", "Kitchen"))
+ watch(selected = "kitchen")
+ compose.mainClock.advanceTimeBy(1_000)
+ compose.onNodeWithText(Copy.loggedOutOf("Projector")).assertDoesNotExist()
+ }
+
+ @Test fun connectAgainLeavesThePage() {
+ var connected = false
+ compose.setContent { LoggedOutScreen(tv("projector", "Projector", 1L), loggedOutAt = 1L, now = 2L, onConnect = { connected = true }, onBack = {}) }
+ compose.onNodeWithText("Projector · XGIMI").assertExists()
+ compose.onNodeWithText("Logged out just now").assertExists()
+ compose.onNodeWithText("Connect again").performClick()
+ assertTrue(connected)
+ }
+
+ @Test fun timeLineSaysWhen() {
+ val hour = 3_600_000L
+ assertEquals("Logged out just now", Copy.loggedOutAt(0L, 60_000L))
+ assertEquals("Logged out yesterday", Copy.loggedOutAt(0L, 30 * hour))
+ assertEquals("Logged out 3 days ago", Copy.loggedOutAt(0L, 80 * hour))
+ }
+}