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.

Make the TV page plain, add Debloat and Advanced

jesse-agent-2328f640016afbc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac5f35b..cf65460 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,3 +22,5 @@ until this file has a section for its version.
- **Improved:** System updaters, Wi-Fi resources and Chrome's library are now protected. [#19](../../pull/19)
- **Fixed:** Done and error messages stay on screen long enough to read. [#20](../../pull/20)
- **Fixed:** Undo and results always go to the TV the action ran on. [#20](../../pull/20)
+- **New:** Debloat in two steps: pick your TV, then review every app it turns off. [#23](../../pull/23)
+- **Improved:** The TV page uses plain words; every number moves to a new Advanced screen. [#23](../../pull/23)
diff --git a/README.md b/README.md
index 3f6f642..8ca1c16 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,8 @@ See inside your Android TV from your phone. Live stats, reversible debloat, app
<p>
<img src="docs/screenshots/scan.png" width="200" alt="Finding TVs on the Wi-Fi">
- <img src="docs/screenshots/tv-page.png" width="200" alt="A TV's page: memory, storage, CPU and temperature">
+ <img src="docs/screenshots/tv-page.png" width="200" alt="A TV's page: how it's doing, free space and suggested clean-up">
+ <img src="docs/screenshots/debloat.png" width="200" alt="Debloat: reviewing the apps it will turn off">
<img src="docs/screenshots/install.png" width="200" alt="Installing an app on the TV">
</p>
@@ -18,9 +19,10 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
- **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.
- **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.
-- **Live stats.** Memory, storage, CPU, temperature and uptime, with a one-line summary such as "Running fine" or "Storage almost full".
+- **How it's doing.** A one-line summary such as "Running fine" or "Storage almost full", and how much space is free.
+- **Advanced.** Every number in one place: memory, storage, CPU, temperature, uptime and screen state, CPU and RAM by app, processes, network and data used, and the TV's address.
- **Apps.** Every app on the TV with its real name and icon. Stop, disable, turn back on or open any app that isn't protected; each button says what it will do and asks first.
-- **Suggested for this TV.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and shows the apps on it that are still on. Pick your model if it isn't matched. Apps are pre-ticked only when the TV runs the Android version the list was tested on, and you confirm before anything is disabled.
+- **Debloat.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and says how many of its apps are still on. **Debloat** first asks which TV it is, with the match already chosen, then shows every app it will turn off. Apps are pre-ticked only when the TV runs the Android version the list was tested on; untick anything you use, and you confirm before anything is disabled.
- **History.** Every change is listed with an Undo, and **Restore everything** turns back on what Tellyscope turned off. History is kept per TV, across restarts.
- **Install apps.** Pick an APK, several split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. Before installing, Tellyscope shows the app's name, version and size and says whether it's new, an update, a reinstall or an older version. It won't install an older version over a newer one unless you tick the box. If the TV refuses, you get the reason in plain words.
- **Files.** Send a file from your phone into the TV's Download or Movies folder, or save one from there to your phone. A file with the same name gets a " (1)" instead of being overwritten, and a cancelled copy leaves nothing half-written behind.
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index a1fee2d..f7b60cf 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -34,7 +34,9 @@ import androidx.lifecycle.viewmodel.viewModelFactory
import app.tellyscope.data.AdbDeviceSource
import app.tellyscope.data.AndroidPhoneStorage
import app.tellyscope.data.FakeDeviceSource
+import app.tellyscope.ui.AdvancedScreen
import app.tellyscope.ui.Copy
+import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceScreen
import app.tellyscope.ui.Done
@@ -123,6 +125,8 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
val snackbar = remember { SnackbarHostState() }
var adding by rememberSaveable { mutableStateOf(false) }
var remote by rememberSaveable { mutableStateOf(false) }
+ var advanced by rememberSaveable { mutableStateOf(false) }
+ var debloat by rememberSaveable { mutableStateOf(false) }
// "*/*": file managers label .apks and .xapk bundles inconsistently, so a narrower type would grey them out.
val pickApp = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { vm.pickedApp(it) }
@@ -132,7 +136,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
Snackbars(snackbar, vm.done, vm.notice, vm::doneShown, vm::noticeShown) { vm.undo(it.entry, it.deviceId) }
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
- LaunchedEffect(state.selectedId) { adding = false; remote = false }
+ LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; debloat = false }
if (state.selected == null || adding) {
BackHandler(enabled = adding) { adding = false }
@@ -158,6 +162,18 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
back = { remote = false },
),
)
+ } else if (advanced) {
+ BackHandler { advanced = false }
+ AdvancedScreen(state, back = { advanced = false }, snackbar = snackbar)
+ } else if (debloat) {
+ // Its own back handler steps back from the review to the model before leaving.
+ DebloatScreen(
+ state.device.lists,
+ onPick = vm::pickList,
+ onDisable = vm::disableSuggested,
+ back = { debloat = false },
+ snackbar = snackbar,
+ )
} else {
DeviceScreen(
state = state,
@@ -184,9 +200,9 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
pickFile = { folder -> vm.folder(folder); pickFile.launch(arrayOf("*/*")) },
saveFile = { f -> vm.saving(f); saveFile.launch(f.name) },
cancelTransfer = vm::cancelTransfer,
- pickList = vm::pickList,
- disableSuggested = vm::disableSuggested,
remote = { remote = true },
+ debloat = { debloat = true },
+ advanced = { advanced = true },
),
)
}
diff --git a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
new file mode 100644
index 0000000..5cdc7d0
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
@@ -0,0 +1,289 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+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.fillMaxHeight
+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.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material3.Card
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.LinearProgressIndicator
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+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.Modifier
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import app.tellyscope.data.AppInfo
+import app.tellyscope.data.AppNames
+import app.tellyscope.data.DeviceState
+import app.tellyscope.data.NetworkInfo
+import app.tellyscope.data.Proc
+import app.tellyscope.data.Snapshot
+import app.tellyscope.ui.theme.SmallNumber
+import app.tellyscope.ui.theme.StatNumber
+
+/**
+ * Everything with a number in it, kept off the TV's page: the full stats, CPU and RAM by app,
+ * processes, network, and the TV's address details.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun AdvancedScreen(
+ state: UiState,
+ back: () -> Unit,
+ snackbar: SnackbarHostState = remember { SnackbarHostState() },
+) {
+ val device = state.selected ?: return
+ val ui = state.device
+ val snap = ui.snapshot
+ val offline = device.state != DeviceState.Online
+ val labels = ui.apps.associate { it.packageName to it.label }
+ fun label(p: Proc) = p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEM
+ val byApp = snap?.procs.orEmpty().groupBy(::label)
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(snackbar) },
+ topBar = {
+ TopAppBar(
+ title = { Text("Advanced") },
+ navigationIcon = {
+ IconButton(onClick = back) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back to the TV's page") }
+ },
+ )
+ },
+ ) { pad ->
+ LazyColumn(
+ Modifier.fillMaxSize().padding(pad),
+ contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 32.dp),
+ verticalArrangement = Arrangement.spacedBy(12.dp),
+ ) {
+ item {
+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
+ Column(Modifier.fillMaxWidth().padding(16.dp)) {
+ Text("This TV", style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(bottom = 4.dp))
+ listOfNotNull(
+ "IP address" to device.hit.ip,
+ "Port" to device.hit.port.toString(),
+ (device.manufacturer ?: device.hit.maker)?.let { "Maker" to it },
+ device.hit.hostname?.let { "Network name" to it },
+ ).forEach { (k, v) -> KeyValue(k, v) }
+ }
+ }
+ }
+ if (snap != null) {
+ // Offline: the last stats this phone saw, greyed and dated, rather than a grid of blanks.
+ item { Stats(snap, if (offline) state.now else null) }
+ } else {
+ item {
+ Text(
+ if (offline) Copy.noStats(device.state) else "Loading stats…",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ }
+ // A TV that lists no processes gets no charts: no bars beats an empty card.
+ if (byApp.isNotEmpty()) {
+ item { UsageCard("CPU by app", byApp.map { (n, ps) -> n to ps.sumOf { it.cpuPercent } }, fmt = { "%.0f%%".format(it) }) }
+ item { UsageCard("RAM by app", byApp.map { (n, ps) -> n to ps.sumOf { it.ramMb }.toDouble() }, fmt = { Copy.mb(it.toInt()) }) }
+ item { Block("Processes") { ProcessTable(snap?.procs.orEmpty(), ui.apps) } }
+ }
+ ui.network?.let { n -> item { Block("Network") { NetworkBlock(n) } } }
+ }
+ }
+}
+
+@Composable
+private fun Block(title: String, body: @Composable () -> Unit) {
+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)) {
+ Column(Modifier.fillMaxWidth().padding(16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
+ Text(title, style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(bottom = 4.dp))
+ body()
+ }
+ }
+}
+
+/**
+ * Memory and storage as "75% used" with a bar, then the small stats. Missing stats show "—",
+ * never 0. [staleSince] set means the TV is offline: these are its last numbers, greyed and dated.
+ */
+@Composable
+private fun Stats(s: Snapshot, staleSince: Long?) {
+ val cells = listOf(
+ "CPU" to "${s.cpuPercent}%",
+ "Temperature" to s.tempC?.let { "$it°C" },
+ "On for" to Copy.uptime(s.uptimeSeconds),
+ "Screen" to s.screenOn?.let { if (it) "On" else "Off" },
+ )
+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
+ if (staleSince != null) {
+ Text(
+ "As of ${Copy.ago(s.at, staleSince)}",
+ style = MaterialTheme.typography.labelLarge,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ Column(Modifier.alpha(if (staleSince != null) 0.5f else 1f), verticalArrangement = Arrangement.spacedBy(16.dp)) {
+ Meter("Memory", s.ramUsedMb / 1024.0, s.ramTotalMb / 1024.0)
+ s.storageUsedGb?.let { u -> s.storageTotalGb?.let { t -> Meter("Storage", u, t) } }
+ Row(Modifier.fillMaxWidth()) {
+ cells.forEach { (label, value) ->
+ Column(Modifier.weight(1f)) {
+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(value ?: "—", style = MaterialTheme.typography.titleLarge.copy(fontFeatureSettings = "tnum"), maxLines = 1)
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun Meter(label: String, usedGb: Double, totalGb: Double) {
+ val frac = if (totalGb > 0) (usedGb / totalGb).toFloat().coerceIn(0f, 1f) else 0f
+ Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
+ Row(verticalAlignment = Alignment.Bottom) {
+ Column(Modifier.weight(1f)) {
+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text("${(frac * 100).toInt()}% used", style = StatNumber)
+ }
+ Text(Copy.gbOf(usedGb, totalGb), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ LinearProgressIndicator(
+ progress = { frac },
+ Modifier.fillMaxWidth(),
+ color = if (frac >= Copy.FULL) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary,
+ )
+ }
+}
+
+/** Grey bars, no chart library: top 6 by value, the rest summed as "other". */
+@Composable
+private fun UsageCard(title: String, rows: List<Pair<String, Double>>, fmt: (Double) -> String) {
+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(title, style = MaterialTheme.typography.titleSmall)
+ Bars(rows, fmt)
+ }
+ }
+}
+
+@Composable
+private fun Bars(rows: List<Pair<String, Double>>, fmt: (Double) -> String, top: Int = 6) {
+ val sorted = rows.sortedByDescending { it.second }
+ val rest = sorted.drop(top).sumOf { it.second }
+ val shown = sorted.take(top) + if (rest > 0) listOf("Other" to rest) else emptyList()
+ val max = shown.maxOfOrNull { it.second }?.coerceAtLeast(1.0) ?: 1.0
+ shown.forEach { (name, v) ->
+ val frac by animateFloatAsState((v / max).toFloat(), MaterialTheme.motionScheme.defaultSpatialSpec(), label = "bar")
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ // Long app names wrap to two lines rather than cut off; the value column only needs "1.2 GB".
+ Text(name, Modifier.width(148.dp), style = MaterialTheme.typography.bodyMedium, maxLines = 2, overflow = TextOverflow.Ellipsis)
+ Spacer(Modifier.width(8.dp))
+ Box(Modifier.weight(1f).height(12.dp).clip(MaterialTheme.shapes.small).background(MaterialTheme.colorScheme.surfaceContainerHigh)) {
+ Box(Modifier.fillMaxHeight().fillMaxWidth(frac).clip(MaterialTheme.shapes.small).background(MaterialTheme.colorScheme.primary))
+ }
+ Text(fmt(v), Modifier.width(60.dp), style = SmallNumber, textAlign = TextAlign.End)
+ }
+ }
+}
+
+@Composable
+private fun ProcessTable(procs: List<Proc>, apps: List<AppInfo>) {
+ val labels = apps.associate { it.packageName to it.label }
+ val groups = procs
+ .groupBy { p -> p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEM }
+ .toList()
+ .sortedByDescending { (_, ps) -> ps.sumOf { it.cpuPercent } }
+ if (groups.isEmpty()) return EmptyLine("")
+ Row {
+ Text("App", Modifier.weight(1f), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text("CPU", Modifier.width(56.dp), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End)
+ Text("RAM", Modifier.width(72.dp), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End)
+ }
+ groups.forEach { (name, ps) ->
+ var open by rememberSaveable(name) { mutableStateOf(false) }
+ Column(Modifier.fillMaxWidth().clickable { open = !open }.padding(vertical = 6.dp)) {
+ Row {
+ Text(
+ if (ps.size > 1) "$name ×${ps.size}" else name,
+ Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis,
+ )
+ Text("%.0f%%".format(ps.sumOf { it.cpuPercent }), Modifier.width(56.dp), style = SmallNumber, textAlign = TextAlign.End)
+ Text(Copy.mb(ps.sumOf { it.ramMb }), Modifier.width(72.dp), style = SmallNumber, textAlign = TextAlign.End)
+ }
+ if (open) ps.forEach { p ->
+ Row(Modifier.padding(start = 12.dp, top = 2.dp)) {
+ Text("${p.pid} ${p.name}", Modifier.weight(1f), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ Text("%.1f%%".format(p.cpuPercent), Modifier.width(56.dp), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End)
+ Text(Copy.mb(p.ramMb), Modifier.width(72.dp), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.End)
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun NetworkBlock(n: NetworkInfo) {
+ // Already the technical screen: every fact shows, nothing behind a Details tap.
+ listOfNotNull(
+ "Connection" to listOfNotNull(if (n.iface == "wifi" || n.iface.startsWith("wlan")) "Wi-Fi" else "Ethernet", n.ssid).joinToString(" · "),
+ n.rssi?.let { "Signal" to "${signalWord(it).replaceFirstChar(Char::uppercase)} ($it dBm)" },
+ "IP address" to n.ip,
+ n.mac?.let { "MAC" to it },
+ n.linkMbps?.let { "Link speed" to "$it Mbps" },
+ ).forEach { (k, v) -> KeyValue(k, v) }
+ Spacer(Modifier.height(8.dp))
+ Text("Data used", style = MaterialTheme.typography.titleSmall)
+ Bars(n.traffic.map { it.app to (it.rxMb + it.txMb).toDouble() }, fmt = { Copy.mb(it.toInt()) })
+ Spacer(Modifier.height(8.dp))
+ Text("Open connections", style = MaterialTheme.typography.titleSmall)
+ if (n.sockets.isEmpty()) EmptyLine("")
+ n.sockets.forEach { s ->
+ Row(Modifier.padding(vertical = 2.dp)) {
+ Text(s.app, Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ Text(s.remote, style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ }
+}
+
+private fun signalWord(rssi: Int) = when {
+ rssi >= -55 -> "strong"
+ rssi >= -67 -> "good"
+ rssi >= -75 -> "weak"
+ else -> "very weak"
+}
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 3edde23..264ef33 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -98,6 +98,12 @@ object Copy {
fun gbOf(used: Double, total: Double) =
if (total < 10) "%.1f of %.1f GB".format(used, total) else "%.1f of %.0f GB".format(used, total)
+ /** Free storage in plain words, rounded down so it never promises room that isn't there; null if unknown. */
+ fun free(s: Snapshot): String? {
+ val gb = s.storageUsedGb?.let { u -> s.storageTotalGb?.let { t -> (t - u).coerceAtLeast(0.0) } } ?: return null
+ return if (gb < 10) "%.1f GB free".format(Math.floor(gb * 10) / 10) else "${gb.toInt()} GB free"
+ }
+
/** An offline TV that has never sent stats; a refusing TV is on, it just hasn't allowed us. */
fun noStats(s: DeviceState) =
if (s == DeviceState.NotAllowed) "Stats show up once the TV allows this phone."
diff --git a/app/src/main/java/app/tellyscope/ui/Details.kt b/app/src/main/java/app/tellyscope/ui/Details.kt
index 5bbb8d7..0da45ed 100644
--- a/app/src/main/java/app/tellyscope/ui/Details.kt
+++ b/app/src/main/java/app/tellyscope/ui/Details.kt
@@ -54,7 +54,7 @@ fun Details(rows: List<Pair<String, String>>, modifier: Modifier = Modifier) {
@Composable
fun KeyValue(k: String, v: String) {
Row(Modifier.padding(vertical = 2.dp)) {
- Text(k, Modifier.width(96.dp), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(k, Modifier.width(120.dp), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(v, style = SmallNumber)
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index dc6657c..7afca92 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -15,10 +15,8 @@ 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.fillMaxHeight
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
@@ -50,7 +48,6 @@ import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
-import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
@@ -86,13 +83,11 @@ import app.tellyscope.data.Device
import app.tellyscope.data.DeviceState
import app.tellyscope.data.HistoryBook
import app.tellyscope.data.HistoryEntry
-import app.tellyscope.data.NetworkInfo
import app.tellyscope.data.Proc
import app.tellyscope.data.Snapshot
import app.tellyscope.data.Suggestions
import app.tellyscope.data.deviceKind
import app.tellyscope.ui.theme.SmallNumber
-import app.tellyscope.ui.theme.StatNumber
data class DeviceActions(
val select: (String) -> Unit = {},
@@ -119,9 +114,11 @@ data class DeviceActions(
/** Asks where to save [TvFile] on the phone, then copies it. */
val saveFile: (TvFile) -> Unit = {},
val cancelTransfer: () -> Unit = {},
- val pickList: (String) -> Unit = {},
- val disableSuggested: (List<String>) -> Unit = {},
val remote: () -> Unit = {},
+ /** Opens the Debloat flow: pick the TV's list, then review the apps it turns off. */
+ val debloat: () -> Unit = {},
+ /** Opens the Advanced screen: every number, per-app CPU and RAM, processes and network. */
+ val advanced: () -> Unit = {},
)
/** Off while the remote is made faster: the device page hides its Remote button. */
@@ -149,7 +146,7 @@ fun DeviceScreen(
TextField(
value = state.query,
onValueChange = actions.query,
- placeholder = { Text("Search apps, processes, connections") },
+ placeholder = { Text("Search apps") },
singleLine = true,
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
@@ -169,6 +166,7 @@ fun DeviceScreen(
title = { DevicePicker(state, actions) },
actions = {
if (REMOTE_ENABLED) TextButton(onClick = actions.remote, enabled = !offline) { Text("Remote") }
+ TextButton(onClick = actions.advanced) { Text("Advanced") }
IconButton(onClick = { searching = true }, enabled = !offline) {
Icon(Icons.Default.Search, contentDescription = "Search")
}
@@ -183,19 +181,21 @@ fun DeviceScreen(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
item {
- Text(
- listOfNotNull(device.model, device.android?.let { "Android $it" }).joinToString(" · "),
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- Details(
- listOfNotNull(
- "IP address" to device.hit.ip,
- "Port" to device.hit.port.toString(),
- (device.manufacturer ?: device.hit.maker)?.let { "Maker" to it },
- device.hit.hostname?.let { "Network name" to it },
- ),
- )
+ // What the TV is on the left, where to find it on the right; the rest is on Advanced.
+ Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
+ Text(
+ listOfNotNull(device.model, device.android?.let { "Android $it" }).joinToString(" · "),
+ Modifier.weight(1f),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ Text(
+ listOfNotNull(device.hit.ip, device.manufacturer ?: device.hit.maker).joinToString(" · "),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ textAlign = androidx.compose.ui.text.style.TextAlign.End,
+ )
+ }
}
val restart = state.restarting[device.id]
if (restart != null) {
@@ -207,9 +207,12 @@ fun DeviceScreen(
}
val snap = ui.snapshot
if (snap != null) {
- if (!offline) item { HealthLine(Copy.health(snap, heaviest(snap, ui.apps))) }
- // Offline: the last stats this phone saw, greyed and dated, rather than a grid of blanks.
- item { Stats(snap, if (offline) state.now else null) }
+ // Plain words only: the health line already reads memory, CPU and heat; free space
+ // decides whether an install fits. Every number is on Advanced.
+ if (!offline) item {
+ HealthLine(Copy.health(snap, heaviest(snap, ui.apps)))
+ Copy.free(snap)?.let { FreeLine(it) }
+ }
} else if (offline) {
item {
Text(
@@ -220,14 +223,10 @@ fun DeviceScreen(
}
}
if (!offline && q.isEmpty()) item { SendRow(actions) }
- snap?.let {
- // The :adb source has no per-process list yet; no bars beats an empty card.
- if (q.isEmpty() && it.procs.isNotEmpty() && !offline) item { UsageCard(it, ui.apps) }
- }
if (!offline && q.isEmpty()) {
val count = (ui.lists as? Suggestions.Ready)?.groups?.sumOf { it.packages.size } ?: 0
- section("lists", "Suggested for this TV", count) {
- SuggestionsBlock(ui.lists, ui.busy == DISABLING, actions.pickList, actions.disableSuggested)
+ section("lists", "Suggested for this TV", count, expandedByDefault = true) {
+ SuggestionsSummary(ui.lists, ui.busy == DISABLING, actions.debloat)
}
}
// An offline TV can't list anything: sections with nothing in them stay out of the way.
@@ -246,12 +245,6 @@ fun DeviceScreen(
AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions)
}
}
- if (!offline || !snap?.procs.isNullOrEmpty()) section("procs", "Processes", snap?.procs?.size ?: 0, forceOpen = q.isNotEmpty()) {
- ProcessTable(snap?.procs.orEmpty(), ui.apps, q)
- }
- if (!offline || ui.network != null) section("net", "Network", ui.network?.sockets?.size ?: 0, forceOpen = q.isNotEmpty()) {
- ui.network?.let { NetworkBlock(it, q) }
- }
if (!offline && q.isEmpty()) section("files", "Files on the TV", ui.files.list?.size ?: 0) {
FilesBlock(ui.files, state.now, actions)
}
@@ -512,101 +505,9 @@ private fun HealthLine(h: Copy.Health) {
}
}
-/**
- * Memory and storage as "75% used" with a bar, then the small stats. Missing stats show "—",
- * never 0. [staleSince] set means the TV is offline: these are its last numbers, greyed and dated.
- */
-@Composable
-private fun Stats(s: Snapshot, staleSince: Long?) {
- val cells = listOf(
- "CPU" to "${s.cpuPercent}%",
- "Temperature" to s.tempC?.let { "$it°C" },
- "On for" to Copy.uptime(s.uptimeSeconds),
- "Screen" to s.screenOn?.let { if (it) "On" else "Off" },
- )
- Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
- if (staleSince != null) {
- Text(
- "As of ${Copy.ago(s.at, staleSince)}",
- style = MaterialTheme.typography.labelLarge,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- Column(Modifier.alpha(if (staleSince != null) 0.5f else 1f), verticalArrangement = Arrangement.spacedBy(16.dp)) {
- Meter("Memory", s.ramUsedMb / 1024.0, s.ramTotalMb / 1024.0)
- s.storageUsedGb?.let { u -> s.storageTotalGb?.let { t -> Meter("Storage", u, t) } }
- Row(Modifier.fillMaxWidth()) {
- cells.forEach { (label, value) ->
- Column(Modifier.weight(1f)) {
- Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text(value ?: "—", style = MaterialTheme.typography.titleLarge.copy(fontFeatureSettings = "tnum"), maxLines = 1)
- }
- }
- }
- }
- }
- }
-}
-
-@Composable
-private fun Meter(label: String, usedGb: Double, totalGb: Double) {
- val frac = if (totalGb > 0) (usedGb / totalGb).toFloat().coerceIn(0f, 1f) else 0f
- Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
- Row(verticalAlignment = Alignment.Bottom) {
- Column(Modifier.weight(1f)) {
- Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text("${(frac * 100).toInt()}% used", style = StatNumber)
- }
- Text(Copy.gbOf(usedGb, totalGb), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
- }
- LinearProgressIndicator(
- progress = { frac },
- Modifier.fillMaxWidth(),
- color = if (frac >= Copy.FULL) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary,
- )
- }
-}
-
-/** Grey bars, no chart library: top 6 by value, the rest summed as "other". */
@Composable
-private fun UsageCard(snap: Snapshot, apps: List<AppInfo>) {
- val labels = apps.associate { it.packageName to it.label }
- fun label(p: Proc) = p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEM
- val byApp = snap.procs.groupBy(::label)
- var cpu by rememberSaveable { mutableStateOf(false) }
- val rows = byApp.map { (name, ps) ->
- name to if (cpu) ps.sumOf { it.cpuPercent } else ps.sumOf { it.ramMb }.toDouble()
- }
- Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Text(if (cpu) "CPU by app" else "RAM by app", style = MaterialTheme.typography.titleSmall, modifier = Modifier.weight(1f))
- TextButton(onClick = { cpu = !cpu }) { Text(if (cpu) "Show RAM" else "Show CPU") }
- }
- Bars(rows, fmt = { if (cpu) "%.0f%%".format(it) else Copy.mb(it.toInt()) })
- }
- }
-}
-
-@Composable
-private fun Bars(rows: List<Pair<String, Double>>, fmt: (Double) -> String, top: Int = 6) {
- val sorted = rows.sortedByDescending { it.second }
- val rest = sorted.drop(top).sumOf { it.second }
- val shown = sorted.take(top) + if (rest > 0) listOf("Other" to rest) else emptyList()
- val max = shown.maxOfOrNull { it.second }?.coerceAtLeast(1.0) ?: 1.0
- shown.forEach { (name, v) ->
- val frac by animateFloatAsState((v / max).toFloat(), MaterialTheme.motionScheme.defaultSpatialSpec(), label = "bar")
- Row(verticalAlignment = Alignment.CenterVertically) {
- // Long app names wrap to two lines rather than cut off; the value column only needs "1.2 GB".
- Text(name, Modifier.width(148.dp), style = MaterialTheme.typography.bodyMedium, maxLines = 2, overflow = TextOverflow.Ellipsis)
- Spacer(Modifier.width(8.dp))
- Box(Modifier.weight(1f).height(12.dp).clip(MaterialTheme.shapes.small).background(MaterialTheme.colorScheme.surfaceContainerHigh)) {
- Box(Modifier.fillMaxHeight().fillMaxWidth(frac).clip(MaterialTheme.shapes.small).background(MaterialTheme.colorScheme.primary))
- }
- Text(fmt(v), Modifier.width(60.dp), style = SmallNumber, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- }
- }
+private fun FreeLine(text: String) {
+ Text(text, Modifier.padding(start = 32.dp), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
/** A collapsible card section. */
@@ -645,7 +546,7 @@ private fun LazyListScope.section(
}
@Composable
-private fun EmptyLine(q: String) {
+internal fun EmptyLine(q: String) {
Text(
if (q.isEmpty()) "Nothing here yet." else "Nothing matches \"$q\".",
style = MaterialTheme.typography.bodyMedium,
@@ -683,7 +584,7 @@ private fun AppRow(
val ram = procs.filter { it.packageName == app.packageName }.sumOf { it.ramMb }
val status = when {
!app.enabled -> "Disabled"
- ram > 0 -> "Running · ${Copy.mb(ram)}"
+ ram > 0 -> "Running"
else -> "Not running"
}
Column(Modifier.fillMaxWidth().clip(MaterialTheme.shapes.large).clickable(enabled = app.protectedReason == null) { open = !open }.padding(vertical = 8.dp)) {
@@ -726,78 +627,6 @@ private fun AppRow(
}
}
-@Composable
-private fun ProcessTable(procs: List<Proc>, apps: List<AppInfo>, q: String) {
- val labels = apps.associate { it.packageName to it.label }
- val groups = procs
- .groupBy { p -> p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEM }
- .filter { (name, ps) -> q.isEmpty() || name.lowercase().contains(q) || ps.any { it.name.lowercase().contains(q) } }
- .toList()
- .sortedByDescending { (_, ps) -> ps.sumOf { it.cpuPercent } }
- if (groups.isEmpty()) return EmptyLine(q)
- Row {
- Text("App", Modifier.weight(1f), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text("CPU", Modifier.width(56.dp), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- Text("RAM", Modifier.width(72.dp), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- }
- groups.forEach { (name, ps) ->
- var open by rememberSaveable(name) { mutableStateOf(false) }
- Column(Modifier.fillMaxWidth().clickable { open = !open }.padding(vertical = 6.dp)) {
- Row {
- Text(
- if (ps.size > 1) "$name ×${ps.size}" else name,
- Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis,
- )
- Text("%.0f%%".format(ps.sumOf { it.cpuPercent }), Modifier.width(56.dp), style = SmallNumber, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- Text(Copy.mb(ps.sumOf { it.ramMb }), Modifier.width(72.dp), style = SmallNumber, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- }
- if (open) ps.forEach { p ->
- Row(Modifier.padding(start = 12.dp, top = 2.dp)) {
- Text("${p.pid} ${p.name}", Modifier.weight(1f), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text("%.1f%%".format(p.cpuPercent), Modifier.width(56.dp), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- Text(Copy.mb(p.ramMb), Modifier.width(72.dp), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = androidx.compose.ui.text.style.TextAlign.End)
- }
- }
- }
- }
-}
-
-@Composable
-private fun NetworkBlock(n: NetworkInfo, q: String) {
- if (q.isEmpty()) {
- KeyValue("Connection", listOfNotNull(if (n.iface == "wifi" || n.iface.startsWith("wlan")) "Wi-Fi" else "Ethernet", n.ssid).joinToString(" · "))
- n.rssi?.let { r -> KeyValue("Signal", signalWord(r).replaceFirstChar(Char::uppercase)) }
- Details(
- listOfNotNull(
- "IP address" to n.ip,
- n.mac?.let { "MAC" to it },
- n.rssi?.let { "Signal" to "$it dBm" },
- n.linkMbps?.let { "Link speed" to "$it Mbps" },
- ),
- )
- Spacer(Modifier.height(8.dp))
- Text("Data used", style = MaterialTheme.typography.titleSmall)
- Bars(n.traffic.map { it.app to (it.rxMb + it.txMb).toDouble() }, fmt = { Copy.mb(it.toInt()) })
- Spacer(Modifier.height(8.dp))
- }
- Text("Open connections", style = MaterialTheme.typography.titleSmall)
- val socks = n.sockets.filter { q.isEmpty() || it.app.lowercase().contains(q) || it.remote.lowercase().contains(q) }
- if (socks.isEmpty()) EmptyLine(q)
- socks.forEach { s ->
- Row(Modifier.padding(vertical = 2.dp)) {
- Text(s.app, Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text(s.remote, style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
- }
- }
-}
-
-private fun signalWord(rssi: Int) = when {
- rssi >= -55 -> "strong"
- rssi >= -67 -> "good"
- rssi >= -75 -> "weak"
- else -> "very weak"
-}
-
@Composable
private fun HistoryList(
history: List<HistoryEntry>,
diff --git a/app/src/main/java/app/tellyscope/ui/ListsCard.kt b/app/src/main/java/app/tellyscope/ui/ListsCard.kt
index d6314f7..4f41549 100644
--- a/app/src/main/java/app/tellyscope/ui/ListsCard.kt
+++ b/app/src/main/java/app/tellyscope/ui/ListsCard.kt
@@ -2,64 +2,57 @@
package app.tellyscope.ui
+import androidx.activity.compose.BackHandler
import androidx.compose.foundation.clickable
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
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
-import androidx.compose.material3.FilledTonalButton
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.RadioButton
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
+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.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.draw.clip
import androidx.compose.ui.unit.dp
-import app.tellyscope.data.ListEntry
import app.tellyscope.data.Suggested
import app.tellyscope.data.Suggestions
-/** Body of the "Suggested for this TV" section: the TV's list, cut down to what it has. */
+/** Body of the "Suggested for this TV" section: one line on what the list offers, and the way in. */
@Composable
-fun SuggestionsBlock(
- lists: Suggestions?,
- disabling: Boolean,
- onPick: (String) -> Unit,
- onDisable: (List<String>) -> Unit,
-) {
- var picking by remember { mutableStateOf(false) }
- var confirming by remember { mutableStateOf(false) }
- // Ticks start from the list and reset whenever it reloads.
- var ticked by remember(lists) {
- mutableStateOf((lists as? Suggestions.Ready)?.groups.orEmpty().flatMap { it.packages }.filter { it.ticked }.map { it.pkg }.toSet())
- }
- val devices = when (lists) {
- is Suggestions.Pick -> lists.devices
- is Suggestions.Ready -> lists.devices
- else -> emptyList()
- }
- if (picking) PickDialog(devices, onPick = { picking = false; onPick(it) }, onDismiss = { picking = false })
- if (confirming) {
- // The dialog's list is exactly what gets disabled.
- val chosen = (lists as? Suggestions.Ready)?.groups.orEmpty().flatMap { it.packages }.filter { it.pkg in ticked }
- DisableDialog(chosen, onDisable = { confirming = false; onDisable(chosen.map { it.pkg }) }, onDismiss = { confirming = false })
- }
-
+fun SuggestionsSummary(lists: Suggestions?, disabling: Boolean, onDebloat: () -> Unit) {
when (lists) {
null -> Muted("Looking up this TV's list…")
Suggestions.Unavailable -> Muted(
@@ -67,79 +60,188 @@ fun SuggestionsBlock(
)
is Suggestions.Pick -> {
Text("Tellyscope doesn't know this model yet. Pick your TV to see what's usually safe to turn off.", style = MaterialTheme.typography.bodyMedium)
- FilledTonalButton(onClick = { picking = true }) { Text("Pick your TV") }
+ DebloatButton(disabling, onDebloat)
}
is Suggestions.Ready -> {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Text("From the list for ${lists.list.name}.", Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium)
- TextButton(onClick = { picking = true }) { Text("Not this TV?") }
- }
- if (!lists.sdkMatches) Muted(
- lists.list.testedOs?.let { "Tested on $it, not this TV's Android version, so nothing is ticked. Tick only what you know you don't use." }
- ?: "This list doesn't say which Android it was tested on, so nothing is ticked. Tick only what you know you don't use.",
- )
- if (lists.groups.isEmpty()) Muted("Nothing on the list is still on here.")
- lists.groups.forEach { g ->
- Text(g.title, style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(top = 8.dp))
- g.packages.forEach { p ->
- Row(
- Modifier.fillMaxWidth().clickable(enabled = !disabling) { ticked = if (p.pkg in ticked) ticked - p.pkg else ticked + p.pkg },
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Checkbox(p.pkg in ticked, onCheckedChange = null, enabled = !disabling)
- Spacer(Modifier.width(8.dp))
- Column(Modifier.weight(1f)) {
- Text(p.label, style = MaterialTheme.typography.bodyLarge)
- Text(
- listOfNotNull(p.pkg, p.note, "optional".takeIf { p.optional }).joinToString(" · "),
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- }
- }
- }
- if (lists.groups.isNotEmpty()) {
- Button(onClick = { confirming = true }, enabled = ticked.isNotEmpty() && !disabling, modifier = Modifier.padding(top = 8.dp)) {
- Text(if (disabling) "Disabling…" else "Disable ${ticked.size} selected")
- }
+ val n = lists.groups.sumOf { it.packages.size }
+ if (n == 0) {
+ Muted("Nothing on the list for ${lists.list.name} is still on here.")
+ } else {
+ Text("$n ${if (n == 1) "app" else "apps"} usually safe to turn off on this TV.", style = MaterialTheme.typography.bodyMedium)
}
+ DebloatButton(disabling, onDebloat)
}
}
if (lists is Suggestions.Pick || lists is Suggestions.Ready) Muted("Lists adapted from cleanyourtv (MIT).")
}
+@Composable
+private fun DebloatButton(disabling: Boolean, onDebloat: () -> Unit) {
+ Button(onClick = onDebloat, enabled = !disabling, modifier = Modifier.padding(vertical = 4.dp)) {
+ Text(if (disabling) "Disabling…" else "Debloat")
+ }
+}
+
@Composable
private fun Muted(text: String) {
Text(text, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
-/** Searchable "Pick your TV". The choice is remembered for this TV. */
+/**
+ * Debloat in two steps. First the TV's model: the matched list is chosen, any other can be, and
+ * an unknown model starts with nothing chosen. Then every app that list would turn off, ticked as
+ * the list says, with a final confirm that names each one.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
@Composable
-fun PickDialog(devices: List<ListEntry>, onPick: (String) -> Unit, onDismiss: () -> Unit) {
+fun DebloatScreen(
+ lists: Suggestions?,
+ onPick: (String) -> Unit,
+ onDisable: (List<String>) -> Unit,
+ back: () -> Unit,
+ snackbar: SnackbarHostState = remember { SnackbarHostState() },
+) {
+ val ready = lists as? Suggestions.Ready
+ val devices = when (lists) {
+ is Suggestions.Pick -> lists.devices
+ is Suggestions.Ready -> lists.devices
+ else -> emptyList()
+ }
+ var step by rememberSaveable { mutableIntStateOf(1) }
+ var chosen by rememberSaveable { mutableStateOf(ready?.list?.id) }
var q by rememberSaveable { mutableStateOf("") }
- val shown = devices.filter { q.isBlank() || it.name.contains(q.trim(), ignoreCase = true) }.sortedBy { it.name.lowercase() }
- AlertDialog(
- onDismissRequest = onDismiss,
- title = { Text("Pick your TV") },
- text = {
- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- OutlinedTextField(q, { q = it }, placeholder = { Text("Brand or model") }, singleLine = true, modifier = Modifier.fillMaxWidth())
- if (shown.isEmpty()) Muted("No list matches \"${q.trim()}\".")
- LazyColumn(Modifier.heightIn(max = 360.dp)) {
- items(shown, key = { it.id }) { d ->
- Text(
- d.name,
- Modifier.fillMaxWidth().clickable { onPick(d.id) }.padding(vertical = 12.dp),
- style = MaterialTheme.typography.bodyLarge,
- )
+ // Ticks start from the list and reset whenever it reloads.
+ var ticked by remember(lists) {
+ mutableStateOf(ready?.groups.orEmpty().flatMap { it.packages }.filter { it.ticked }.map { it.pkg }.toSet())
+ }
+ var confirming by remember { mutableStateOf(false) }
+ val showing = ready?.takeIf { it.list.id == chosen }
+ if (confirming && showing != null) {
+ // The dialog's list is exactly what gets disabled.
+ val apps = showing.groups.flatMap { it.packages }.filter { it.pkg in ticked }
+ DisableDialog(apps, onDisable = { confirming = false; onDisable(apps.map { it.pkg }); back() }, onDismiss = { confirming = false })
+ }
+ val goBack = { if (step == 2) step = 1 else back() }
+ BackHandler(onBack = goBack)
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(snackbar) },
+ topBar = {
+ TopAppBar(
+ title = {
+ Column {
+ Text(if (step == 1) "Which TV is this?" else "Review the apps")
+ Text("Debloat · step $step of 2", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ },
+ navigationIcon = {
+ IconButton(onClick = goBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") }
+ },
+ )
+ },
+ bottomBar = {
+ Surface(tonalElevation = 3.dp) {
+ Box(Modifier.fillMaxWidth().navigationBarsPadding().padding(16.dp)) {
+ if (step == 1) {
+ Button(
+ onClick = { chosen?.let { if (it != ready?.list?.id) onPick(it) }; step = 2 },
+ enabled = chosen != null,
+ modifier = Modifier.fillMaxWidth(),
+ ) { Text("Next") }
+ } else {
+ Button(
+ onClick = { confirming = true },
+ enabled = showing != null && ticked.isNotEmpty(),
+ modifier = Modifier.fillMaxWidth(),
+ ) { Text("Disable ${ticked.size} ${if (ticked.size == 1) "app" else "apps"}") }
}
}
}
},
- confirmButton = {},
- dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
- )
+ ) { pad ->
+ if (step == 1) {
+ // The matched list first, then the rest by name.
+ val shown = devices
+ .filter { q.isBlank() || it.name.contains(q.trim(), ignoreCase = true) }
+ .sortedWith(compareBy({ it.id != ready?.list?.id }, { it.name.lowercase() }))
+ LazyColumn(Modifier.fillMaxSize().padding(pad), contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp)) {
+ item {
+ Text(
+ if (ready != null) "Tellyscope matched this TV to the ${ready.list.name} list. Pick another model if that's wrong."
+ else "Tellyscope doesn't know this model yet. Pick the closest match.",
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ OutlinedTextField(
+ q, { q = it },
+ placeholder = { Text("Brand or model") },
+ singleLine = true,
+ modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
+ )
+ // Empty while a picked list reloads, if they came back to change it.
+ if (devices.isEmpty()) Muted("Loading the lists…")
+ else if (shown.isEmpty()) Muted("No list matches \"${q.trim()}\".")
+ }
+ items(shown, key = { it.id }) { d ->
+ Row(
+ Modifier.fillMaxWidth().clip(MaterialTheme.shapes.medium).clickable { chosen = d.id }.padding(vertical = 4.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ RadioButton(d.id == chosen, onClick = null)
+ Spacer(Modifier.width(12.dp))
+ Text(d.name, style = MaterialTheme.typography.bodyLarge)
+ }
+ }
+ }
+ } else {
+ LazyColumn(
+ Modifier.fillMaxSize().padding(pad),
+ contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
+ verticalArrangement = Arrangement.spacedBy(4.dp),
+ ) {
+ if (showing == null) {
+ item {
+ Muted(
+ if (lists == Suggestions.Unavailable) "Couldn't load that list. Check the phone's internet and try again."
+ else "Loading the list…",
+ )
+ }
+ return@LazyColumn
+ }
+ item {
+ Text(
+ "From the list for ${showing.list.name}. Untick anything you use. Nothing is deleted: each app is hidden, and History can turn it back on.",
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ if (!showing.sdkMatches) Muted(
+ showing.list.testedOs?.let { "Tested on $it, not this TV's Android version, so nothing is ticked. Tick only what you know you don't use." }
+ ?: "This list doesn't say which Android it was tested on, so nothing is ticked. Tick only what you know you don't use.",
+ )
+ if (showing.groups.isEmpty()) Muted("Nothing on the list is still on here.")
+ }
+ showing.groups.forEach { g ->
+ item(key = "g:" + g.title) { Text(g.title, style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(top = 8.dp)) }
+ items(g.packages, key = { it.pkg }) { p ->
+ Row(
+ Modifier.fillMaxWidth().clip(MaterialTheme.shapes.medium)
+ .clickable { ticked = if (p.pkg in ticked) ticked - p.pkg else ticked + p.pkg },
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Checkbox(p.pkg in ticked, onCheckedChange = null)
+ Spacer(Modifier.width(8.dp))
+ Column(Modifier.weight(1f)) {
+ Text(p.label, style = MaterialTheme.typography.bodyLarge)
+ Text(
+ listOfNotNull(p.pkg, p.note, "optional".takeIf { p.optional }).joinToString(" · "),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
@Composable
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index b9ae44d..035d216 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -12,6 +12,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.test.junit4.v2.createComposeRule
+import androidx.compose.ui.test.assertIsEnabled
+import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
@@ -28,11 +30,15 @@ import app.tellyscope.data.Device
import app.tellyscope.data.DeviceState
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.HistoryEntry
+import app.tellyscope.data.ListEntry
import app.tellyscope.data.PickedApp
import app.tellyscope.data.ScanHit
import app.tellyscope.data.ScanKind
import app.tellyscope.data.ScanProgress
import app.tellyscope.data.Suggested
+import app.tellyscope.data.Suggestions
+import app.tellyscope.ui.AdvancedScreen
+import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceScreen
import app.tellyscope.ui.Copy
@@ -151,12 +157,30 @@ class ScreenshotTest {
snapshot = fake.snapshot(d.id),
apps = fake.apps(d.id),
network = fake.network(d.id),
+ lists = lists(d.id),
).device(),
now = now,
)
}
- @Test fun device_overview() = shot("04_device") { DeviceScreen(deviceState(), DeviceActions()) }
+ /** The fake's list, among a few other models so "Which TV is this?" has a choice. */
+ private suspend fun lists(id: String): Suggestions.Ready {
+ val ready = fake.suggestions(id) as Suggestions.Ready
+ val others = listOf("Sony Bravia (Google TV)", "TCL C-series", "Xiaomi Mi Box S").map {
+ val slug = it.lowercase().replace(Regex("[^a-z]+"), "-").trim('-')
+ ListEntry(slug, it, null, 30, "devices/$slug.json", "0".repeat(64))
+ }
+ return ready.copy(devices = ready.devices + others)
+ }
+
+ @Test fun device_overview() {
+ shot("04_device") { DeviceScreen(deviceState(), DeviceActions()) }
+ // Plain words on the main page: no Details expander, no MB per app; numbers live on Advanced.
+ compose.onNodeWithText("Details").assertDoesNotExist()
+ compose.onNodeWithText("Advanced").assertExists()
+ compose.onNodeWithText("Running · ", substring = true).assertDoesNotExist()
+ compose.onNodeWithText("Debloat").assertExists()
+ }
@Test fun device_overview_dark() = shot("04_device", dark = true) { DeviceScreen(deviceState(), DeviceActions()) }
@@ -326,6 +350,42 @@ class ScreenshotTest {
@Test fun reboot() = shot("15_reboot", screen = true) { RebootDialog({}, {}) }
+ @Config(qualifiers = "w411dp-h2400dp-xxhdpi")
+ @Test fun advanced() = shot("17_advanced") { AdvancedScreen(deviceState(), back = {}) }
+
+ @Test fun debloat_pick() {
+ val lists = deviceState().device.lists
+ shot("18_debloat_pick") { DebloatScreen(lists, {}, {}, {}) }
+ compose.onNodeWithText("Next").assertIsEnabled() // the matched list is already chosen
+ }
+
+ @Test fun debloat_unknownModel() {
+ val ready = deviceState().device.lists as Suggestions.Ready
+ shot("18_debloat_pick_unknown") { DebloatScreen(Suggestions.Pick(null, ready.devices), {}, {}, {}) }
+ compose.onNodeWithText("Next").assertIsNotEnabled() // nothing guessed for a model it doesn't know
+ }
+
+ @Test fun debloat_review() {
+ val lists = deviceState().device.lists as Suggestions.Ready
+ val next = { compose.onNodeWithText("Next").performClick(); Unit }
+ shot("19_debloat_review", before = next) { DebloatScreen(lists, {}, {}, {}) }
+ val apps = lists.groups.flatMap { it.packages }
+ for (a in apps) compose.onNodeWithText(a.label).assertExists()
+ val ticked = apps.count { it.ticked }
+ compose.onNodeWithText("Disable $ticked ${if (ticked == 1) "app" else "apps"}").assertIsEnabled()
+ }
+
+ @Test fun debloat_review_otherAndroid() {
+ // A list tested on another Android version ticks nothing, the way the list builder hands it over.
+ val lists = (deviceState().device.lists as Suggestions.Ready).let { r ->
+ r.copy(sdk = 28, groups = r.groups.map { g -> g.copy(packages = g.packages.map { it.copy(ticked = false) }) })
+ }
+ val next = { compose.onNodeWithText("Next").performClick(); Unit }
+ shot("19_debloat_review_other_android", before = next) { DebloatScreen(lists, {}, {}, {}) }
+ compose.onNodeWithText("so nothing is ticked", substring = true).assertExists()
+ compose.onNodeWithText("Disable 0 apps").assertIsNotEnabled()
+ }
+
@Test fun disableSuggested() {
val apps = listOf(
Suggested("com.xgimi.assistant", "XGIMI Assistant", null, optional = false, ticked = true),
diff --git a/docs/screenshots/debloat.png b/docs/screenshots/debloat.png
new file mode 100644
index 0000000..59617a6
Binary files /dev/null and b/docs/screenshots/debloat.png differ
diff --git a/docs/screenshots/tv-page.png b/docs/screenshots/tv-page.png
index 42c4bf0..757a283 100644
Binary files a/docs/screenshots/tv-page.png and b/docs/screenshots/tv-page.png differ