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.

Add your TV step by step, with a screen per TV

jesse-agent-232146929bf3a18
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7c10e0..a9eeca3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ until this file has a section for its version.
## Unreleased
+- **Improved:** Adding a TV walks through it a step at a time, with the steps for your brand, and each TV gets its own screen for the pairing code or the Allow box. That screen shows this phone's key, so you can check it against the one on the TV.
- **New:** The app opens on its logo, then a one-time welcome for first-time users. [#65](../../pull/65)
- **Improved:** Overview puts the TV first, with chips to switch and debloat counts. [#64](../../pull/64)
- **Improved:** An offline TV keeps its maker and Android version after the app restarts. [#63](../../pull/63)
diff --git a/README.md b/README.md
index d9fe3cf..d7c7e0e 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,14 @@ Or get updates automatically with [Obtainium](#get-it).
<td align="center"><sub>Switch the home screen</sub></td>
<td align="center"><sub>Uninstall apps you added</sub></td>
</tr>
+ <tr>
+ <td><img src="docs/screenshots/add-tv.png" alt="Add your TV: brand chips, the setup steps ticked off, and two TVs found with Connect"></td>
+ <td><img src="docs/screenshots/connect.png" alt="Allow on your TV: this phone's key, and a drawing of the TV's Allow box with the same key"></td>
+ </tr>
+ <tr>
+ <td align="center"><sub>Add your TV step by step</sub></td>
+ <td align="center"><sub>Check the key, then Allow</sub></td>
+ </tr>
</table>
<sub>Rendered from the app's screenshot tests with sample data.</sub>
@@ -79,7 +87,7 @@ The full rules are under [Safety rules](#safety-rules).
Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV over the network using ADB, the same debugging protocol developers use.
-- **Find and connect.** It looks for TVs on your Wi-Fi, or you add one by IP address. Classic network debugging (port 5555) and Android 11+ wireless debugging with a 6-digit pairing code both work. A step-by-step card shows how to turn debugging on for Google TV, Android TV, Fire TV, Xiaomi and XGIMI. The first launch opens a short welcome with the three setup steps, and on Android 17 or newer asks for the local-network permission it needs to reach the TV.
+- **Find and connect.** It looks for TVs on your Wi-Fi, or you add one by IP address. Classic network debugging (port 5555) and Android 11+ wireless debugging with a 6-digit pairing code both work. **Add your TV** walks through turning debugging on one step at a time, with the menu names for Google TV, Android TV, Fire TV, Xiaomi or XGIMI, then lists the TVs it found. Each TV opens its own screen: the pairing code, or the Allow box with this phone's key to check against the one the TV shows. The first launch opens a short welcome with the three setup steps, and on Android 17 or newer asks for the local-network permission it needs to reach the TV.
- **Remembers your TVs.** They reconnect on their own after a restart of the app or the TV. You can rename a TV (the name stays on your phone) or forget it.
- **How it's doing.** Each TV's Overview opens with the TV itself: its name, maker and model, and a one-line summary such as "Running fine" or "Storage almost full". Below that is a chip per TV to switch between them, then a **+ Device** chip. Then comes free space as a bar, with CPU, RAM, temperature and network speed. When a TV is offline, it shows the storage from the last time Tellyscope saw it. Its address and how long it's been on are under Advanced.
- **The main jobs up front.** Big **Install app**, **Debloat** and **Send file** tiles sit right under the vitals. Debloat shows a count while the TV's list still has apps on, or while apps Tellyscope turned off are back on, often after a TV update. When there's nothing left, it opens Apps instead. Under **Suggested for this TV**, one line says how many of the list's apps are off. If any came back on, a red line says so. Below that are the TV's Android version, when it last updated, and **Check for updates**, which opens the TV's own update screen. The Apps tab has an **Install app** button, and Files has **Upload files**.
@@ -97,8 +105,8 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
1. On the TV, open **About** in Settings and press OK on **Build** (Fire TV: your device's name) 7 times, until it says you're a developer.
2. In **Developer options**, turn on **USB debugging** (Fire TV: **ADB debugging**), and **Network debugging** if your TV lists it. Newer TVs may show **Wireless debugging** instead; turn that on too.
-3. Put your phone on the same Wi-Fi as the TV and open Tellyscope. Tap **Connect** next to your TV.
-4. The TV asks "Allow USB debugging?". Tick **Always allow from this computer**, then press **Allow**. With wireless debugging, Tellyscope asks for the 6-digit pairing code the TV shows instead.
+3. Put your phone on the same Wi-Fi as the TV and open Tellyscope. Pick your TV's brand under **Add your TV**, and tap **Connect** when your TV shows up under **Find your TV**.
+4. The TV asks "Allow USB debugging?". Check its key matches the one Tellyscope shows, tick **Always allow from this computer**, then press **Allow**. With wireless debugging, Tellyscope asks for the 6-digit pairing code the TV shows instead.
The menu paths differ by brand; the app shows the exact steps for yours.
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Connector.kt b/adb/src/main/kotlin/app/tellyscope/adb/Connector.kt
index 984ce97..3aec841 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Connector.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Connector.kt
@@ -19,6 +19,12 @@ import java.io.InterruptedIOException
import java.net.InetSocketAddress
import java.net.Socket
import java.nio.channels.InterruptedByTimeoutException
+import java.math.BigInteger
+import java.nio.ByteBuffer
+import java.nio.ByteOrder
+import java.security.MessageDigest
+import java.security.cert.CertificateFactory
+import java.security.interfaces.RSAPublicKey
sealed interface ConnectResult {
class Online(val session: AdbSession) : ConnectResult
@@ -68,6 +74,35 @@ object Connector {
KadbCert.ensureReady()
}
+ /**
+ * This phone's key as the TV's "Allow USB debugging?" box prints it: the MD5 of the ADB public key,
+ * as colon-separated hex pairs, the way Android's AdbDebuggingManager formats it. Null before [init].
+ */
+ fun fingerprint(): String? = runCatching {
+ val cert = CertificateFactory.getInstance("X.509").generateCertificate(KadbCert.ensureReady().certificatePem.inputStream())
+ MessageDigest.getInstance("MD5").digest(adbPublicKey(cert.publicKey as RSAPublicKey))
+ .joinToString(":") { "%02X".format(it) }
+ }.getOrNull()
+
+ /**
+ * The public key in adb's own layout, the bytes the TV hashes: word count, -1/n mod 2^32,
+ * the modulus, R^2 mod n, then the exponent. All little-endian, least significant word first.
+ */
+ internal fun adbPublicKey(key: RSAPublicKey): ByteArray {
+ val n = key.modulus
+ val words = n.bitLength() / 32
+ val r32 = BigInteger.ONE.shiftLeft(32)
+ val rr = BigInteger.ONE.shiftLeft(words * 32).pow(2).mod(n)
+ val buf = ByteBuffer.allocate(4 * (3 + 2 * words)).order(ByteOrder.LITTLE_ENDIAN)
+ buf.putInt(words)
+ buf.putInt(r32.subtract(n.mod(r32).modInverse(r32)).toInt())
+ fun putWords(v: BigInteger) = repeat(words) { i -> buf.putInt(v.shiftRight(32 * i).toInt()) }
+ putWords(n)
+ putWords(rr)
+ buf.putInt(key.publicExponent.toInt())
+ return buf.array()
+ }
+
/**
* Connects to [host]:[port]. The call blocks while the Allow prompt is on the TV, up to
* [allowWaitMs]; the UI shows WAITING for that whole time. Cancelling it closes the attempt.
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ConnectorTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ConnectorTest.kt
index 0528230..c114bd2 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/ConnectorTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ConnectorTest.kt
@@ -12,10 +12,31 @@ import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
class ConnectorTest {
@BeforeTest fun key() = Connector.init(File(Files.createTempDirectory("adbkey").toFile(), "adbkey"))
+ @Test fun fingerprintLooksLikeTheTvShowsIt() {
+ // The TV prints 16 colon-separated hex pairs; the phone must show the same, and the same each time.
+ val f = Connector.fingerprint()
+ assertNotNull(f)
+ assertTrue(Regex("(?:[0-9A-F]{2}:){15}[0-9A-F]{2}").matches(f), f)
+ assertEquals(f, Connector.fingerprint())
+ }
+
+ @Test fun adbKeyLayoutIsWhatTheTvHashes() {
+ val key = java.security.KeyPairGenerator.getInstance("RSA").apply { initialize(2048) }.generateKeyPair().public
+ as java.security.interfaces.RSAPublicKey
+ val b = java.nio.ByteBuffer.wrap(Connector.adbPublicKey(key)).order(java.nio.ByteOrder.LITTLE_ENDIAN)
+ assertEquals(524, b.capacity())
+ assertEquals(64, b.getInt(0))
+ // n0inv is -1/n mod 2^32, so n0inv * n's lowest word is all ones.
+ assertEquals(-1, b.getInt(4) * b.getInt(8))
+ assertEquals(65537, b.getInt(520))
+ }
+
@Test fun portOutOfRangeIsUnreachable() = runBlocking<Unit> {
// InetSocketAddress threw IllegalArgumentException here, which nothing caught.
assertIs<ConnectResult.Unreachable>(Connector.connect("127.0.0.1", 70000))
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index ea3c6d5..efb0424 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -35,6 +35,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
+import app.tellyscope.adb.Connector
import app.tellyscope.data.AdbDeviceSource
import app.tellyscope.data.AndroidPhoneStorage
import app.tellyscope.data.FakeDeviceSource
@@ -190,6 +191,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
onAddByIp = vm::addByIp,
onBack = if (adding) ({ adding = false }) else null,
onOpenWifi = { context.openWifiSettings() },
+ phoneKey = remember { Connector.fingerprint() },
)
} else if (remote) {
BackHandler { remote = false }
diff --git a/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt b/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt
new file mode 100644
index 0000000..115898a
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/ConnectScreen.kt
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+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.Spacer
+import androidx.compose.foundation.layout.aspectRatio
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.BasicTextField
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material.icons.filled.Check
+import androidx.compose.material.icons.filled.Warning
+import androidx.compose.material3.Button
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.LoadingIndicator
+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.graphics.Color
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.input.KeyboardType
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import app.tellyscope.data.ScanHit
+import app.tellyscope.data.ScanKind
+import app.tellyscope.ui.theme.SmallNumber
+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.
+ */
+@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+fun ConnectScreen(
+ hit: ScanHit,
+ row: RowState,
+ now: Long,
+ brand: TvBrand,
+ phoneKey: String?,
+ onCode: (String) -> Unit,
+ onPair: () -> Unit,
+ onRetry: () -> Unit,
+ onBack: () -> Unit,
+) {
+ Scaffold(
+ topBar = {
+ TopAppBar(
+ title = {},
+ navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } },
+ )
+ },
+ bottomBar = {
+ Row(
+ Modifier.fillMaxWidth().padding(16.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ when (row) {
+ RowState.NotAllowed -> {
+ TextButton(onClick = onBack) { Text("Back to TVs") }
+ Button(onClick = onRetry) { Text("Try again") }
+ }
+ is RowState.Code -> {
+ TextButton(onClick = onBack) { Text("Cancel") }
+ val missing = CODE_LENGTH - row.input.length
+ // The button says what's missing instead of sitting there disabled with no reason.
+ Button(onClick = onPair, enabled = !row.busy && missing == 0) {
+ Text(
+ when {
+ row.busy -> "Pairing…"
+ missing == 0 -> "Pair"
+ missing == 1 -> "1 more digit"
+ else -> "$missing more digits"
+ },
+ )
+ }
+ }
+ else -> TextButton(onClick = onBack) { Text("Cancel") }
+ }
+ }
+ },
+ ) { 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(
+ listOfNotNull(hit.hostname ?: "Android device", hit.maker).distinct().joinToString(" · "),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ when (row) {
+ is RowState.Code -> {
+ Text("Type the pairing code", style = MaterialTheme.typography.headlineMedium)
+ Text(
+ "On the TV, open the pairing screen and type the 6 digits it shows.",
+ style = MaterialTheme.typography.bodyLarge,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ InfoBox { Text(marked(brand.pair ?: brands.first().pair.orEmpty()), style = MaterialTheme.typography.bodyMedium) }
+ Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
+ CodeBoxes(row.input, onChange = onCode, enabled = !row.busy, isError = row.error != null)
+ }
+ row.error?.let { Text(it, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodyMedium) }
+ row.detail?.let { Details(listOf("From the TV" to it)) }
+ }
+ RowState.NotAllowed -> {
+ Surface(Modifier.size(64.dp), shape = CircleShape, color = MaterialTheme.colorScheme.errorContainer) {
+ Box(contentAlignment = Alignment.Center) {
+ Icon(Icons.Default.Warning, null, Modifier.size(32.dp), tint = MaterialTheme.colorScheme.onErrorContainer)
+ }
+ }
+ Text("No answer from the TV", style = MaterialTheme.typography.headlineMedium)
+ Text(
+ "The TV didn't accept the connection.",
+ style = MaterialTheme.typography.bodyLarge,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ listOf(
+ "Is the TV on and awake?",
+ "Was the box on the TV closed, or Deny pressed? Try again and it asks once more.",
+ "Some TVs switch debugging off after a restart. Turn it back on.",
+ ).forEach { Text("• $it", style = MaterialTheme.typography.bodyMedium) }
+ }
+ }
+ // Wireless debugging TVs that already know this phone connect without asking.
+ is RowState.Waiting -> if (hit.kind == ScanKind.Wireless) Connecting() else {
+ Text("Allow on your TV", style = MaterialTheme.typography.headlineMedium)
+ Text(
+ marked(
+ if (phoneKey != null) "A box pops up on your TV. Check its key matches this phone's, tick **Always allow**, then select **Allow**."
+ else "A box pops up on your TV. Tick **Always allow**, then select **Allow**.",
+ ),
+ style = MaterialTheme.typography.bodyLarge,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ phoneKey?.let { key ->
+ InfoBox {
+ Text("This phone's key", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ // Two lines of eight pairs, so it reads like the TV's and compares at a glance.
+ Text(
+ key.split(':').chunked(8).joinToString("\n") { it.joinToString(":") },
+ style = MaterialTheme.typography.titleMedium.copy(fontFamily = FontFamily.Monospace),
+ )
+ }
+ }
+ TvPrompt(phoneKey)
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ LoadingIndicator(Modifier.size(32.dp))
+ Spacer(Modifier.width(12.dp))
+ Text(
+ "Waiting for the TV… ${((now - row.since) / 1000).coerceAtLeast(0)} s",
+ style = SmallNumber,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ }
+ RowState.Found -> Connecting()
+ }
+ }
+ }
+}
+
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun Connecting() {
+ Text("Connecting", style = MaterialTheme.typography.headlineMedium)
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ LoadingIndicator(Modifier.size(48.dp))
+ Spacer(Modifier.width(12.dp))
+ Text("Reaching the TV…", style = MaterialTheme.typography.bodyLarge)
+ }
+}
+
+@Composable
+private fun InfoBox(content: @Composable () -> Unit) {
+ Surface(Modifier.fillMaxWidth(), shape = MaterialTheme.shapes.medium, color = MaterialTheme.colorScheme.surfaceContainerHigh) {
+ Column(Modifier.padding(horizontal = 16.dp, vertical = 12.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) { content() }
+ }
+}
+
+/**
+ * A drawing of the box the TV shows, so people know what to look for. The TV's own colours,
+ * not the app theme: it's a picture of another screen. [key] appears where the TV prints it.
+ */
+@Composable
+private fun TvPrompt(key: String?) {
+ val accent = Color(0xFF80D4D5)
+ Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
+ Box(
+ Modifier.fillMaxWidth().aspectRatio(16f / 9f)
+ .background(Color(0xFF2B3131), RoundedCornerShape(10.dp))
+ .border(6.dp, Color(0xFF161D1D), RoundedCornerShape(10.dp)),
+ contentAlignment = Alignment.Center,
+ ) {
+ Column(
+ Modifier.fillMaxWidth(0.84f).background(Color(0xFF1C2222), RoundedCornerShape(12.dp)).padding(horizontal = 14.dp, vertical = 12.dp),
+ verticalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Text("Allow USB debugging?", color = Color.White, style = MaterialTheme.typography.titleSmall)
+ if (key != null) {
+ Text("The computer's RSA key fingerprint is:", color = Color(0xFFBEC8C8), fontSize = 9.sp, lineHeight = 12.sp)
+ Text(
+ key.split(':').chunked(8).joinToString(":\n") { it.joinToString(":") },
+ color = Color.White,
+ fontSize = 9.sp,
+ lineHeight = 12.sp,
+ fontFamily = FontFamily.Monospace,
+ modifier = Modifier.background(accent.copy(alpha = 0.25f), RoundedCornerShape(3.dp)).padding(horizontal = 2.dp),
+ )
+ }
+ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ Box(Modifier.size(16.dp).background(accent, RoundedCornerShape(3.dp)), contentAlignment = Alignment.Center) {
+ Icon(Icons.Default.Check, null, Modifier.size(14.dp), tint = Color(0xFF003738))
+ }
+ Text("Always allow from this computer", color = Color(0xFFE3E9E9), fontSize = 11.sp)
+ }
+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
+ Text("Cancel", color = accent, fontSize = 12.sp, modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp))
+ // Focused, the way the remote shows it.
+ Text(
+ "Allow",
+ color = Color(0xFF003738),
+ fontSize = 12.sp,
+ modifier = Modifier.background(accent, CircleShape).padding(horizontal = 12.dp, vertical = 6.dp),
+ )
+ }
+ }
+ }
+ Box(Modifier.width(56.dp).height(6.dp).background(Color(0xFF161D1D), RoundedCornerShape(bottomStart = 4.dp, bottomEnd = 4.dp)))
+ }
+}
+
+private const val CODE_LENGTH = 6
+
+/** One box per digit, on the number keypad. A single hidden field underneath, so paste and delete just work. */
+@Composable
+private fun CodeBoxes(code: String, onChange: (String) -> Unit, enabled: Boolean, isError: Boolean) {
+ BasicTextField(
+ value = code,
+ onValueChange = onChange,
+ modifier = Modifier.semantics { contentDescription = "Pairing code" },
+ enabled = enabled,
+ singleLine = true,
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
+ decorationBox = { _ ->
+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ repeat(CODE_LENGTH) { i ->
+ val current = enabled && i == code.length
+ val color = when {
+ isError -> MaterialTheme.colorScheme.error
+ current -> MaterialTheme.colorScheme.primary
+ else -> MaterialTheme.colorScheme.outline
+ }
+ Box(
+ Modifier.size(width = 44.dp, height = 56.dp)
+ .border(if (current) 2.dp else 1.dp, color, MaterialTheme.shapes.medium),
+ contentAlignment = Alignment.Center,
+ ) {
+ Text(code.getOrNull(i)?.toString().orEmpty(), style = StatNumber)
+ }
+ }
+ }
+ },
+ )
+}
diff --git a/app/src/main/java/app/tellyscope/ui/GuideCard.kt b/app/src/main/java/app/tellyscope/ui/GuideCard.kt
index 8f0884d..9eab039 100644
--- a/app/src/main/java/app/tellyscope/ui/GuideCard.kt
+++ b/app/src/main/java/app/tellyscope/ui/GuideCard.kt
@@ -2,108 +2,194 @@
package app.tellyscope.ui
+import androidx.compose.animation.animateContentSize
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
+import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
-import androidx.compose.material3.Card
-import androidx.compose.material3.CardDefaults
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Check
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Button
import androidx.compose.material3.FilterChip
-import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-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.text.AnnotatedString
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.buildAnnotatedString
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
-import app.tellyscope.ui.theme.SmallNumber
/**
- * Shown when a scan finds nothing. Steps differ per brand because the menu
- * names do. The scan keeps re-running behind this card, so the user never has
- * to come back and press anything.
+ * How to switch on debugging, per brand, because the menu names differ. [pair] is where the
+ * pairing code lives on TVs with Wireless debugging; null where the brand only has the older switch.
+ * `**…**` marks the words to find on the TV.
*/
-private val guides = linkedMapOf(
- "Google TV" to listOf(
- "Settings → System → About",
- "Highlight \"Android TV OS build\" and press OK 7 times, until it says you're a developer",
- "Back to System → Developer options",
- "Turn on \"USB debugging\"",
+class TvBrand(val name: String, val unlock: String, val debugTitle: String, val debug: String, val pair: String?)
+
+private const val ANDROID_TV_PAIR = "**Device Preferences → Developer options → Wireless debugging → Pair device with pairing code**"
+
+val brands = listOf(
+ TvBrand(
+ "Google TV",
+ unlock = "On the TV: **Settings → System → About**. Press OK on **Android TV OS build** 7 times, until it says you're a developer.",
+ debugTitle = "Turn on Wireless debugging",
+ debug = "Back to **System → Developer options**. Turn on **Wireless debugging**. Older TVs call it **USB debugging**.",
+ pair = "**System → Developer options → Wireless debugging → Pair device with pairing code**",
),
- "Android TV" to listOf(
- "Settings → Device Preferences → About",
- "Press OK on \"Build\" 7 times",
- "Back to Device Preferences → Developer options",
- "Turn on \"USB debugging\", and \"Network debugging\" if you see it",
+ TvBrand(
+ "Android TV",
+ unlock = "On the TV: **Settings → Device Preferences → About**. Press OK on **Build** 7 times.",
+ debugTitle = "Turn on Wireless debugging",
+ debug = "Back to **Device Preferences → Developer options**. Turn on **Wireless debugging**. Older TVs have **USB debugging** and **Network debugging** instead: turn on both.",
+ pair = ANDROID_TV_PAIR,
),
- "Fire TV" to listOf(
- "Settings → My Fire TV → About",
- "Press OK on the first row (your Fire TV's name) 7 times",
- "Back to My Fire TV → Developer options",
- "Turn on \"ADB debugging\"",
+ TvBrand(
+ "Fire TV",
+ unlock = "On the TV: **Settings → My Fire TV → About**. Press OK on the first row, your Fire TV's name, 7 times.",
+ debugTitle = "Turn on ADB debugging",
+ debug = "Back to **My Fire TV → Developer options**. Turn on **ADB debugging**.",
+ pair = null,
),
- "Xiaomi" to listOf(
- "Settings → Device Preferences → About",
- "Press OK on \"Build\" 7 times",
- "Back to Device Preferences → Developer options",
- "Turn on \"USB debugging\"",
+ TvBrand(
+ "Xiaomi",
+ unlock = "On the TV: **Settings → Device Preferences → About**. Press OK on **Build** 7 times.",
+ debugTitle = "Turn on Wireless debugging",
+ debug = "Back to **Device Preferences → Developer options**. Turn on **Wireless debugging**. Older TVs call it **USB debugging**.",
+ pair = ANDROID_TV_PAIR,
),
- "XGIMI" to listOf(
- "Settings → Device Preferences → About",
- "Press OK on \"Build\" 7 times",
- "Back to Device Preferences → Developer options",
- "Turn on \"USB debugging\", then \"Network debugging\" if it's listed",
+ TvBrand(
+ "XGIMI",
+ unlock = "On the TV: **Settings → Device Preferences → About**. Press OK on **Build** 7 times.",
+ debugTitle = "Turn on Wireless debugging",
+ debug = "Back to **Device Preferences → Developer options**. Turn on **Wireless debugging**. Older projectors have **USB debugging**, then **Network debugging** if it's listed: turn on both.",
+ pair = ANDROID_TV_PAIR,
),
)
+/** The brand chips: every brand stays visible, so nobody has to guess what a menu hides. */
@OptIn(ExperimentalLayoutApi::class)
@Composable
-fun GuideCard(modifier: Modifier = Modifier) {
- var brand by rememberSaveable { mutableStateOf(guides.keys.first()) }
- Card(
- modifier.fillMaxWidth(),
- colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh),
- ) {
- Column(Modifier.padding(20.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
- Text("Turn on debugging on your TV", style = MaterialTheme.typography.titleLarge)
- Text(
- "Pick your TV and follow the steps on it. This screen finds it on its own when you're done.",
- style = MaterialTheme.typography.bodyMedium,
- )
- FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- guides.keys.forEach { b ->
- FilterChip(selected = b == brand, onClick = { brand = b }, label = { Text(b) })
- }
+fun BrandChips(brand: TvBrand, onPick: (TvBrand) -> Unit) {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text("Pick your TV", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ brands.forEach { b ->
+ FilterChip(
+ selected = b == brand,
+ onClick = { onPick(b) },
+ label = { Text(b.name) },
+ leadingIcon = if (b == brand) ({ Icon(Icons.Default.Check, null, Modifier.size(18.dp)) }) else null,
+ )
}
- guides.getValue(brand).forEachIndexed { i, step ->
- Row {
- Text("${i + 1}", style = SmallNumber, color = MaterialTheme.colorScheme.primary)
- androidx.compose.foundation.layout.Spacer(Modifier.width(12.dp))
- Text(step, style = MaterialTheme.typography.bodyLarge)
+ }
+ }
+}
+
+/**
+ * One step open at a time: "Done, next" ticks it off and opens the next, "Back" reopens the one
+ * before. The last step holds [findTvs], which is the live scan and whatever it found.
+ */
+@Composable
+fun GuideSteps(brand: TvBrand, step: Int, onStep: (Int) -> Unit, findTvs: @Composable () -> Unit) {
+ val steps = listOf(
+ Triple("Unlock developer options", brand.unlock, "Developer options unlocked"),
+ Triple(brand.debugTitle, brand.debug, brand.debugTitle.removePrefix("Turn on ") + " on"),
+ Triple("Find your TV", "", ""),
+ )
+ Column(Modifier.animateContentSize(MaterialTheme.motionScheme.defaultSpatialSpec())) {
+ steps.forEachIndexed { i, (title, body, done) ->
+ val last = i == steps.lastIndex
+ Row(Modifier.height(IntrinsicSize.Min)) {
+ Column(Modifier.width(32.dp).fillMaxHeight(), horizontalAlignment = Alignment.CenterHorizontally) {
+ StepDot(i + 1, done = i < step, current = i == step)
+ if (!last) Box(Modifier.padding(vertical = 4.dp).width(2.dp).weight(1f).background(MaterialTheme.colorScheme.outlineVariant))
+ }
+ Column(
+ Modifier.padding(start = 16.dp, top = 4.dp, bottom = if (last) 8.dp else 24.dp).weight(1f),
+ verticalArrangement = Arrangement.spacedBy(4.dp),
+ ) {
+ Text(
+ title,
+ style = MaterialTheme.typography.titleMedium,
+ color = if (i > step) MaterialTheme.colorScheme.outline else MaterialTheme.colorScheme.onSurface,
+ )
+ when {
+ i < step -> Text(done, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ i == step && last -> findTvs()
+ i == step -> {
+ Text(marked(body), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Row(Modifier.padding(top = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ Button(onClick = { onStep(i + 1) }) { Text("Done, next") }
+ if (i > 0) TextButton(onClick = { onStep(i - 1) }) { Text("Back") }
+ }
+ }
+ }
}
}
- HorizontalDivider()
- Text(
- "Newer TVs (Android 11+) may show \"Wireless debugging\" instead. Turn that on too; you'll type a 6-digit code when you connect.",
- style = MaterialTheme.typography.bodySmall,
- )
- if (brand == "Fire TV") {
- Text(
- "No Developer options after 7 presses? Newer Fire TVs run Vega OS, which isn't Android, and Tellyscope can't reach them.",
- style = MaterialTheme.typography.bodySmall,
- )
- }
- Text(
- "Debugging switched itself off? Some TVs reset it after a restart. Turn it back on and this screen reconnects.",
- style = MaterialTheme.typography.bodySmall,
- )
}
}
}
+
+@Composable
+private fun StepDot(n: Int, done: Boolean, current: Boolean) {
+ val c = MaterialTheme.colorScheme
+ val filled = done || current
+ Box(
+ Modifier.size(32.dp)
+ .background(if (filled) c.primary else c.surface, CircleShape)
+ .border(2.dp, if (filled) c.primary else c.outlineVariant, CircleShape),
+ contentAlignment = Alignment.Center,
+ ) {
+ if (done) Icon(Icons.Default.Check, contentDescription = "Done", Modifier.size(18.dp), tint = c.onPrimary)
+ else Text("$n", style = MaterialTheme.typography.labelLarge, color = if (current) c.onPrimary else c.outline)
+ }
+}
+
+/** "Can't find your TV?": the fixes that used to sit under the guide as small print. */
+@Composable
+fun HelpDialog(brand: TvBrand, onAddByIp: () -> Unit, onDismiss: () -> Unit) {
+ val tips = buildList {
+ add("Keep the phone and the TV on the same Wi-Fi. Guest networks often keep devices apart.")
+ add("Debugging switched itself off? Some TVs reset it after a restart. Turn it back on and this screen finds the TV again.")
+ if (brand.name == "Fire TV") add("No Developer options after 7 presses? Newer Fire TVs run Vega OS, which isn't Android, and Tellyscope can't reach them.")
+ add("Still nothing? Add the TV by its IP address, from the TV's network settings.")
+ }
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = { Text("Can't find your TV?") },
+ text = {
+ Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
+ tips.forEach { Text(it, style = MaterialTheme.typography.bodyMedium) }
+ }
+ },
+ confirmButton = { TextButton(onClick = { onDismiss(); onAddByIp() }) { Text("Add by IP address") } },
+ dismissButton = { TextButton(onClick = onDismiss) { Text("Close") } },
+ )
+}
+
+/** Turns `**words**` into medium-weight spans: the menu names to look for on the TV. */
+@Composable
+fun marked(text: String): AnnotatedString {
+ val strong = SpanStyle(fontWeight = FontWeight.Medium, color = MaterialTheme.colorScheme.onSurface)
+ return buildAnnotatedString {
+ text.split("**").forEachIndexed { i, part -> if (i % 2 == 1) withStyle(strong) { append(part) } else append(part) }
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt b/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
index 000e321..0e0ddd0 100644
--- a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
@@ -2,12 +2,10 @@
package app.tellyscope.ui
-import androidx.compose.animation.animateContentSize
-import androidx.compose.foundation.border
+import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
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
@@ -16,13 +14,14 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Add
+import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
@@ -33,10 +32,8 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
-import androidx.compose.material3.LinearWavyProgressIndicator
import androidx.compose.material3.LoadingIndicator
import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
@@ -44,23 +41,27 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+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.semantics.contentDescription
-import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import app.tellyscope.data.ScanHit
-import app.tellyscope.data.ScanKind
import app.tellyscope.ui.theme.SmallNumber
-import app.tellyscope.ui.theme.StatNumber
-@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
+/**
+ * "Add your TV": pick the brand, follow its steps one at a time, then pick the TV the scan found.
+ * The scan runs from the start, so a TV that turns up early skips the steps it has proved done.
+ * Connect opens that TV's own [ConnectScreen]; [phoneKey] is shown there for the Allow box.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScanScreen(
scan: ScanUi,
@@ -72,53 +73,158 @@ fun ScanScreen(
onAddByIp: (String) -> String?,
onBack: (() -> Unit)? = null,
onOpenWifi: () -> Unit = {},
+ phoneKey: String? = null,
) {
var adding by remember { mutableStateOf(false) }
+ var help by remember { mutableStateOf(false) }
+ var brandName by rememberSaveable { mutableStateOf(brands.first().name) }
+ val brand = brands.first { it.name == brandName }
+ var step by rememberSaveable { mutableIntStateOf(if (scan.hits.isEmpty()) 0 else 2) }
+ // The TV whose connect screen is open. A successful connect leaves this screen altogether.
+ var open by rememberSaveable { mutableStateOf<String?>(null) }
+ LaunchedEffect(scan.hits.isNotEmpty()) { if (scan.hits.isNotEmpty()) step = 2 }
+
+ val openHit = scan.hits.firstOrNull { it.ip == open }
+ if (openHit != null) {
+ BackHandler { open = null }
+ ConnectScreen(
+ hit = openHit,
+ row = scan.rows[openHit.ip] ?: RowState.Found,
+ now = now,
+ brand = brand,
+ phoneKey = phoneKey,
+ onCode = { onCode(openHit, it) },
+ onPair = { onPair(openHit) },
+ onRetry = { onConnect(openHit) },
+ onBack = { open = null },
+ )
+ return
+ }
+
Scaffold(
topBar = {
TopAppBar(
- title = { Text("Tellyscope") },
- navigationIcon = { if (onBack != null) TextButton(onClick = onBack) { Text("Done") } },
- actions = {
- IconButton(onClick = onRescan, enabled = !scan.scanning) {
- Icon(Icons.Default.Refresh, contentDescription = "Scan again")
- }
+ title = {},
+ navigationIcon = {
+ if (onBack != null) IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") }
},
)
},
) { pad ->
if (scan.offWifi) {
OffWifi(Modifier.padding(pad), onOpenWifi, onAddByIp = { adding = true })
- } else LazyColumn(
- Modifier.fillMaxSize().padding(pad),
- contentPadding = PaddingValues(16.dp),
- verticalArrangement = Arrangement.spacedBy(12.dp),
+ } else Column(
+ Modifier.fillMaxSize().padding(pad).verticalScroll(rememberScrollState()).padding(horizontal = 16.dp, vertical = 8.dp),
+ verticalArrangement = Arrangement.spacedBy(20.dp),
) {
- item {
- Text("What's running on your TV?", style = MaterialTheme.typography.headlineMedium)
- Text(
- "Live stats, apps and network for the Android TVs on your Wi-Fi.",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- item { ScanStatus(scan) }
- items(scan.hits, key = { it.ip }) { hit ->
- HitCard(hit, scan.rows[hit.ip] ?: RowState.Found, now, onConnect, onCode, onPair)
+ Text("Add your TV", style = MaterialTheme.typography.headlineMedium)
+ Surface(shape = MaterialTheme.shapes.large, color = MaterialTheme.colorScheme.secondaryContainer) {
+ Row(Modifier.fillMaxWidth().padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
+ Icon(Icons.Default.Info, null, Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSecondaryContainer)
+ Spacer(Modifier.width(12.dp))
+ Text(
+ if (scan.noLan) "You're not on Wi-Fi, so only TVs that announce themselves show up. Join your TV's Wi-Fi."
+ else "Keep your phone and TV on the same Wi-Fi.",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSecondaryContainer,
+ )
+ }
}
- if (!scan.scanning && scan.hits.isEmpty()) {
- item { GuideCard() }
+ BrandChips(brand, onPick = { brandName = it.name })
+ GuideSteps(brand, step, onStep = { step = it }) {
+ FoundTvs(scan, onRescan, onPick = { hit ->
+ val row = scan.rows[hit.ip] ?: RowState.Found
+ if (row == RowState.Found || row == RowState.NotAllowed) onConnect(hit)
+ open = hit.ip
+ })
}
- item {
- OutlinedButton(onClick = { adding = true }) {
+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ TextButton(onClick = { adding = true }) {
Icon(Icons.Default.Add, null, Modifier.size(18.dp))
Spacer(Modifier.width(8.dp))
Text("Add by IP address")
}
+ TextButton(onClick = { help = true }) { Text("Can't find your TV?") }
+ }
+ }
+ }
+ if (help) HelpDialog(brand, onAddByIp = { adding = true }, onDismiss = { help = false })
+ if (adding) AddByIpDialog(
+ subnet = scan.progress?.subnet,
+ onDismiss = { adding = false },
+ onSubmit = { text ->
+ onAddByIp(text).also { e ->
+ if (e == null) {
+ adding = false
+ open = text.trim().substringBefore(':')
+ }
+ }
+ },
+ )
+}
+
+/** Step 3: what the scan has found so far, each a tap away from its connect screen. */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun FoundTvs(scan: ScanUi, onRescan: () -> Unit, onPick: (ScanHit) -> Unit) {
+ Column(Modifier.padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ scan.hits.forEach { hit ->
+ val row = scan.rows[hit.ip] ?: RowState.Found
+ Card(
+ Modifier.fillMaxWidth(),
+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
+ ) {
+ Row(Modifier.padding(start = 16.dp, top = 12.dp, end = 12.dp, bottom = 12.dp), verticalAlignment = Alignment.CenterVertically) {
+ Icon(DeviceIcons.Tv, null, Modifier.size(24.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
+ Spacer(Modifier.width(16.dp))
+ Column(Modifier.weight(1f)) {
+ Text(hit.hostname ?: hit.maker ?: "Android device", style = MaterialTheme.typography.titleMedium)
+ Text(
+ listOfNotNull(hit.maker, hit.ip).joinToString(" · "),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ FilledTonalButton(onClick = { onPick(hit) }) {
+ Text(
+ when (row) {
+ RowState.Found -> "Connect"
+ RowState.NotAllowed -> "Try again"
+ else -> "Continue"
+ },
+ )
+ }
+ }
+ }
+ }
+ val p = scan.progress
+ Row(Modifier.padding(vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {
+ when {
+ scan.scanning -> {
+ LoadingIndicator(Modifier.size(32.dp))
+ Spacer(Modifier.width(12.dp))
+ Text(
+ "Looking for ${if (scan.hits.isEmpty()) "your TV" else "more TVs"}…",
+ Modifier.weight(1f),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ if (p != null) Text("${p.probed}/${p.total}", style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ // An empty scan starts again by itself; only a list that has something offers the button.
+ scan.hits.isEmpty() -> Text(
+ "No TV yet. Tellyscope looks again in a moment.",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ else -> TextButton(onClick = onRescan) {
+ Icon(Icons.Default.Refresh, null, Modifier.size(18.dp))
+ Spacer(Modifier.width(8.dp))
+ Text("Scan again")
+ }
}
}
}
- if (adding) AddByIpDialog(subnet = scan.progress?.subnet, onDismiss = { adding = false }, onSubmit = { onAddByIp(it).also { e -> if (e == null) adding = false } })
}
/** Off Wi-Fi with no TV announcing itself: one way forward instead of an empty list. */
@@ -149,161 +255,6 @@ private fun OffWifi(modifier: Modifier, onOpenWifi: () -> Unit, onAddByIp: () ->
}
}
-@OptIn(ExperimentalMaterial3ExpressiveApi::class)
-@Composable
-private fun ScanStatus(scan: ScanUi) {
- val p = scan.progress
- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- if (scan.scanning) {
- Text(
- "Looking for TVs${if (scan.noLan) "" else " on your Wi-Fi"}… ${p?.probed ?: 0}/${p?.total ?: 254}",
- style = MaterialTheme.typography.labelLarge,
- )
- LinearWavyProgressIndicator(
- progress = { p?.let { it.probed / it.total.toFloat() } ?: 0f },
- modifier = Modifier.fillMaxWidth(),
- )
- } else {
- val n = scan.hits.size
- Text(
- if (n == 0) "No TVs found yet" else "Found $n ${if (n == 1) "TV" else "TVs"}${if (scan.noLan) "" else " on your Wi-Fi"}",
- style = MaterialTheme.typography.labelLarge,
- )
- }
- if (scan.noLan) {
- Text(
- "You're not on Wi-Fi, so only TVs that announce themselves show up. Join the TV's Wi-Fi, or add it by IP address.",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- }
-}
-
-@OptIn(ExperimentalMaterial3ExpressiveApi::class)
-@Composable
-private fun HitCard(
- hit: ScanHit,
- row: RowState,
- now: Long,
- onConnect: (ScanHit) -> Unit,
- onCode: (ScanHit, String) -> Unit,
- onPair: (ScanHit) -> Unit,
-) {
- Card(
- Modifier.fillMaxWidth().animateContentSize(MaterialTheme.motionScheme.defaultSpatialSpec()),
- colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
- ) {
- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Column(Modifier.weight(1f)) {
- Text(hit.hostname ?: hit.maker ?: "Android device", style = MaterialTheme.typography.titleMedium)
- Text(
- hit.maker ?: "Unknown maker",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- Details(listOf("IP address" to hit.ip, "Port" to hit.port.toString()))
- }
- when (row) {
- RowState.Found -> FilledTonalButton(onClick = { onConnect(hit) }) { Text("Connect") }
- RowState.NotAllowed -> FilledTonalButton(onClick = { onConnect(hit) }) { Text("Try again") }
- else -> Unit
- }
- }
- when (row) {
- RowState.Found -> Text(
- if (hit.kind == ScanKind.Wireless) "Needs the pairing code from the TV" else "Ready to connect",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- is RowState.Waiting -> if (hit.kind == ScanKind.Wireless) Row(verticalAlignment = Alignment.CenterVertically) {
- LoadingIndicator(Modifier.size(32.dp))
- Spacer(Modifier.width(12.dp))
- Text("Connecting…", style = MaterialTheme.typography.bodyMedium)
- } else Row(verticalAlignment = Alignment.CenterVertically) {
- LoadingIndicator(Modifier.size(48.dp))
- Spacer(Modifier.width(12.dp))
- Column {
- Text("Check your TV", style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary)
- Text(
- "A box saying \"Allow USB debugging?\" is on screen. Tick \"Always allow from this computer\", then press Allow.",
- style = MaterialTheme.typography.bodyMedium,
- )
- Text(
- "Waiting… ${((now - row.since) / 1000).coerceAtLeast(0)} s",
- style = SmallNumber,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- }
- RowState.NotAllowed -> Column {
- Text("No answer from the TV", style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.error)
- Text(
- "Is the box still on screen? If you pressed Deny by mistake, tap Try again and it will ask once more.",
- style = MaterialTheme.typography.bodyMedium,
- )
- }
- is RowState.Code -> Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- Text(
- "On the TV: Settings → Developer options → Wireless debugging → Pair device with pairing code. Type the 6 digits it shows:",
- style = MaterialTheme.typography.bodyMedium,
- )
- CodeBoxes(row.input, onChange = { onCode(hit, it) }, enabled = !row.busy, isError = row.error != null)
- val missing = CODE_LENGTH - row.input.length
- // The button says what's missing instead of sitting there disabled with no reason.
- Button(onClick = { onPair(hit) }, enabled = !row.busy && missing == 0) {
- Text(
- when {
- row.busy -> "Pairing…"
- missing == 0 -> "Pair"
- missing == 1 -> "1 more digit"
- else -> "$missing more digits"
- },
- )
- }
- row.error?.let { Text(it, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodyMedium) }
- row.detail?.let { Details(listOf("From the TV" to it)) }
- }
- }
- }
- }
-}
-
-private const val CODE_LENGTH = 6
-
-/** One box per digit, on the number keypad. A single hidden field underneath, so paste and delete just work. */
-@Composable
-private fun CodeBoxes(code: String, onChange: (String) -> Unit, enabled: Boolean, isError: Boolean) {
- BasicTextField(
- value = code,
- onValueChange = onChange,
- modifier = Modifier.semantics { contentDescription = "Pairing code" },
- enabled = enabled,
- singleLine = true,
- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
- decorationBox = { _ ->
- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- repeat(CODE_LENGTH) { i ->
- val current = enabled && i == code.length
- val color = when {
- isError -> MaterialTheme.colorScheme.error
- current -> MaterialTheme.colorScheme.primary
- else -> MaterialTheme.colorScheme.outline
- }
- Box(
- Modifier.size(width = 44.dp, height = 56.dp)
- .border(if (current) 2.dp else 1.dp, color, MaterialTheme.shapes.medium),
- contentAlignment = Alignment.Center,
- ) {
- Text(code.getOrNull(i)?.toString().orEmpty(), style = StatNumber)
- }
- }
- }
- },
- )
-}
-
@Composable
private fun AddByIpDialog(subnet: String?, onDismiss: () -> Unit, onSubmit: (String) -> String?) {
var text by remember { mutableStateOf("") }
diff --git a/app/src/test/java/app/tellyscope/OffWifiTest.kt b/app/src/test/java/app/tellyscope/OffWifiTest.kt
index 3106a53..3d0f938 100644
--- a/app/src/test/java/app/tellyscope/OffWifiTest.kt
+++ b/app/src/test/java/app/tellyscope/OffWifiTest.kt
@@ -6,6 +6,7 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performScrollTo
import androidx.lifecycle.viewModelScope
import app.tellyscope.data.Device
import app.tellyscope.data.DeviceSource
@@ -74,13 +75,13 @@ class OffWifiTest {
@Test fun aTvThatAnnouncedItselfStillShows() {
show(ScanUi(noLan = true, hits = listOf(tv), rows = mapOf(tv.ip to RowState.Found)))
- compose.onNodeWithText("chromecast").assertIsDisplayed()
+ compose.onNodeWithText("chromecast").performScrollTo().assertIsDisplayed()
compose.onNodeWithText("This phone isn't on Wi-Fi").assertDoesNotExist()
}
@Test fun onWifiShowsTheScan() {
show(ScanUi())
- compose.onNodeWithText("What's running on your TV?").assertIsDisplayed()
+ compose.onNodeWithText("Add your TV").assertIsDisplayed()
compose.onNodeWithText("This phone isn't on Wi-Fi").assertDoesNotExist()
}
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index f3012ab..4b39cdd 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -50,6 +50,7 @@ import app.tellyscope.data.Suggested
import app.tellyscope.data.SuggestedGroup
import app.tellyscope.data.Suggestions
import app.tellyscope.ui.AdvancedScreen
+import app.tellyscope.ui.ConnectScreen
import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceTabsScreen
@@ -74,6 +75,7 @@ import app.tellyscope.ui.ScanScreen
import app.tellyscope.ui.ScanUi
import app.tellyscope.ui.SideloadUi
import app.tellyscope.ui.TransferUi
+import app.tellyscope.ui.brands
import app.tellyscope.ui.UiState
import app.tellyscope.ui.theme.TellyscopeTheme
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
@@ -135,15 +137,7 @@ class ScreenshotTest {
ScanScreen(ui, now, {}, {}, { _, _ -> }, {}, { null })
}
- @Test fun scan_inProgress() = scan(
- ScanUi(
- scanning = true,
- progress = ScanProgress(115, 254, "192.168.1.0/24"),
- hits = listOf(xgimi, box),
- rows = mapOf(xgimi.ip to RowState.Found, box.ip to RowState.Found),
- ),
- name = "01_scan_in_progress",
- )
+ @Test fun scan_inProgress() = scan(inProgress, name = "01_scan_in_progress")
private val connectStates get() = ScanUi(
scanning = false,
@@ -160,11 +154,39 @@ class ScreenshotTest {
@Test fun scan_connectStates_dark() = scan(connectStates, dark = true, name = "02_scan_connect_states")
- @Test fun scan_empty() = scan(
- ScanUi(scanning = false, progress = ScanProgress(254, 254, "192.168.1.0/24")),
- name = "03_scan_empty_guide",
+ private val inProgress get() = ScanUi(
+ scanning = true,
+ progress = ScanProgress(115, 254, "192.168.1.0/24"),
+ hits = listOf(xgimi, box),
+ rows = mapOf(xgimi.ip to RowState.Found, box.ip to RowState.Found),
)
+ @Test fun scan_inProgress_dark() = scan(inProgress, dark = true, name = "01_scan_in_progress")
+
+ private val empty = ScanUi(scanning = true, progress = ScanProgress(40, 254, "192.168.1.0/24"))
+
+ @Test fun scan_empty() = scan(empty, name = "03_scan_empty_guide")
+
+ @Test fun scan_empty_dark() = scan(empty, dark = true, name = "03_scan_empty_guide")
+
+ private val key = "3F:A2:91:0C:7B:E4:58:D6:21:9A:C3:4F:80:1E:B7:65"
+
+ private fun connect(hit: ScanHit, row: RowState, dark: Boolean, name: String) = shot(name, dark) {
+ ConnectScreen(hit, row, now, brands.first(), key, {}, {}, {}, {})
+ }
+
+ @Test fun connect_code() = connect(chromecast, RowState.Code("4821"), false, "03_connect_code")
+
+ @Test fun connect_code_dark() = connect(chromecast, RowState.Code("4821"), true, "03_connect_code")
+
+ @Test fun connect_allow() = connect(xgimi, RowState.Waiting(now - 12_000), false, "03_connect_allow")
+
+ @Test fun connect_allow_dark() = connect(xgimi, RowState.Waiting(now - 12_000), true, "03_connect_allow")
+
+ @Test fun connect_notAllowed() = connect(unknown, RowState.NotAllowed, false, "03_connect_no_answer")
+
+ @Test fun connect_notAllowed_dark() = connect(unknown, RowState.NotAllowed, true, "03_connect_no_answer")
+
private fun deviceState(device: DeviceUi.() -> DeviceUi = { this }): UiState = runBlocking {
val d = Device(xgimi.ip, xgimi, DeviceState.Online, "XGIMI Horizon Pro", "XGIMI", "11", now)
UiState(
diff --git a/docs/screenshots/add-tv.png b/docs/screenshots/add-tv.png
new file mode 100644
index 0000000..c9315b7
Binary files /dev/null and b/docs/screenshots/add-tv.png differ
diff --git a/docs/screenshots/connect.png b/docs/screenshots/connect.png
new file mode 100644
index 0000000..e747c93
Binary files /dev/null and b/docs/screenshots/connect.png differ
diff --git a/docs/screenshots/frame.py b/docs/screenshots/frame.py
index d2fb83f..92faaa0 100644
--- a/docs/screenshots/frame.py
+++ b/docs/screenshots/frame.py
@@ -20,6 +20,8 @@ OUT = Path(__file__).parent
# so the top bar and the tabs along the bottom stay in shot.
SHOTS = {
"welcome": "00_welcome",
+ "add-tv": "01_scan_in_progress",
+ "connect": "03_connect_allow",
"tv-page": "04_device",
"debloat": "20_readme_debloat",
"debloat-confirm": "21_readme_confirm",