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.

Overview: offline, show the saved storage as of last seen

jesse-agent-362bdcd0378680b
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 107d7d3..0a27ef7 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -167,8 +167,11 @@ object Copy {
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
+ fun free(s: Snapshot): String? = free(s.storageUsedGb, s.storageTotalGb)
+
+ /** [free] from the two numbers, for a TV's saved facts as well as a live reading. */
+ fun free(used: Double?, total: Double?): String? {
+ val gb = used?.let { u -> total?.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"
}
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index 50d406d..00e763e 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -118,21 +118,31 @@ internal const val REMOTE_ENABLED = false
* install fits, then CPU, RAM, temperature and network speed as plain numbers.
*/
@Composable
-internal fun SystemWidget(s: Snapshot) {
+internal fun SystemWidget(s: Snapshot) = SystemWidget(s.storageUsedGb, s.storageTotalGb, s)
+
+/**
+ * The same card for a TV that's away: storage as it was [asOf] the last visit, and the live
+ * numbers as dashes, since old ones don't speak for a TV that isn't there.
+ */
+@Composable
+internal fun SystemWidget(usedGb: Double?, totalGb: Double?, live: Snapshot?, asOf: String? = null) {
val dash = "\u2014"
Card(
Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
) {
Column(Modifier.padding(16.dp)) {
- val used = s.storageUsedGb
- val total = s.storageTotalGb?.takeIf { it > 0 }
+ if (asOf != null) {
+ Text("As of $asOf", Modifier.padding(bottom = 8.dp), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ val used = usedGb
+ val total = totalGb?.takeIf { it > 0 }
if (used != null && total != null) {
Row {
Text("Internal storage", Modifier.weight(1f), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
Text("${Copy.gbOf(used, total)} used", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
- Copy.free(s)?.let { Text(it, style = MaterialTheme.typography.titleLarge) }
+ Copy.free(used, total)?.let { Text(it, style = MaterialTheme.typography.titleLarge) }
val full = used / total
LinearProgressIndicator(
progress = { full.toFloat().coerceIn(0f, 1f) },
@@ -141,10 +151,10 @@ internal fun SystemWidget(s: Snapshot) {
)
}
Row {
- Vital("CPU", "${s.cpuPercent}%", Modifier.weight(1f))
- Vital("RAM", if (s.ramTotalMb > 0) "${s.ramUsedMb * 100 / s.ramTotalMb}%" else dash, Modifier.weight(1f))
- Vital("Temp", s.tempC?.let { "$it\u00b0C" } ?: dash, Modifier.weight(1f))
- Vital("Network", s.netBytesPerSec?.let(Copy::speed) ?: dash, Modifier.weight(1.3f))
+ Vital("CPU", live?.let { "${it.cpuPercent}%" } ?: dash, Modifier.weight(1f))
+ Vital("RAM", live?.takeIf { it.ramTotalMb > 0 }?.let { "${it.ramUsedMb * 100 / it.ramTotalMb}%" } ?: dash, Modifier.weight(1f))
+ Vital("Temp", live?.tempC?.let { "$it\u00b0C" } ?: dash, Modifier.weight(1f))
+ Vital("Network", live?.netBytesPerSec?.let(Copy::speed) ?: dash, Modifier.weight(1.3f))
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
index bcb4de0..4fbc091 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
@@ -248,9 +248,14 @@ fun DeviceTabsScreen(
} else if (offline) {
item { OfflineCard(device, state.now, actions.reconnect) }
}
+ // Away, storage is the last one seen, this session's or the saved one after a restart.
+ val used = snap?.storageUsedGb ?: device.lastKnown?.storageUsedGb
+ val total = snap?.storageTotalGb ?: device.lastKnown?.storageTotalGb
if (live != null) {
item { SystemWidget(live) }
- } else if (offline && snap == null) {
+ } else if (offline && used != null && total != null) {
+ item { SystemWidget(used, total, null, asOf = device.lastSeen?.let { Copy.ago(it, state.now) } ?: "the last visit") }
+ } else if (offline) {
item { Muted(Copy.noStats(device.state)) }
}
val debloat = debloatState(ui)
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index c44e310..b354e72 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -244,6 +244,13 @@ class ScreenshotTest {
compose.onNodeWithText("Kitchen").performClick()
assertEquals(state.devices[2].id, picked)
}
+ // After a restart there's no snapshot: the saved storage still shows, as of the last visit.
+ @Test fun offlineAfterRestartShowsSavedStorage() {
+ val state = md3State().let { it.copy(selectedId = it.devices[2].id, device = DeviceUi()) }
+ compose.setContent { TellyscopeTheme(dynamic = false) { DeviceTabsScreen(state, DeviceActions()) } }
+ compose.onNodeWithText("As of 2 h ago").assertExists()
+ compose.onNodeWithText("4.9 GB free").assertExists()
+ }
@Test fun md3_oneTv() = md3("63_md3_one_tv", false) { md3State().let { it.copy(devices = it.devices.take(1)) } }
@Test fun md3_oneTv_dark() = md3("63_md3_one_tv", true) { md3State().let { it.copy(devices = it.devices.take(1)) } }
@@ -322,9 +329,10 @@ class ScreenshotTest {
shot("06_device_offline") {
DeviceTabsScreen(base.copy(selectedId = off.id, device = DeviceUi(snapshot = last), showOffline = true), DeviceActions())
}
- // Old numbers don't speak for a TV that's away; what it is still does.
- compose.onNodeWithText("Up for").assertDoesNotExist()
- compose.onNodeWithText("Internal storage").assertDoesNotExist()
+ // Away, storage shows as it was last seen; the live numbers are dashes.
+ compose.onNodeWithText("As of ", substring = true).assertExists()
+ compose.onNodeWithText("Internal storage").assertExists()
+ compose.onAllNodesWithText("\u2014").assertCountEquals(4)
compose.onNodeWithText("Updated ", substring = true).assertExists()
}