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.

Remote: an app dock, and Restart moves to the top bar

jesse-agent-23213eba3c9a957
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc566df..57c1bc3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ until this file has a section for its version.
## Unreleased
+- **New:** Dock up to four apps on the Remote, one tap to open. [#PR](../../pull/PR)
+- **Improved:** Restart TV sits in the Remote's top bar and waits with you. [#PR](../../pull/PR)
+- **Improved:** Sleep and Menu leave the Remote, making room for the dock. [#PR](../../pull/PR)
+
## 0.7.0 — 2026-10-25
- **New:** The Remote is back, and keys land in about 50 ms. [#111](../../pull/111)
diff --git a/NOTICE b/NOTICE
index 7970ba7..4e7f350 100644
--- a/NOTICE
+++ b/NOTICE
@@ -26,7 +26,9 @@ The TV and HDMI (streaming stick) device icons use the path data of the
"cleaning_services", the off-Wi-Fi screen that of "wifi_off", and the
Apps, Files and Tweaks tabs those of "apps", "folder" and "tune", the
Upload files button that of "upload", the empty Movies folder that of
-"movie", and the links in Settings that of "open_in_new".
+"movie", the links in Settings that of "open_in_new", and the Remote's
+restart, waiting, can't-reach and dock menu icons those of "restart_alt",
+"hourglass_top", "link_off", "swap_horiz" and "remove_circle_outline".
--------------------------------------------------------------------------------
cleanyourtv — https://github.com/Gathin23/cleanyourtv
diff --git a/README.md b/README.md
index f1bfac6..dec90a9 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,7 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
- **TV tweaks.** **Block ads with Private DNS** sends the TV's address lookups to an ad-blocking DNS provider (AdGuard by default, or any other you type in). Tellyscope then checks the TV can still look addresses up, and puts the old setting back if not. It needs Android 9 or newer. **Faster animations** makes menus move at twice the speed. Both land in History with an Undo. **Clear caches** frees space by clearing every app's temporary files; app data and sign-ins stay. **Take screenshot** saves what the TV shows to your phone.
- **Connection requests.** When another device asks to debug the TV, Tellyscope shows the TV's "Allow debugging?" prompt on your phone, with the device's key fingerprint, so you can **Allow** or **Deny** it without the remote. **Always allow this device** appears when the TV's own prompt offers it.
- **Files.** Send a file from your phone into the TV's Download or Movies folder, or save one from there to your phone. Two buttons under the TV pick the folder, and stay pinned under the bar as you scroll. An empty folder says so in the middle of the page. A file with the same name gets a " (1)" instead of being overwritten, and a cancelled copy leaves nothing half-written behind.
+- **Remote.** A D-pad, Back, Home, volume, Play/Pause and typing on the TV. **Add to dock** puts up to four of the TV's apps under Back and Home, each one tap from opening on the TV. Long-press one to change or remove it, or keep holding and move it to reorder. An app uninstalled from the TV leaves the dock by itself, and a snackbar says so. The restart button in the top bar asks first, then waits for the TV to come back: **Hide** keeps the wait in the top bar, and after a minute **Retry** waits another one.
## Setting up your TV
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
index 0c52c08..4d5b75f 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
@@ -132,6 +132,10 @@ class Actions(private val shell: AdbShell) {
return currentHome()?.substringBefore('/') == activity.substringBefore('/')
}
+ /** Packages the TV can open from a launcher icon; null when it didn't say (no `cmd` before Android 7). */
+ suspend fun launchable(): Set<String>? =
+ packagesIn(shell.shell(Commands.LAUNCHABLE).output).ifEmpty { null }
+
/** [pkg]'s accessibility service as the TV has it installed; null when it has none. */
suspend fun homeService(pkg: String): String? =
activitiesIn(shell.shell(Commands.A11Y_SERVICES).output).firstOrNull { it.substringBefore('/') == pkg }
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
index 82ded1e..89d5833 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
@@ -43,6 +43,10 @@ internal object Commands {
const val HOME_ACTIVITY = "cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME"
const val SET_HOME = "cmd package set-home-activity --user 0"
const val HOME_ACTIVITIES = "cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.HOME"
+ /** Apps with an icon on a TV home screen, then those with one on a phone's; some TVs list only one kind. */
+ const val LAUNCHABLE =
+ "cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LEANBACK_LAUNCHER 2>/dev/null; " +
+ "cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 2>/dev/null"
const val A11Y_SERVICES = "cmd package query-services --brief -a android.accessibilityservice.AccessibilityService"
const val A11Y_ON = "settings get secure enabled_accessibility_services"
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
index 7ec79d0..6c20927 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
@@ -15,13 +15,10 @@ enum class RemoteKey(val code: Int, val repeats: Boolean = false) {
OK(23),
BACK(4),
HOME(3),
- MENU(82),
PLAY_PAUSE(85),
VOLUME_UP(24, repeats = true),
VOLUME_DOWN(25, repeats = true),
MUTE(164),
- /** Sleep, not the power toggle: pressing it twice never wakes a TV the user meant to turn off. */
- SLEEP(223),
}
class Remote(private val session: AdbSession, private val keys: KeyHelper? = null) {
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
index 23ba785..72954f9 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
@@ -277,4 +277,19 @@ class ActionsTest {
assertTrue(Actions(sh).homeBack("com.google.android.tvlauncher", "com.google.android.tvlauncher/.MainActivity") is HomeResult.Failed)
assertTrue(Actions(sh).homeBack("com.spocky.projengmenu") is HomeResult.Failed) // already Home
}
+
+ @Test fun launchableListsEveryAppWithALauncherIcon() = runTest {
+ val sh = FakeShell(mapOf("cmd package query-activities" to ok(
+ "priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false\n" +
+ "com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity\n" +
+ "org.jellyfin.androidtv/.ui.startup.StartupActivity\n" +
+ "org.jellyfin.androidtv/.ui.startup.StartupActivity\n",
+ )))
+ assertEquals(setOf("com.google.android.youtube.tv", "org.jellyfin.androidtv"), Actions(sh).launchable())
+ }
+
+ @Test fun launchableIsUnknownWithoutCmd() = runTest {
+ val sh = FakeShell(mapOf("cmd package" to ShellResult("", 127)))
+ assertEquals(null, Actions(sh).launchable())
+ }
}
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
index e444a19..d77f978 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
@@ -15,8 +15,8 @@ class RemoteTest {
@Test fun keysSendTheirCode() = runTest {
val sh = FakeShell()
assertTrue(Remote(sh).press(RemoteKey.DOWN))
- assertTrue(Remote(sh).press(RemoteKey.SLEEP))
- assertEquals(listOf("input keyevent 20", "input keyevent 223"), sh.ran)
+ assertTrue(Remote(sh).press(RemoteKey.MUTE))
+ assertEquals(listOf("input keyevent 20", "input keyevent 164"), sh.ran)
}
@Test fun keysGoThroughTheHelperWhileItRuns() = runBlocking { // see KeyHelperTest
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 0d9f453..0d07e03 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -208,6 +208,10 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
type = vm::type,
reboot = vm::reboot,
back = { remote = false },
+ retryRestart = vm::retryRestart,
+ stopWaiting = vm::stopWaiting,
+ launch = vm::launch,
+ setDock = vm::setDock,
),
)
} else if (advanced) {
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 049e92f..6858d52 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -91,6 +91,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
private val pairingPorts = ConcurrentHashMap<String, Int>()
private val book = HistoryBook(File(appContext.filesDir, "history.tsv"))
private val names = NameBook(File(appContext.filesDir, "names.tsv"))
+ private val docks = DockBook(File(appContext.filesDir, "docks.tsv"))
/** Last label seen per package, so history entries read like the app list. */
private val labels = ConcurrentHashMap<String, String>()
/** The remote's key helper on each TV, while the remote is open. */
@@ -332,6 +333,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {
val system = Parsers.packages(shell.shell("pm list packages -s").output).map { it.name }.toSet()
val disabled = Parsers.packages(shell.shell("pm list packages -d").output).map { it.name }.toSet()
val userInstalled = Parsers.packages(shell.shell("pm list packages -3").output).map { it.name }.toSet()
+ // Before Android 7 there's no asking which apps have an icon; the ones the user installed do.
+ val launchable = Actions(shell).launchable() ?: userInstalled
// Older pm rejects --show-versioncode and prints no packages; list again without it.
val listed = Parsers.packages(shell.shell("pm list packages --show-versioncode").output)
.ifEmpty { Parsers.packages(shell.shell("pm list packages").output) }
@@ -365,6 +368,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
homeBack = back?.takeIf { p.name == homeOptions?.current }?.let { names[it.pkg]?.label ?: AppNames.fallback(it.pkg) },
homeService = p.name in serviceLaunchers,
listKeep = p.name in keep,
+ launchable = p.name in launchable,
)
}.sortedBy { it.label.lowercase() }
}
@@ -596,6 +600,19 @@ class AdbDeviceSource(context: Context) : DeviceSource {
override suspend fun openUpdates(deviceId: String) = Remote(session(deviceId)).openUpdates()
+ override suspend fun launch(deviceId: String, packageName: String) =
+ busy(deviceId) { Actions(session(deviceId)).run(AdbAction.OPEN, packageName) is ActionResult.Done }
+
+ override suspend fun dock(deviceId: String): List<Docked> {
+ restored.await()
+ return docks[key(deviceId)]
+ }
+
+ override suspend fun setDock(deviceId: String, dock: List<Docked>) {
+ restored.await()
+ docks.set(key(deviceId), dock)
+ }
+
override suspend fun tweaks(deviceId: String): TvTweaks {
val t = Tweaks(session(deviceId))
return TvSettings.tweaks(t.read(Tweak.PRIVATE_DNS), t.read(Tweak.ANIMATIONS), sdk(deviceId))
@@ -657,6 +674,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
if (keys.put(deviceId, key) != key) {
book.rekey(deviceId, key)
names.rekey(deviceId, key)
+ docks.rekey(deviceId, key)
remember(deviceId)
}
return key
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index 8d15393..ee615cd 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -122,6 +122,14 @@ interface DeviceSource {
/** Restarts the TV. The link drops and reconnects on its own once the TV is back. False if the TV refused. */
suspend fun reboot(deviceId: String): Boolean
+ /** Opens [packageName] on the TV, the way its launcher icon would. False when it has nothing to open. Not history. */
+ suspend fun launch(deviceId: String, packageName: String): Boolean
+
+ /** The Remote's dock for this TV, kept on the phone so it shows while the TV is off. */
+ suspend fun dock(deviceId: String): List<Docked>
+
+ suspend fun setDock(deviceId: String, dock: List<Docked>)
+
/** Opens the TV's system update screen on the TV. False when the TV has no such screen. */
suspend fun openUpdates(deviceId: String): Boolean
diff --git a/app/src/main/java/app/tellyscope/data/DockBook.kt b/app/src/main/java/app/tellyscope/data/DockBook.kt
new file mode 100644
index 0000000..5b4b4b4
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/data/DockBook.kt
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.data
+
+import java.io.File
+
+/**
+ * The apps on each TV's Remote dock, in order, keyed like [NameBook] so the dock follows the TV
+ * across DHCP changes. `key \t package \t label` per line; null file keeps it in memory (tests,
+ * the fake source).
+ */
+class DockBook(private val file: File? = null) {
+ private val docks = linkedMapOf<String, List<Docked>>()
+
+ init {
+ file?.takeIf { it.exists() }?.let { f ->
+ runCatching { f.readLines() }.getOrDefault(emptyList()).forEach { line ->
+ val (k, pkg, label) = line.split('\t').takeIf { it.size == 3 && it.none(String::isBlank) } ?: return@forEach
+ docks[k] = docks[k].orEmpty() + Docked(pkg, label)
+ }
+ }
+ }
+
+ @Synchronized
+ operator fun get(key: String): List<Docked> = docks[key].orEmpty()
+
+ @Synchronized
+ fun set(key: String, dock: List<Docked>) {
+ val clean = dock.map { it.copy(label = it.label.replace(Regex("[\\t\\r\\n]"), " ").trim()) }
+ .distinctBy { it.packageName }.take(Dock.MAX)
+ if (clean.isEmpty()) docks.remove(key) else docks[key] = clean
+ save()
+ }
+
+ /** The address stood in until the TV said who it is; the dock moves to the real key. */
+ @Synchronized
+ fun rekey(from: String, to: String) {
+ if (from == to) return
+ val dock = docks.remove(from) ?: return
+ docks.putIfAbsent(to, dock)
+ save()
+ }
+
+ private fun save() {
+ val f = file ?: return
+ f.parentFile?.mkdirs()
+ val tmp = File(f.path + ".tmp")
+ tmp.writeText(docks.entries.joinToString("") { (k, dock) -> dock.joinToString("") { "$k\t${it.packageName}\t${it.label}\n" } })
+ if (!tmp.renameTo(f)) {
+ f.delete()
+ tmp.renameTo(f)
+ }
+ }
+}
+
+/** The dock's rules, kept apart from the screen so they can be tested on their own. */
+object Dock {
+ /** One row of four under Back and Home; "Add to dock" goes once it's full. */
+ const val MAX = 4
+
+ /** The apps the picker offers: ones a launcher can open, already-docked ones included (shown as Added). */
+ fun choices(apps: List<AppInfo>): List<AppInfo> = apps.filter { it.launchable && it.enabled }
+
+ fun add(dock: List<Docked>, app: AppInfo): List<Docked> =
+ if (dock.size >= MAX || dock.any { it.packageName == app.packageName }) dock else dock + Docked(app.packageName, app.label)
+
+ /** Puts [app] in [old]'s place; an app already elsewhere on the dock moves here instead. */
+ fun replace(dock: List<Docked>, old: String, app: AppInfo): List<Docked> =
+ dock.mapNotNull {
+ when (it.packageName) {
+ old -> Docked(app.packageName, app.label)
+ app.packageName -> null
+ else -> it
+ }
+ }
+
+ fun remove(dock: List<Docked>, pkg: String): List<Docked> = dock.filterNot { it.packageName == pkg }
+
+ fun move(dock: List<Docked>, from: Int, to: Int): List<Docked> {
+ if (from !in dock.indices || to !in dock.indices || from == to) return dock
+ return dock.toMutableList().apply { add(to, removeAt(from)) }
+ }
+
+ /**
+ * Splits [dock] into what is still on the TV and what was uninstalled, by [apps], the TV's
+ * full package list. A disabled app stays: it's still there, and opening it says why it can't.
+ * An empty list is a read that went wrong, not a TV with no apps, so nothing leaves.
+ */
+ fun prune(dock: List<Docked>, apps: List<AppInfo>): Pair<List<Docked>, List<Docked>> {
+ if (apps.isEmpty()) return dock to emptyList()
+ val installed = apps.mapTo(HashSet()) { it.packageName }
+ return dock.partition { it.packageName in installed }
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
index df35c29..18e9a1b 100644
--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
@@ -314,6 +314,17 @@ class FakeDeviceSource(
return true
}
+ override suspend fun launch(deviceId: String, packageName: String): Boolean {
+ delay(200)
+ return appsFor(deviceId).any { it.packageName == packageName && it.launchable && it.enabled }
+ }
+
+ private val docks = DockBook()
+
+ override suspend fun dock(deviceId: String) = docks[deviceId]
+
+ override suspend fun setDock(deviceId: String, dock: List<Docked>) = docks.set(deviceId, dock)
+
override suspend fun reboot(deviceId: String): Boolean {
delay(300)
remembered[deviceId]?.let { remembered[deviceId] = it.copy(state = DeviceState.Offline) }
@@ -372,15 +383,15 @@ class FakeDeviceSource(
val baseApps = listOf(
- AppInfo("com.spocky.projengmenu", "Projectivy Launcher", 0xFF3D5AFE, false, true, "this is your home screen", "4.52"),
- AppInfo("com.google.android.youtube.tv", "YouTube", 0xFFC4302B, false, true, null, "4.40.303"),
- AppInfo("com.netflix.ninja", "Netflix", 0xFFB20710, false, true, null, "11.2.0", removable = true),
- AppInfo("org.jellyfin.androidtv", "Jellyfin", 0xFF7B5EA7, false, true, null, "0.17.4", removable = true),
+ AppInfo("com.spocky.projengmenu", "Projectivy Launcher", 0xFF3D5AFE, false, true, "this is your home screen", "4.52", launchable = true),
+ AppInfo("com.google.android.youtube.tv", "YouTube", 0xFFC4302B, false, true, null, "4.40.303", launchable = true),
+ AppInfo("com.netflix.ninja", "Netflix", 0xFFB20710, false, true, null, "11.2.0", removable = true, launchable = true),
+ AppInfo("org.jellyfin.androidtv", "Jellyfin", 0xFF7B5EA7, false, true, null, "0.17.4", removable = true, launchable = true),
AppInfo("com.xgimi.assistant", "XGIMI Assistant", null, true, true, null, "2.1.8"),
AppInfo("com.xgimi.ota", "XGIMI Updates", null, true, true, null, "1.4.0"),
AppInfo("com.google.android.tvrecommendations", "TV Recommendations", null, true, false, null, "1.0"),
AppInfo("com.android.systemui", "System UI", null, true, true, "the TV needs this to draw the screen", "11"),
- AppInfo("com.android.tv.settings", "Settings", null, true, true, "you need this to change TV settings", "11"),
+ AppInfo("com.android.tv.settings", "Settings", null, true, true, "you need this to change TV settings", "11", launchable = true),
AppInfo("com.google.android.gms", "Google Play services", null, true, true, "most apps stop working without it", "24.38"),
AppInfo("com.google.android.inputmethod.latin", "Gboard", null, true, true, "you'd lose the on-screen keyboard", "14.1"),
)
diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.kt
index 158ba12..9fc557a 100644
--- a/app/src/main/java/app/tellyscope/data/Model.kt
+++ b/app/src/main/java/app/tellyscope/data/Model.kt
@@ -125,8 +125,13 @@ data class AppInfo(
val homeService: Boolean = false,
/** This TV's list says to keep it: Stop, Disable and Uninstall still run, after a warning. */
val listKeep: Boolean = false,
+ /** Has an icon on a launcher, so the Remote's dock can open it. */
+ val launchable: Boolean = false,
)
+/** An app on the Remote's dock. [label] is kept so it can be named after the app is gone. */
+data class Docked(val packageName: String, val label: String)
+
data class Socket(val app: String, val remote: String, val state: String)
data class AppTraffic(val app: String, val rxMb: Int, val txMb: Int)
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 1760691..364906f 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -333,7 +333,39 @@ object Copy {
}
const val REBOOT_TITLE = "Restart the TV?"
- const val REBOOT_TEXT = "Whatever is playing stops, and the TV takes a minute or two to come back. Tellyscope reconnects on its own when it's back."
+ const val REBOOT_TEXT = "The TV turns off and on again. Tellyscope reconnects by itself when it's back, usually within a minute."
+ const val RESTARTING_TITLE = "Restarting…"
+ const val RESTARTING_TEXT = "The TV is restarting. Tellyscope will reconnect by itself."
+ const val RESTART_LATE_TITLE = "The TV hasn't come back yet"
+ const val RESTART_LATE_TEXT = "It's been a minute. Some TVs take longer to start; Retry waits another minute."
+ const val RESTART_LOST_TEXT = "Use the TV's own remote to turn it on, then tap Retry."
+
+ fun waitingFor(name: String, ms: Long): String {
+ val s = (ms / 1000).coerceAtLeast(0)
+ return "Waiting for $name · ${s / 60}:${(s % 60).toString().padStart(2, '0')}"
+ }
+
+ fun restartLost(name: String) = "Still can't reach $name"
+ fun backOnline(name: String) = "Back online. $name reconnected."
+
+ // Dock
+
+ const val ADD_TO_DOCK = "Add to dock"
+ const val DOCK_PICK_TITLE = "Add an app to the dock"
+ const val DOCK_PICK_HINT = "Tap an app to add it."
+ const val DOCK_ADDED = "Added"
+ const val DOCK_NO_APPS = "Still reading the TV's apps. Open this again in a moment."
+ const val DOCK_CHANGE = "Change app"
+ const val DOCK_REMOVE = "Remove from dock"
+ const val DOCK_REORDER = "Keep holding and move to reorder"
+
+ fun dockPickFrom(name: String) = "Apps installed on $name"
+ fun dockSwap(label: String) = "Put another app in $label's place"
+ fun cantOpen(label: String) = "The TV couldn't open $label. If it's turned off, turn it on in Apps."
+
+ fun leftDock(labels: List<String>) =
+ if (labels.size == 1) "${labels[0]} was uninstalled, so it left the dock."
+ else "${labels.size} apps were uninstalled, so they left the dock."
fun restarting(minutes: Long) =
if (minutes < 3) "Tellyscope reconnects on its own when the TV is back, usually within a couple of minutes."
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
index e253168..0d0ee27 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
@@ -434,7 +434,7 @@ private fun AppMenu(state: UiState, actions: DeviceActions) {
/** One group of the menu, as a slightly darker rounded block inside it. */
@Composable
-private fun MenuBlock(items: @Composable () -> Unit) {
+internal fun MenuBlock(items: @Composable () -> Unit) {
Surface(
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colorScheme.surfaceContainerHighest,
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
index efe7f67..3e46dfb 100644
--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
@@ -2,23 +2,32 @@
package app.tellyscope.ui
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.foundation.gestures.drag
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.KeyboardActions
@@ -27,23 +36,30 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.Send
+import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowLeft
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.KeyboardArrowUp
-import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.CircularWavyProgressIndicator
+import androidx.compose.material3.DropdownMenu
+import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
+import androidx.compose.material3.ListItem
+import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LoadingIndicator
+import androidx.compose.material3.MaterialShapes
import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
@@ -54,31 +70,54 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.ripple
+import androidx.compose.material3.toShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.key
+import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.graphics.vector.PathParser
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
+import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.platform.LocalHapticFeedback
+import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.onClick
+import androidx.compose.ui.semantics.onLongClick
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.ImeAction
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.zIndex
import app.tellyscope.adb.RemoteKey
+import app.tellyscope.data.AppInfo
import app.tellyscope.data.DeviceState
+import app.tellyscope.data.Dock
+import app.tellyscope.data.Docked
+import kotlin.math.abs
+import kotlin.math.roundToInt
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@@ -89,6 +128,12 @@ data class RemoteActions(
val type: (String) -> String? = { null },
val reboot: () -> Unit = {},
val back: () -> Unit = {},
+ /** A restart running late: try the TV again and wait another minute. */
+ val retryRestart: () -> Unit = {},
+ /** Give up waiting for a restart that never came back. */
+ val stopWaiting: () -> Unit = {},
+ val launch: (Docked) -> Unit = {},
+ val setDock: (List<Docked>) -> Unit = {},
)
/** A held key repeats after this, then every [REPEAT_EVERY_MS], or slower if the TV is slower. */
@@ -123,15 +168,29 @@ fun RemoteScreen(
val live = device.state == DeviceState.Online && restart == null
var confirmReboot by rememberSaveable { mutableStateOf(false) }
if (confirmReboot) RebootDialog(onRestart = { confirmReboot = false; actions.reboot() }, onDismiss = { confirmReboot = false })
+ // Hide keeps a restart in the top bar; the dialog comes back when the wait moves on, or on a tap there.
+ val stage = restart?.let { "${it.since}/${it.waitFrom}/${it.phase(state.now)}" }
+ var hidden by rememberSaveable { mutableStateOf<String?>(null) }
+ if (restart != null && hidden != stage) {
+ RestartDialog(
+ restart, state.now, name(device),
+ onHide = { hidden = stage },
+ onRetry = actions.retryRestart,
+ onStop = actions.stopWaiting,
+ )
+ }
Scaffold(
snackbarHost = { SnackbarHost(snackbar) },
topBar = {
TopAppBar(
- title = { Text("Remote") },
+ title = { if (restart != null && hidden == stage) RestartStatus(onClick = { hidden = null }) else Text("Remote") },
navigationIcon = {
IconButton(onClick = actions.back) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back to the TV's page") }
},
+ actions = {
+ IconButton(onClick = { confirmReboot = true }, enabled = live) { Icon(RemoteIcons.RestartAlt, contentDescription = "Restart TV") }
+ },
)
},
) { pad ->
@@ -140,25 +199,24 @@ fun RemoteScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp),
) {
- when {
- restart != null -> RestartingCard(restart, state.now)
- device.state != DeviceState.Online -> Text(
- Copy.REMOTE_OFFLINE,
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
+ if (restart == null && device.state != DeviceState.Online) Text(
+ Copy.REMOTE_OFFLINE,
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
Column(
Modifier.alpha(if (live) 1f else 0.38f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp),
) {
DPad(live, actions.press)
+ // Two keys where there were three: Menu went, and its room stays in case it comes back.
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) {
RoundKey(RemoteKey.BACK, "Back", live, actions.press) { Icon(Icons.AutoMirrored.Filled.ArrowBack, null) }
RoundKey(RemoteKey.HOME, "Home", live, actions.press) { Icon(Icons.Default.Home, null) }
- RoundKey(RemoteKey.MENU, "Menu", live, actions.press) { Icon(Icons.Default.Menu, null) }
}
+ // Clear space above and below, so a thumb aiming at Back, Home or Vol doesn't open an app.
+ DockSection(state.device.dock, state.device.apps, name(device), live, actions, Modifier.padding(vertical = 4.dp))
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
PillKey(RemoteKey.VOLUME_DOWN, "Volume down", live, actions.press, Modifier.weight(1f)) { Text("Vol −") }
PillKey(RemoteKey.MUTE, "Mute", live, actions.press, Modifier.weight(1f)) { Text("Mute") }
@@ -172,15 +230,6 @@ fun RemoteScreen(
}
}
Keyboard(live, actions.type)
- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- val scope = rememberCoroutineScope()
- OutlinedButton(onClick = { scope.launch { actions.press(RemoteKey.SLEEP) } }, enabled = live, modifier = Modifier.weight(1f)) {
- Text("Sleep")
- }
- OutlinedButton(onClick = { confirmReboot = true }, enabled = live, modifier = Modifier.weight(1f)) {
- Text("Restart TV")
- }
- }
}
}
}
@@ -312,6 +361,7 @@ private fun Keyboard(enabled: Boolean, type: (String) -> String?) {
fun RebootDialog(onRestart: () -> Unit, onDismiss: () -> Unit) {
AlertDialog(
onDismissRequest = onDismiss,
+ icon = { Icon(RemoteIcons.RestartAlt, contentDescription = null) },
title = { Text(Copy.REBOOT_TITLE) },
text = { Text(Copy.REBOOT_TEXT) },
confirmButton = { Button(onClick = onRestart) { Text("Restart") } },
@@ -337,3 +387,319 @@ fun RestartingCard(restart: Restart, now: Long) {
}
}
}
+
+/**
+ * A restart from the Remote: waiting for a minute, then late, then, after a Retry's minute,
+ * lost. Hide and the first Close leave it waiting in the top bar; the last Close stops waiting.
+ */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun RestartDialog(restart: Restart, now: Long, tvName: String, onHide: () -> Unit, onRetry: () -> Unit, onStop: () -> Unit) {
+ val c = MaterialTheme.colorScheme
+ when (restart.phase(now)) {
+ Restart.Phase.Waiting -> AlertDialog(
+ onDismissRequest = onHide,
+ // Wavy, not the loading indicator: that one is for waits under a few seconds.
+ icon = { CircularWavyProgressIndicator(Modifier.size(48.dp)) },
+ title = { Text(Copy.RESTARTING_TITLE) },
+ text = {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(Copy.RESTARTING_TEXT)
+ Text(Copy.waitingFor(tvName, now - restart.since), style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
+ }
+ },
+ confirmButton = { TextButton(onClick = onHide) { Text("Hide") } },
+ )
+ Restart.Phase.Late -> AlertDialog(
+ onDismissRequest = onHide,
+ icon = { StatusShape(RemoteIcons.HourglassTop, c.secondaryContainer, c.onSecondaryContainer) },
+ title = { Text(Copy.RESTART_LATE_TITLE) },
+ text = { Text(Copy.RESTART_LATE_TEXT) },
+ confirmButton = { Button(onClick = onRetry) { Text("Retry") } },
+ dismissButton = { TextButton(onClick = onHide) { Text("Close") } },
+ )
+ Restart.Phase.Lost -> AlertDialog(
+ onDismissRequest = onStop,
+ icon = { StatusShape(RemoteIcons.LinkOff, c.errorContainer, c.onErrorContainer) },
+ title = { Text(Copy.restartLost(tvName)) },
+ text = { Text(Copy.RESTART_LOST_TEXT) },
+ confirmButton = { Button(onClick = onRetry) { Text("Retry") } },
+ dismissButton = { TextButton(onClick = onStop) { Text("Close") } },
+ )
+ }
+}
+
+/** A filled glyph in the cookie the TV header uses, for a state that needs a look rather than a spinner. */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun StatusShape(icon: ImageVector, container: Color, content: Color) {
+ Box(Modifier.size(56.dp).clip(MaterialShapes.Cookie9Sided.toShape()).background(container), contentAlignment = Alignment.Center) {
+ Icon(icon, contentDescription = null, tint = content, modifier = Modifier.size(28.dp))
+ }
+}
+
+/** The top bar's title while a hidden restart runs; a tap brings its dialog back. */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun RestartStatus(onClick: () -> Unit) {
+ Row(
+ Modifier.clip(MaterialTheme.shapes.small).clickable(onClickLabel = "Show the restart", onClick = onClick).padding(4.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ LoadingIndicator(Modifier.size(28.dp))
+ Text(Copy.RESTARTING_TITLE)
+ Icon(Icons.Default.KeyboardArrowRight, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+}
+
+/**
+ * Up to [Dock.MAX] apps in fixed slots from the left, with "Add to dock" under them until the row
+ * is full. A tap opens the app on the TV; a long press opens its menu, and moving while still
+ * holding drags it to another slot.
+ */
+@Composable
+private fun DockSection(dock: List<Docked>, apps: List<AppInfo>, tvName: String, enabled: Boolean, actions: RemoteActions, modifier: Modifier = Modifier) {
+ // Null: closed. Empty: adding. A package: swapping that app for another.
+ var picking by rememberSaveable { mutableStateOf<String?>(null) }
+ picking?.let { swap ->
+ DockPicker(
+ dock, apps, tvName, swapping = dock.firstOrNull { it.packageName == swap },
+ onPick = { app ->
+ picking = null
+ actions.setDock(if (swap.isEmpty()) Dock.add(dock, app) else Dock.replace(dock, swap, app))
+ },
+ onDismiss = { picking = null },
+ )
+ }
+ Column(modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(16.dp)) {
+ if (dock.isNotEmpty()) DockRow(dock, apps, enabled, actions, onSwap = { picking = it.packageName })
+ if (dock.size < Dock.MAX) {
+ OutlinedButton(
+ onClick = { picking = "" },
+ enabled = enabled,
+ contentPadding = PaddingValues(horizontal = 12.dp),
+ modifier = Modifier.height(28.dp),
+ ) {
+ Icon(Icons.Default.Add, contentDescription = null, modifier = Modifier.size(16.dp))
+ Spacer(Modifier.width(6.dp))
+ Text(Copy.ADD_TO_DOCK, style = MaterialTheme.typography.labelLarge)
+ }
+ }
+ }
+}
+
+@Composable
+private fun DockRow(dock: List<Docked>, apps: List<AppInfo>, enabled: Boolean, actions: RemoteActions, onSwap: (Docked) -> Unit) {
+ var menu by remember { mutableStateOf<String?>(null) }
+ // The app being dragged, and how far; the others make room for it as it goes.
+ var lifted by remember { mutableStateOf<String?>(null) }
+ var dragX by remember { mutableFloatStateOf(0f) }
+ BoxWithConstraints(Modifier.fillMaxWidth().height(80.dp)) {
+ val slot = constraints.maxWidth / Dock.MAX.toFloat()
+ fun from() = dock.indexOfFirst { it.packageName == lifted }
+ fun to() = (from() + (dragX / slot).roundToInt()).coerceIn(0, dock.lastIndex)
+ val order = if (from() < 0) dock else Dock.move(dock, from(), to())
+ dock.forEachIndexed { i, app -> key(app.packageName) {
+ val up = app.packageName == lifted
+ val x by animateFloatAsState(order.indexOf(app) * slot, label = "dock slot")
+ val info = apps.firstOrNull { it.packageName == app.packageName }
+ ?: AppInfo(app.packageName, app.label, null, false, true, null, "")
+ Box(
+ Modifier
+ .width(maxWidth / Dock.MAX)
+ .offset { IntOffset((if (up) i * slot + dragX else x).roundToInt(), 0) }
+ .zIndex(if (up) 1f else 0f),
+ ) {
+ val moves = listOfNotNull(
+ CustomAccessibilityAction("Move left") { actions.setDock(Dock.move(dock, i, i - 1)); true }.takeIf { i > 0 },
+ CustomAccessibilityAction("Move right") { actions.setDock(Dock.move(dock, i, i + 1)); true }.takeIf { i < dock.lastIndex },
+ )
+ DockTile(
+ info, up, enabled, moves,
+ onOpen = { actions.launch(app) },
+ onHold = { menu = app.packageName; lifted = app.packageName; dragX = 0f },
+ onDrag = { dx ->
+ dragX = dx
+ // A real move means reordering, so the menu gets out of the way.
+ if (abs(dx) > slot / 4) menu = null
+ },
+ onDrop = {
+ if (from() >= 0 && to() != from()) actions.setDock(Dock.move(dock, from(), to()))
+ lifted = null
+ dragX = 0f
+ },
+ onMenu = { menu = app.packageName },
+ )
+ DropdownMenu(menu == app.packageName, onDismissRequest = { menu = null }, shape = MaterialTheme.shapes.large) {
+ Row(Modifier.padding(start = 12.dp, end = 16.dp, top = 4.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
+ AppIcon(info, Modifier.size(32.dp))
+ Spacer(Modifier.width(12.dp))
+ Text(app.label, style = MaterialTheme.typography.titleSmall)
+ }
+ MenuBlock {
+ DropdownMenuItem(
+ text = { Text(Copy.DOCK_CHANGE) },
+ leadingIcon = { Icon(RemoteIcons.SwapHoriz, null) },
+ onClick = { menu = null; onSwap(app) },
+ )
+ DropdownMenuItem(
+ text = { Text(Copy.DOCK_REMOVE, color = MaterialTheme.colorScheme.error) },
+ leadingIcon = { Icon(RemoteIcons.RemoveCircle, null, tint = MaterialTheme.colorScheme.error) },
+ onClick = { menu = null; actions.setDock(Dock.remove(dock, app.packageName)) },
+ )
+ }
+ Text(
+ Copy.DOCK_REORDER,
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 4.dp),
+ )
+ }
+ }
+ } }
+ }
+}
+
+/** One docked app: its icon and name, lifted a size up while held. */
+@Composable
+private fun DockTile(
+ app: AppInfo,
+ lifted: Boolean,
+ enabled: Boolean,
+ /** Reordering for a screen reader, which can't drag. */
+ moves: List<CustomAccessibilityAction>,
+ onOpen: () -> Unit,
+ onHold: () -> Unit,
+ onDrag: (Float) -> Unit,
+ onDrop: () -> Unit,
+ onMenu: () -> Unit,
+) {
+ val haptic = LocalHapticFeedback.current
+ val scale by animateFloatAsState(if (lifted) 1.1f else 1f, label = "dock lift")
+ // The gesture outlives a recomposition; it must call the newest handlers, which see the newest dock.
+ val open by rememberUpdatedState(onOpen)
+ val hold by rememberUpdatedState(onHold)
+ val move by rememberUpdatedState(onDrag)
+ val drop by rememberUpdatedState(onDrop)
+ Column(
+ Modifier
+ .fillMaxWidth()
+ .graphicsLayer { scaleX = scale; scaleY = scale }
+ .semantics {
+ role = Role.Button
+ contentDescription = app.label
+ if (enabled) {
+ onClick("Open on the TV") { onOpen(); true }
+ onLongClick("Change or remove") { onMenu(); true }
+ customActions = moves
+ }
+ }
+ .pointerInput(enabled) {
+ if (!enabled) return@pointerInput
+ awaitEachGesture {
+ val down = awaitFirstDown()
+ // Up before the long-press time is a tap; still down after it is a hold.
+ var up: PointerInputChange? = null
+ val held = withTimeoutOrNull(viewConfiguration.longPressTimeoutMillis) { up = waitForUpOrCancellation(); false } ?: true
+ if (!held) {
+ up?.let { it.consume(); open() }
+ return@awaitEachGesture
+ }
+ haptic.performHapticFeedback(HapticFeedbackType.LongPress)
+ hold()
+ var dx = 0f
+ drag(down.id) { change ->
+ dx += change.positionChange().x
+ change.consume()
+ move(dx)
+ }
+ drop()
+ }
+ }
+ .padding(top = 4.dp),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(4.dp),
+ ) {
+ Box(Modifier.shadow(if (lifted) 6.dp else 0.dp, MaterialTheme.shapes.medium)) { AppIcon(app, Modifier.size(48.dp)) }
+ Text(
+ app.label,
+ style = MaterialTheme.typography.labelMedium,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.padding(horizontal = 4.dp),
+ )
+ }
+}
+
+/** The apps a launcher can open, to add to the dock or to put in [swapping]'s place. Docked ones show as Added. */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+private fun DockPicker(dock: List<Docked>, apps: List<AppInfo>, tvName: String, swapping: Docked?, onPick: (AppInfo) -> Unit, onDismiss: () -> Unit) {
+ val choices = Dock.choices(apps)
+ ModalBottomSheet(onDismissRequest = onDismiss) {
+ Column(Modifier.padding(horizontal = 24.dp).padding(bottom = 8.dp)) {
+ Text(swapping?.let { Copy.dockSwap(it.label) } ?: Copy.DOCK_PICK_TITLE, style = MaterialTheme.typography.titleLarge)
+ Text(Copy.dockPickFrom(tvName), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ if (choices.isEmpty()) {
+ Text(
+ Copy.DOCK_NO_APPS,
+ style = MaterialTheme.typography.bodyMedium,
+ modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
+ )
+ return@ModalBottomSheet
+ }
+ LazyColumn {
+ items(choices, key = { it.packageName }) { app ->
+ val added = dock.any { it.packageName == app.packageName }
+ ListItem(
+ headlineContent = { Text(app.label) },
+ leadingContent = { AppIcon(app) },
+ trailingContent = if (added) ({ Text(Copy.DOCK_ADDED, style = MaterialTheme.typography.labelMedium) }) else null,
+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),
+ modifier = Modifier.alpha(if (added) 0.38f else 1f).clickable(enabled = !added) { onPick(app) },
+ )
+ }
+ item {
+ Text(
+ Copy.DOCK_PICK_HINT,
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
+ )
+ }
+ }
+ }
+}
+
+private object RemoteIcons {
+ // Absolute commands only: Compose's path parser misplaces a relative move after a close.
+ val RestartAlt = icon(
+ "RestartAlt",
+ "M12 5L12 2L8 6L12 10L12 7C15.31 7 18 9.69 18 13C18 15.97 15.83 18.43 13 18.91L13 20.93C16.95 20.44 20 17.08 20 13C20 8.58 16.42 5 12 5Z" +
+ "M6 13C6 11.35 6.67 9.85 7.76 8.76L6.34 7.34C4.9 8.79 4 10.79 4 13C4 17.08 7.05 20.44 11 20.93L11 18.91C8.17 18.43 6 15.97 6 13Z",
+ )
+ val HourglassTop = icon(
+ "HourglassTop",
+ "M6 2L6.01 8L10 12L6.01 16.01L6 22L18 22L18 16L14 12L18 8.01L18 2L6 2Z M16 16.5L16 20L8 20L8 16.5L12 12.5L16 16.5Z",
+ )
+ val LinkOff = icon(
+ "LinkOff",
+ "M17 7L13 7L13 8.9L17 8.9C18.71 8.9 20.1 10.29 20.1 12C20.1 13.43 19.12 14.63 17.79 14.98L19.25 16.44C20.88 15.61 22 13.95 22 12C22 9.24 19.76 7 17 7Z" +
+ "M16 11L13.81 11L15.81 13L16 13Z" +
+ "M2 4.27L5.11 7.38C3.29 8.12 2 9.91 2 12C2 14.76 4.24 17 7 17L11 17L11 15.1L7 15.1C5.29 15.1 3.9 13.71 3.9 12C3.9 10.41 5.11 9.1 6.66 8.93" +
+ "L8.73 11L8 11L8 13L10.73 13L13 15.27L13 17L14.73 17L18.74 21L20 19.74L3.27 3L2 4.27Z",
+ )
+ val SwapHoriz = icon("SwapHoriz", "M6.99 11L3 15L6.99 19L6.99 16L14 16L14 14L6.99 14L6.99 11Z M21 9L17.01 5L17.01 8L10 8L10 10L17.01 10L17.01 13L21 9Z")
+ val RemoveCircle = icon(
+ "RemoveCircle",
+ "M7 11L7 13L17 13L17 11L7 11Z" +
+ "M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2Z" +
+ "M12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20Z",
+ )
+
+ private fun icon(name: String, path: String) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
+ .addPath(PathParser().parsePathString(path).toNodes(), pathFillType = PathFillType.NonZero, fill = SolidColor(Color.Black))
+ .build()
+}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 72baf1b..4d09ec7 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -23,6 +23,8 @@ import app.tellyscope.data.ConnectResult
import app.tellyscope.data.Device
import app.tellyscope.data.DeviceSource
import app.tellyscope.data.DeviceState
+import app.tellyscope.data.Dock
+import app.tellyscope.data.Docked
import app.tellyscope.data.HistoryEntry
import app.tellyscope.data.NetworkInfo
import app.tellyscope.data.NotAnApp
@@ -93,6 +95,8 @@ data class DeviceUi(
val tweaks: TvTweaks? = null,
/** Another device asking the TV for debugging access; null when nothing is asking. */
val request: ConnectionRequest? = null,
+ /** The Remote's app shortcuts, in order. */
+ val dock: List<Docked> = emptyList(),
)
data class SideloadUi(
@@ -147,8 +151,27 @@ data class UiState(
/** An action that went through on [deviceId]; the snackbar offers its undo. */
data class Done(val deviceId: String, val entry: HistoryEntry)
-/** A restart in progress: [down] once the TV has dropped, so its coming back can be told apart from not having left. */
-data class Restart(val since: Long, val down: Boolean = false)
+/**
+ * A restart in progress: [down] once the TV has dropped, so its coming back can be told apart from
+ * not having left. Each wait lasts [RESTART_WAIT_MS] from [waitFrom]: the first from [since], the
+ * next from each Retry.
+ */
+data class Restart(val since: Long, val down: Boolean = false, val waitFrom: Long = since, val retried: Boolean = false) {
+ enum class Phase { Waiting, Late, Lost }
+
+ /**
+ * Late once the first minute is up; Lost when a Retry's minute is up too. A TV that never
+ * dropped stays Waiting: it ignored the restart, which [RESTART_GRACE_MS] reports instead.
+ */
+ fun phase(now: Long) = when {
+ !down || now - waitFrom < RESTART_WAIT_MS -> Phase.Waiting
+ retried -> Phase.Lost
+ else -> Phase.Late
+ }
+}
+
+/** Most TVs are back within this; after it the Remote asks whether to keep waiting. */
+const val RESTART_WAIT_MS = 60_000L
/** [DeviceUi.busy] value while "Restore everything" runs. */
const val RESTORING = "restore"
@@ -349,7 +372,8 @@ class TellyscopeViewModel(
// History lives on the phone, so it shows (and undo is offered) even while the TV is off.
viewModelScope.launch {
val history = source.history(device.id)
- _state.update { if (it.selectedId == device.id) it.copy(device = it.device.copy(history = history)) else it }
+ val dock = source.dock(device.id)
+ _state.update { if (it.selectedId == device.id) it.copy(device = it.device.copy(history = history, dock = dock)) else it }
}
if (device.state != DeviceState.Online) return
liveJob = viewModelScope.launch {
@@ -367,6 +391,7 @@ class TellyscopeViewModel(
// Read first: update {} may run its block again, and must never call the TV.
val apps = source.apps(id!!)
updateDevice(id) { it.copy(apps = apps) }
+ pruneDock(id, apps)
val tweaks = source.tweaks(id)
updateDevice(id) { it.copy(tweaks = tweaks) }
loadFiles()
@@ -544,6 +569,7 @@ class TellyscopeViewModel(
val history = source.history(id)
updateDevice(id) { it.copy(apps = apps, busy = null, history = history) }
if (undoing == null) _done.value = Done(id, entry)
+ if (action == Action.Uninstall) pruneDock(id, apps)
}
}
@@ -967,6 +993,54 @@ class TellyscopeViewModel(
}
}
+ /** Retry once a restart runs late: the link tries the TV again, and the wait starts over for a minute. */
+ fun retryRestart() {
+ val id = _state.value.selectedId ?: return
+ _state.update { s ->
+ val r = s.restarting[id] ?: return@update s
+ s.copy(restarting = s.restarting + (id to r.copy(waitFrom = clock(), retried = true)))
+ }
+ viewModelScope.launch { source.reconnect(id) }
+ }
+
+ /** Close on "Still can't reach": stop waiting, and the Remote shows the TV as offline. */
+ fun stopWaiting() {
+ val id = _state.value.selectedId ?: return
+ _state.update { it.copy(restarting = it.restarting - id) }
+ }
+
+ /** The dock's add, swap, remove and reorder all land here, saved per TV. */
+ fun setDock(dock: List<Docked>) {
+ val id = _state.value.selectedId ?: return
+ updateDevice(id) { it.copy(dock = dock) }
+ viewModelScope.launch { source.setDock(id, dock) }
+ }
+
+ /** A dock tap: opens the app on the TV, without a history entry. */
+ fun launch(app: Docked) {
+ val id = _state.value.selectedId ?: return
+ viewModelScope.launch {
+ val ok = try {
+ source.launch(id, app.packageName)
+ } catch (e: CancellationException) {
+ throw e
+ } catch (_: Exception) {
+ _notice.value = Copy.REMOTE_LOST
+ return@launch
+ }
+ if (!ok) _notice.value = Copy.cantOpen(app.label)
+ }
+ }
+
+ /** An app uninstalled, here or on the TV itself, leaves the dock, and the snackbar says so. */
+ private suspend fun pruneDock(id: String, apps: List<AppInfo>) {
+ val (kept, gone) = Dock.prune(source.dock(id), apps)
+ if (gone.isEmpty()) return
+ source.setDock(id, kept)
+ updateDevice(id) { it.copy(dock = kept) }
+ _notice.value = Copy.leftDock(gone.map { it.label })
+ }
+
/**
* A restart ends when the TV is back online after dropping, or stops at a refusal. One still
* online after [RESTART_GRACE_MS] never went down, so the TV ignored the request.
@@ -974,9 +1048,13 @@ class TellyscopeViewModel(
private fun restarts(current: Map<String, Restart>, known: List<Device>): Map<String, Restart> {
val now = clock()
return current.mapNotNull { (id, r) ->
- val state = known.firstOrNull { it.id == id }?.state ?: return@mapNotNull null
+ val device = known.firstOrNull { it.id == id } ?: return@mapNotNull null
+ val state = device.state
when {
- state == DeviceState.Online && r.down -> null
+ state == DeviceState.Online && r.down -> {
+ _notice.value = Copy.backOnline(name(device))
+ null
+ }
state == DeviceState.Online && now - r.since > RESTART_GRACE_MS -> {
_notice.value = Copy.REBOOT_IGNORED
null
diff --git a/app/src/test/java/app/tellyscope/DockTest.kt b/app/src/test/java/app/tellyscope/DockTest.kt
new file mode 100644
index 0000000..f900234
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/DockTest.kt
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.AppInfo
+import app.tellyscope.data.Dock
+import app.tellyscope.data.DockBook
+import app.tellyscope.data.Docked
+import org.junit.Assert.assertEquals
+import org.junit.Test
+import java.io.File
+import java.nio.file.Files
+
+class DockTest {
+ private fun app(pkg: String, enabled: Boolean = true, launchable: Boolean = true) =
+ AppInfo(pkg, pkg.substringAfterLast('.'), null, false, enabled, null, "", launchable = launchable)
+
+ private val youtube = Docked("com.google.android.youtube.tv", "YouTube")
+ private val netflix = Docked("com.netflix.ninja", "Netflix")
+ private val smarttube = Docked("org.smarttube.stable", "SmartTube")
+
+ @Test fun addStopsAtFourAndNeverTwice() {
+ val four = (1..4).map { Docked("com.example.app$it", "App $it") }
+ assertEquals(four, Dock.add(four, app("com.example.app5")))
+ assertEquals(listOf(youtube), Dock.add(listOf(youtube), app(youtube.packageName)))
+ assertEquals(listOf(youtube, Docked("com.example.kodi", "kodi")), Dock.add(listOf(youtube), app("com.example.kodi")))
+ }
+
+ @Test fun changeKeepsTheSlot() {
+ val dock = listOf(youtube, netflix, smarttube)
+ assertEquals(listOf(youtube, Docked("com.example.kodi", "kodi"), smarttube), Dock.replace(dock, netflix.packageName, app("com.example.kodi")))
+ }
+
+ @Test fun removeAndMove() {
+ val dock = listOf(youtube, netflix, smarttube)
+ assertEquals(listOf(youtube, smarttube), Dock.remove(dock, netflix.packageName))
+ assertEquals(listOf(netflix, smarttube, youtube), Dock.move(dock, 0, 2))
+ assertEquals(listOf(smarttube, youtube, netflix), Dock.move(dock, 2, 0))
+ assertEquals(dock, Dock.move(dock, 1, 3)) // off the end: nothing moves
+ }
+
+ @Test fun anUninstalledAppLeavesADisabledOneStays() {
+ val dock = listOf(youtube, netflix, smarttube)
+ val apps = listOf(app(youtube.packageName), app(netflix.packageName, enabled = false))
+ assertEquals(listOf(youtube, netflix) to listOf(smarttube), Dock.prune(dock, apps))
+ }
+
+ @Test fun anEmptyAppListIsAFailedReadNotAnEmptyTv() {
+ val dock = listOf(youtube, netflix)
+ assertEquals(dock to emptyList<Docked>(), Dock.prune(dock, emptyList()))
+ }
+
+ @Test fun thePickerOffersAppsALauncherCanOpen() {
+ val apps = listOf(app("com.a"), app("com.b", launchable = false), app("com.c", enabled = false))
+ assertEquals(listOf("com.a"), Dock.choices(apps).map { it.packageName })
+ }
+
+ @Test fun theBookKeepsOrderAcrossARestartAndFollowsARekey() {
+ val file = File(Files.createTempDirectory("dock").toFile(), "docks.tsv")
+ DockBook(file).apply {
+ set("192.0.2.10:5555", listOf(netflix, youtube))
+ set("other", listOf(Docked("com.x", "Tab\tin name")))
+ rekey("192.0.2.10:5555", "serial-1")
+ }
+ val again = DockBook(file)
+ assertEquals(listOf(netflix, youtube), again["serial-1"])
+ assertEquals(emptyList<Docked>(), again["192.0.2.10:5555"])
+ assertEquals(listOf(Docked("com.x", "Tab in name")), again["other"])
+ }
+}
diff --git a/app/src/test/java/app/tellyscope/RestartAndDockTest.kt b/app/src/test/java/app/tellyscope/RestartAndDockTest.kt
new file mode 100644
index 0000000..1349230
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/RestartAndDockTest.kt
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import androidx.lifecycle.viewModelScope
+import app.tellyscope.data.Action
+import app.tellyscope.data.AppInfo
+import app.tellyscope.data.Device
+import app.tellyscope.data.DeviceSource
+import app.tellyscope.data.DeviceState
+import app.tellyscope.data.Docked
+import app.tellyscope.data.FakeDeviceSource
+import app.tellyscope.data.HistoryEntry
+import app.tellyscope.data.ScanHit
+import app.tellyscope.data.ScanKind
+import app.tellyscope.data.Snapshot
+import app.tellyscope.ui.Copy
+import app.tellyscope.ui.Restart
+import app.tellyscope.ui.TellyscopeViewModel
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.cancel
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.advanceTimeBy
+import kotlinx.coroutines.test.resetMain
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.setMain
+import org.junit.After
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+
+/** One TV called Projector, whose state, apps and dock the test sets; launches are recorded. */
+private class Tv : DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {
+ var state = DeviceState.Online
+ var apps = emptyList<AppInfo>()
+ var dock = emptyList<Docked>()
+ var opens = true
+ val launched = mutableListOf<String>()
+ val acted = mutableListOf<String>()
+
+ override suspend fun known() = listOf(
+ Device("tv", ScanHit("tv", 5555, ScanKind.Classic, "tv", null), state, null, null, null, 0L, nickname = "Projector"),
+ )
+
+ override fun live(deviceId: String) = emptyFlow<Snapshot>()
+ override suspend fun apps(deviceId: String) = apps
+ override suspend fun reboot(deviceId: String) = true
+ override suspend fun dock(deviceId: String) = dock
+ override suspend fun setDock(deviceId: String, dock: List<Docked>) { this.dock = dock }
+
+ override suspend fun launch(deviceId: String, packageName: String): Boolean {
+ launched += packageName
+ return opens
+ }
+
+ override suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long?): HistoryEntry {
+ acted += packageName
+ return HistoryEntry(1, deviceId, 0, action, packageName, packageName, null, null)
+ }
+}
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class RestartAndDockTest {
+ private val dispatcher = StandardTestDispatcher()
+ private val test = TestScope(dispatcher)
+ private val tv = Tv()
+ private var now = 0L
+ private lateinit var vm: TellyscopeViewModel
+
+ private fun app(pkg: String, label: String, enabled: Boolean = true) = AppInfo(pkg, label, null, false, enabled, null, "", launchable = true)
+
+ @Before fun setUp() = Dispatchers.setMain(dispatcher)
+
+ @After fun tearDown() {
+ if (::vm.isInitialized) vm.viewModelScope.cancel()
+ Dispatchers.resetMain()
+ }
+
+ private fun start() = with(test) {
+ vm = TellyscopeViewModel(tv, clock = { now })
+ runCurrent()
+ }
+
+ @Test fun aRestartWaitsAMinuteThenIsLateThenAfterRetryIsLost() {
+ val r = Restart(since = 0, down = true)
+ assertEquals(Restart.Phase.Waiting, r.phase(59_999))
+ assertEquals(Restart.Phase.Late, r.phase(60_000))
+ val retried = r.copy(waitFrom = 70_000, retried = true)
+ assertEquals(Restart.Phase.Waiting, retried.phase(129_999))
+ assertEquals(Restart.Phase.Lost, retried.phase(130_000))
+ // Still on after a minute: the TV ignored it, and that's said elsewhere.
+ assertEquals(Restart.Phase.Waiting, Restart(since = 0).phase(60_000))
+ }
+
+ @Test fun aTvBackFromARestartSaysSoByName() = with(test) {
+ start()
+ vm.reboot()
+ runCurrent()
+ tv.state = DeviceState.Offline
+ advanceTimeBy(3_100)
+ assertTrue(vm.state.value.restarting.getValue("tv").down)
+ tv.state = DeviceState.Online
+ advanceTimeBy(3_100)
+ assertNull(vm.state.value.restarting["tv"])
+ assertEquals(Copy.backOnline("Projector"), vm.notice.value)
+ }
+
+ @Test fun retryWaitsAnotherMinuteAndCloseStopsWaiting() = with(test) {
+ start()
+ vm.reboot()
+ runCurrent()
+ tv.state = DeviceState.Offline
+ now = 61_000
+ advanceTimeBy(3_100)
+ assertEquals(Restart.Phase.Late, vm.state.value.restarting.getValue("tv").phase(now))
+ vm.retryRestart()
+ assertEquals(Restart.Phase.Waiting, vm.state.value.restarting.getValue("tv").phase(now))
+ now = 122_000
+ assertEquals(Restart.Phase.Lost, vm.state.value.restarting.getValue("tv").phase(now))
+ vm.stopWaiting()
+ assertNull(vm.state.value.restarting["tv"])
+ }
+
+ @Test fun anAppUninstalledOnTheTvLeavesTheDock() = with(test) {
+ tv.dock = listOf(Docked("com.youtube", "YouTube"), Docked("org.smarttube", "SmartTube"), Docked("com.kodi", "Kodi"))
+ tv.apps = listOf(app("com.youtube", "YouTube"), app("com.kodi", "Kodi", enabled = false))
+ start()
+ assertEquals(listOf("YouTube", "Kodi"), vm.state.value.device.dock.map { it.label })
+ assertEquals(listOf("YouTube", "Kodi"), tv.dock.map { it.label })
+ assertEquals(Copy.leftDock(listOf("SmartTube")), vm.notice.value)
+ }
+
+ @Test fun aDockTapOpensTheAppWithoutHistory() = with(test) {
+ start()
+ vm.launch(Docked("com.youtube", "YouTube"))
+ runCurrent()
+ assertEquals(listOf("com.youtube"), tv.launched)
+ assertEquals(emptyList<String>(), tv.acted)
+ tv.opens = false
+ vm.launch(Docked("com.kodi", "Kodi"))
+ runCurrent()
+ assertEquals(Copy.cantOpen("Kodi"), vm.notice.value)
+ }
+
+ @Test fun theDockIsSavedPerTv() = with(test) {
+ start()
+ vm.setDock(listOf(Docked("com.youtube", "YouTube")))
+ runCurrent()
+ assertEquals(listOf("com.youtube"), tv.dock.map { it.packageName })
+ assertEquals(listOf("com.youtube"), vm.state.value.device.dock.map { it.packageName })
+ }
+}
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index 6c475f4..a6fdd14 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -43,6 +43,7 @@ import app.tellyscope.adb.TvFile
import app.tellyscope.adb.TvFolder
import app.tellyscope.data.Action
import app.tellyscope.data.AppInfo
+import app.tellyscope.data.Docked
import app.tellyscope.data.AppNames
import app.tellyscope.data.Device
import app.tellyscope.data.DeviceState
@@ -921,13 +922,45 @@ class ScreenshotTest {
@Test fun restore() = shot("11_restore", screen = true) { RestoreDialog(2, {}, {}) }
- @Test fun remote() = shot("12_remote") { RemoteScreen(deviceState(), RemoteActions()) }
+ private val docked = listOf(Docked("com.google.android.youtube.tv", "YouTube"), Docked("com.netflix.ninja", "Netflix"))
- @Test fun remote_dark() = shot("12_remote", dark = true) { RemoteScreen(deviceState(), RemoteActions()) }
+ private fun remoteState(apps: List<Docked> = docked, restart: Restart? = null) =
+ deviceState { copy(dock = apps) }.let { s -> restart?.let { s.copy(restarting = mapOf(s.selectedId!! to it)) } ?: s }
- @Test fun remote_restarting() {
- val state = deviceState().let { it.copy(restarting = mapOf(it.selectedId!! to Restart(now - 25_000, down = true))) }
- shot("13_remote_restarting") { RemoteScreen(state, RemoteActions()) }
+ @Test fun remote() = shot("12_remote") { RemoteScreen(remoteState(), RemoteActions()) }
+
+ @Test fun remote_dark() = shot("12_remote", dark = true) { RemoteScreen(remoteState(), RemoteActions()) }
+
+ @Test fun remote_dockFull() {
+ val four = docked + listOf(Docked("org.jellyfin.androidtv", "Jellyfin"), Docked("com.spocky.projengmenu", "Projectivy Launcher"))
+ shot("12_remote_dock_full") { RemoteScreen(remoteState(four), RemoteActions()) }
+ // A full row has no Add to dock.
+ compose.onNodeWithText(Copy.ADD_TO_DOCK).assertDoesNotExist()
+ }
+
+ @Test fun remote_dockPicker() = shot("12_remote_dock_picker", screen = true, before = { compose.onNodeWithText(Copy.ADD_TO_DOCK).performClick() }) {
+ RemoteScreen(remoteState(), RemoteActions())
+ }
+
+ @Test fun remote_dockMenu() = shot(
+ "12_remote_dock_menu", screen = true,
+ before = { compose.onNodeWithContentDescription("Netflix").performSemanticsAction(SemanticsActions.OnLongClick) },
+ ) { RemoteScreen(remoteState(), RemoteActions()) }
+
+ @Test fun remote_restarting() = shot("13_remote_restarting", screen = true) {
+ RemoteScreen(remoteState(restart = Restart(now - 25_000, down = true)), RemoteActions())
+ }
+
+ @Test fun remote_restartHidden() = shot("13_remote_restart_hidden", before = { compose.onNodeWithText("Hide").performClick() }) {
+ RemoteScreen(remoteState(restart = Restart(now - 25_000, down = true)), RemoteActions())
+ }
+
+ @Test fun remote_restartLate() = shot("13_remote_restart_late", screen = true) {
+ RemoteScreen(remoteState(restart = Restart(now - 61_000, down = true)), RemoteActions())
+ }
+
+ @Test fun remote_restartLost() = shot("13_remote_restart_lost", screen = true) {
+ RemoteScreen(remoteState(restart = Restart(now - 130_000, down = true, waitFrom = now - 61_000, retried = true)), RemoteActions())
}
@Test fun device_restarting() {