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.

TV menu as a bottom sheet, History on its own screen, a dot for new changes

jesse-agent-2324152fd8fdf43
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf9e7d2..674e5f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ until this file has a section for its version.
## Unreleased
+- **Improved:** ⋮ opens a sheet, with History on its own screen instead of in Tweaks. A dot on ⋮ marks a change you haven't looked at, and Advanced is now Advanced monitor.
- **New:** A Home screen card in Tweaks switches launchers; only the TV's own turns off. [#186](../../pull/186)
- **Fixed:** Undo in History turns off a new home screen's accessibility service, as promised. [#185](../../pull/185)
- **Fixed:** Restore everything always ends on your TV's own home screen. [#184](../../pull/184)
diff --git a/README.md b/README.md
index c0ab25d..b6c8d1b 100644
--- a/README.md
+++ b/README.md
@@ -33,24 +33,24 @@ Debloat your Android TV, install apps, and browse and transfer files on it, all
<td><img src="docs/screenshots/send.png" alt="Sending a video from the phone to the TV's Movies folder"></td>
<td><img src="docs/screenshots/tweaks.png" alt="Tweaks: the Home screen card with Google TV Home as Current and Get another launcher, then ad-blocking Private DNS on, faster animations and clear caches"></td>
<td><img src="docs/screenshots/home.png" alt="Make Projectivy Launcher the home screen: the confirm says Google TV Home, the TV's built-in launcher, is the only one ever turned off"></td>
- <td><img src="docs/screenshots/advanced.png" alt="Advanced: CPU and RAM by app, the TV's network connection, and the apps' open connections"></td>
+ <td><img src="docs/screenshots/advanced.png" alt="Advanced monitor: CPU and RAM by app, the TV's network connection, and the apps' open connections"></td>
</tr>
<tr>
<td align="center"><sub>Send files to the TV</sub></td>
<td align="center"><sub>Block ads, tweak the TV, add a launcher</sub></td>
<td align="center"><sub>Make a launcher Home</sub></td>
- <td align="center"><sub>Advanced: what is using the CPU, RAM and network</sub></td>
+ <td align="center"><sub>Advanced monitor: what is using the CPU, RAM and network</sub></td>
</tr>
</table>
-<sub>Rendered from the app's screenshot tests with sample data. The Install dialog is drawn to match the app, and Advanced joins parts of its longer page.</sub>
+<sub>Rendered from the app's screenshot tests with sample data. The Install dialog is drawn to match the app, and Advanced monitor joins parts of its longer page.</sub>
## What it does
Tellyscope talks to your Android TV, Google TV, NVIDIA Shield or Fire TV over Wi-Fi using ADB, the debugging protocol developers use. Shield and Fire TV haven't been tested on real hardware yet.
- **Connect.** Finds TVs on your Wi-Fi, or add one by IP. Works with network debugging and with Android 11+ wireless debugging and its pairing code. TVs reconnect by themselves.
-- **See how it's doing.** Free space, CPU, RAM, temperature and network speed, plus what's paired or plugged in. **Advanced** has CPU and RAM by app, processes, network and data used.
+- **See how it's doing.** Free space, CPU, RAM, temperature and network speed, plus what's paired or plugged in. **Advanced monitor** has CPU and RAM by app, processes, network and data used.
- **Debloat.** Matches your TV to one of 330+ tested lists (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and shows every app it will turn off before it does. Untick anything you use. No list for your model? Pick from the maker's lists, or by hand.
- **Apps.** See what's running and what's on the TV. Turn off apps you don't want, turn them back on any time, and uninstall the ones you added yourself.
- **Install apps.** From an APK, split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. It says first whether it's new, an update or an older version.
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 8b90c8c..8a55c87 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -47,6 +47,7 @@ import app.tellyscope.data.Device
import app.tellyscope.data.DeviceState
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.FoldBook
+import app.tellyscope.data.SeenBook
import app.tellyscope.data.KeyHaptics
import app.tellyscope.data.UpdateCheck
import app.tellyscope.ui.AccessActions
@@ -58,6 +59,7 @@ import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceTabsScreen
import app.tellyscope.ui.Done
+import app.tellyscope.ui.HistoryScreen
import app.tellyscope.ui.LauncherActions
import app.tellyscope.ui.LauncherScreen
import app.tellyscope.ui.LocalNow
@@ -71,6 +73,7 @@ import app.tellyscope.ui.RowState
import app.tellyscope.ui.ScanScreen
import app.tellyscope.ui.SettingsScreen
import app.tellyscope.ui.TellyscopeViewModel
+import app.tellyscope.ui.TvTab
import app.tellyscope.ui.UpdateDialog
import app.tellyscope.ui.WelcomeScreen
import app.tellyscope.ui.brands
@@ -118,6 +121,7 @@ class MainActivity : ComponentActivity() {
folds = FoldBook(File(filesDir, "folds.properties")),
keyHaptics = KeyHaptics(File(filesDir, "remote.properties")),
gates = FoldBook(File(filesDir, "gates.properties")),
+ historySeen = SeenBook(File(filesDir, "history-seen.properties")),
appFacts = AppFacts(installedVersion(), "${Build.MANUFACTURER} ${Build.MODEL}, Android ${Build.VERSION.RELEASE}"),
)
}
@@ -189,6 +193,9 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
var adding by rememberSaveable { mutableStateOf(false) }
var remote by rememberSaveable { mutableStateOf(false) }
var advanced by rememberSaveable { mutableStateOf(false) }
+ var history by rememberSaveable { mutableStateOf(false) }
+ // The TV's page comes back on the tab it was left on, from History or any screen its menu opens.
+ var tvTab by rememberSaveable { mutableStateOf(TvTab.Overview) }
var debloat by rememberSaveable { mutableStateOf(false) }
var settings by rememberSaveable { mutableStateOf(false) }
var access by rememberSaveable { mutableStateOf(false) }
@@ -216,10 +223,10 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
LoggedOutSnackbars(snackbar, { state.devices }, { state.selectedId }, onView = vm::select)
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
- LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; debloat = false; settings = false; access = false; rejoinId = null }
+ LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; history = false; debloat = false; settings = false; access = false; rejoinId = null }
// Logged out mid-screen: the page takes over, and the TV comes back on Overview once allowed again.
val loggedOutAt = state.selected?.loggedOutAt
- LaunchedEffect(loggedOutAt) { if (loggedOutAt != null) { remote = false; advanced = false; debloat = false; settings = false; access = false } }
+ LaunchedEffect(loggedOutAt) { if (loggedOutAt != null) { remote = false; advanced = false; history = false; debloat = false; settings = false; access = false } }
// The Allow screen while the TV is asked; allowed lands on Overview, a Deny there is a plain refusal (its card).
val rejoining = state.selected?.takeIf { it.id == rejoinId && it.state == DeviceState.Waiting }
LaunchedEffect(state.selected?.state, loggedOutAt) {
@@ -301,6 +308,14 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
onDispose { vm.showStats(StatsProfile.OTHER) }
}
AdvancedScreen(state, back = { advanced = false }, snackbar = snackbar)
+ } else if (history) {
+ BackHandler { history = false }
+ // Seen on the way in, and again on the way out for changes made here, so ⋮ has no dot for them.
+ DisposableEffect(Unit) {
+ vm.historyOpened()
+ onDispose { vm.historyOpened() }
+ }
+ HistoryScreen(state, onUndo = vm::undo, onRestoreAll = vm::restoreAll, back = { history = false }, snackbar = snackbar)
} else if (access || state.device.removal != null) {
// A removal started from the warning opens this screen too, and back steps out of it first.
BackHandler { if (state.device.removal != null) vm.closeRemoval() else access = false }
@@ -350,6 +365,8 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
DeviceTabsScreen(
state = state,
snackbar = snackbar,
+ startTab = tvTab,
+ onTab = { tvTab = it },
actions = DeviceActions(
select = vm::select,
addDevice = { adding = true; vm.rescan() },
@@ -385,6 +402,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
remote = { remote = true },
debloat = { debloat = true },
advanced = { advanced = true },
+ history = { history = true },
checkUpdates = vm::checkUpdates,
setDns = vm::setDns,
setFastAnimations = vm::setFastAnimations,
diff --git a/app/src/main/java/app/tellyscope/data/SeenBook.kt b/app/src/main/java/app/tellyscope/data/SeenBook.kt
new file mode 100644
index 0000000..0cea4b9
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/data/SeenBook.kt
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.data
+
+import java.io.File
+import java.util.Properties
+
+/**
+ * When each TV's History was last opened, kept in [file]: ⋮ shows a dot for a change newer than
+ * that. Never opened reads as 0, so a TV with History shows the dot once.
+ */
+class SeenBook(private val file: File) {
+ @Synchronized
+ fun seen(): Map<String, Long> = props().let { p -> p.stringPropertyNames().associateWith { p.getProperty(it).toLongOrNull() ?: 0L } }
+
+ @Synchronized
+ fun set(deviceId: String, at: Long) {
+ val p = props().apply { setProperty(deviceId, at.toString()) }
+ runCatching {
+ file.parentFile?.mkdirs()
+ file.outputStream().use { p.store(it, null) }
+ }
+ }
+
+ private fun props() = Properties().apply {
+ runCatching { file.takeIf { it.exists() }?.inputStream()?.use(::load) }
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
index 616804f..5933d8a 100644
--- a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
@@ -79,7 +79,7 @@ fun AdvancedScreen(
snackbarHost = { SnackbarHost(snackbar) },
topBar = {
TopAppBar(
- title = { Text("Advanced") },
+ title = { Text(Copy.ADVANCED_MONITOR) },
navigationIcon = {
IconButton(onClick = back) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back to the TV's page") }
},
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 81da6b1..0b1fb3e 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -70,7 +70,7 @@ object Copy {
// A setting's label is the whole sentence: "Private DNS set to …".
Action.Change -> app
Action.ClearCaches -> "Cleared $app"
- Action.Home -> "Set $app as the default launcher"
+ Action.Home -> "Made $app Home"
Action.HomeBack -> "Switched home back to $app"
}
@@ -580,6 +580,15 @@ object Copy {
const val REMOVE_ACCESS = "Remove all other access…"
const val CONNECTED_NOW = "Connected now"
const val WHO_HAS_ACCESS = "Who has access"
+
+ /** The TV menu's rows for the screens it opens. */
+ const val HISTORY = "History"
+ const val ADVANCED_MONITOR = "Advanced monitor"
+
+ /** Under History in the menu, and on top of the History screen: apps Restore everything turns back on. */
+ fun stillOff(n: Int) = if (n == 1) "1 app still off" else "$n apps still off"
+ fun stillOffTitle(n: Int) = if (n == 1) "1 app Tellyscope turned off is still off" else "$n apps Tellyscope turned off are still off"
+ const val STILL_OFF_TEXT = "Restore everything turns them back on. Apps that were off before Tellyscope's first change stay off."
fun othersConnected(n: Int) = if (n == 1) "1 other connected now" else "$n others connected now"
fun connections(n: Int) = if (n == 1) "1 connection" else "$n connections"
fun connectedFrom(address: String, n: Int) = "From $address · ${connections(n)}"
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index 32d8b10..108df55 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -20,7 +20,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
-import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Info
@@ -61,7 +60,6 @@ import app.tellyscope.data.AppInfo
import app.tellyscope.data.AppNames
import app.tellyscope.data.Device
import app.tellyscope.data.DeviceState
-import app.tellyscope.data.HistoryBook
import app.tellyscope.data.HistoryEntry
import app.tellyscope.data.Proc
import app.tellyscope.data.Snapshot
@@ -109,8 +107,10 @@ data class DeviceActions(
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. */
+ /** Opens the Advanced monitor: every number, per-app CPU and RAM, processes and network. */
val advanced: () -> Unit = {},
+ /** Opens History: every change on this TV with its Undo, and Restore everything. */
+ val history: () -> Unit = {},
/** Opens the TV's own system update screen. */
val checkUpdates: () -> Unit = {},
/** Ad-blocking Private DNS through the given hostname; null goes back to Automatic. */
@@ -471,55 +471,3 @@ internal fun AppRow(
}
}
-@Composable
-internal fun HistoryList(
- history: List<HistoryEntry>,
- now: Long,
- onUndo: (HistoryEntry) -> Unit,
- restoring: Boolean = false,
- onRestoreAll: () -> Unit = {},
- /** Something is running on this TV, a restore included: Undo and Restore wait for it. */
- busy: Boolean = restoring,
-) {
- var confirming by rememberSaveable { mutableStateOf(false) }
- val off = HistoryBook.leftDisabled(history).size
- if (confirming) RestoreDialog(off, onRestore = { confirming = false; onRestoreAll() }, onDismiss = { confirming = false })
- var disabling by remember { mutableStateOf<HistoryEntry?>(null) }
- disabling?.let { h ->
- UndoDisableDialog(h, onDisable = { disabling = null; onUndo(h) }, onDismiss = { disabling = null })
- }
- if (off > 0) {
- OutlinedButton(onClick = { confirming = true }, enabled = !busy) {
- Text(if (restoring) "Turning apps back on…" else "Restore everything ($off)")
- }
- }
- if (history.isEmpty()) {
- Text(
- "Nothing changed yet. Anything you stop, disable or turn on shows up here, with a way to undo it.",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- return
- }
- history.forEach { h ->
- Row(Modifier.padding(vertical = 2.dp), verticalAlignment = Alignment.CenterVertically) {
- Column(Modifier.weight(1f)) {
- Text(Copy.done(h.action, h.label), style = MaterialTheme.typography.bodyMedium)
- Text(Copy.ago(h.at, now), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
- }
- when {
- // Same button as Undo, switched off: the row keeps its shape and reads as done.
- h.undoneAt != null -> TextButton(
- onClick = {},
- enabled = false,
- colors = ButtonDefaults.textButtonColors(disabledContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
- ) {
- Icon(Icons.Default.Check, contentDescription = null, Modifier.size(18.dp))
- Spacer(Modifier.width(4.dp))
- Text("Undone")
- }
- h.undo != null -> TextButton(onClick = { if (h.undo == Action.Disable) disabling = h else onUndo(h) }, enabled = !busy) { Text(Copy.undo(h.undo)) }
- }
- }
- }
-}
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
index 4832a77..b891acb 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
@@ -7,6 +7,7 @@ package app.tellyscope.ui
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.ExperimentalFoundationApi
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
@@ -16,6 +17,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
@@ -43,8 +45,6 @@ import androidx.compose.material3.BadgedBox
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
-import androidx.compose.material3.DropdownMenu
-import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.ExtendedFloatingActionButton
@@ -55,6 +55,7 @@ import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialShapes
import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.ShortNavigationBar
import androidx.compose.material3.ShortNavigationBarItem
@@ -67,6 +68,7 @@ import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
+import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.toShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
@@ -76,6 +78,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
@@ -102,8 +105,10 @@ import app.tellyscope.adb.TvFolder
import app.tellyscope.data.Action
import app.tellyscope.data.AppInfo
import app.tellyscope.data.DeviceState
+import app.tellyscope.data.HistoryBook
import app.tellyscope.data.Snapshot
import app.tellyscope.data.Suggestions
+import kotlinx.coroutines.launch
/** The TV page's destinations, one job each, in the bottom bar. */
enum class TvTab(val label: String) { Overview("Overview"), Apps("Apps"), Files("Files"), Tweaks("Tweaks") }
@@ -144,10 +149,13 @@ fun DeviceTabsScreen(
actions: DeviceActions,
snackbar: SnackbarHostState = remember { SnackbarHostState() },
startTab: TvTab = TvTab.Overview,
+ /** The tab shown, so a screen opened from here can come back to it. */
+ onTab: (TvTab) -> Unit = {},
) {
val device = state.selected ?: return
val ui = state.device
var tab by rememberSaveable { mutableStateOf(startTab) }
+ LaunchedEffect(tab) { onTab(tab) }
var searching by rememberSaveable { mutableStateOf(false) }
var appsTab by rememberSaveable { mutableStateOf(AppsTab.Running) }
val q = state.query.trim().lowercase()
@@ -176,8 +184,6 @@ fun DeviceTabsScreen(
}
}
// The tabs share one list, so each opens at the top with its hero, not where the last one was left.
- // "See changes" lands on Tweaks scrolled to Recent changes, the item after the hero and the cards above it.
- var toChanges by remember { mutableStateOf(false) }
var shown by rememberSaveable { mutableStateOf(tab) }
var gate by rememberSaveable { mutableStateOf(false) }
if (gate) {
@@ -206,9 +212,7 @@ fun DeviceTabsScreen(
LaunchedEffect(tab) {
if (tab == shown) return@LaunchedEffect
shown = tab
- val hub = !offline && homeLaunchers(ui.apps).isNotEmpty()
- list.scrollToItem(if (tab == TvTab.Tweaks && toChanges) (if (hub) 3 else 2) else 0)
- toChanges = false
+ list.scrollToItem(0)
}
// Opening search starts the results from the top; closing it brings the TV back into view.
var wasSearching by rememberSaveable { mutableStateOf(searching) }
@@ -331,7 +335,7 @@ fun DeviceTabsScreen(
}
}
// The list, what's plugged in, and Android.
- item { SuggestedCard(ui.lists, debloat, offline, onChanges = { toChanges = true; tab = TvTab.Tweaks }) }
+ item { SuggestedCard(ui.lists, debloat, offline, onChanges = actions.history) }
ui.peripherals?.takeIf { !offline }?.let { p -> item(key = "connectedDevices") { ConnectedDevicesCard(p) } }
item { AndroidCard(state, snap, offline, onUpdates = actions.checkUpdates) }
}
@@ -401,11 +405,6 @@ fun DeviceTabsScreen(
if (homeLaunchers(ui.apps).isNotEmpty()) item { Panel(Copy.HOME_SCREEN) { HomeScreenBlock(ui, actions) } }
item { Panel(Copy.TWEAKS) { TweaksBlock(ui, actions) } }
}
- item {
- Panel("Recent changes") {
- HistoryList(ui.history, state.clock(), actions.undo, restoring = ui.busy == RESTORING, onRestoreAll = actions.restoreAll, busy = ui.busy != null)
- }
- }
}
}
item(key = "tail") { Spacer(Modifier.height(with(LocalDensity.current) { tail.toDp() }).testTag("tail")) }
@@ -439,9 +438,11 @@ private fun Muted(text: String) {
}
/**
- * The overflow: the TV on top, so it's clear which TV its items touch, then two blocks, this TV's
- * items and then the app-wide ones.
+ * The overflow, as a bottom sheet: the TV on top, so it's clear which TV its items touch, then this
+ * TV's items, the app-wide ones, and Forget on its own. ⋮ carries a dot: red while others are
+ * connected, else the primary colour for a change since History was last opened.
*/
+@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun AppMenu(state: UiState, actions: DeviceActions) {
var open by remember { mutableStateOf(false) }
@@ -459,44 +460,91 @@ private fun AppMenu(state: UiState, actions: DeviceActions) {
)
if (forgetting) ForgetDialog(name(device), onForget = { forgetting = false; actions.forget(device.id) }, onDismiss = { forgetting = false })
if (renaming) RenameDialog(device.nickname.orEmpty(), device.model ?: networkName(device), onSave = { renaming = false; actions.rename(device.id, it) }, onDismiss = { renaming = false })
- Box {
- val others = state.device.access?.others.orEmpty().size
- IconButton(onClick = { open = true }) {
- // The access warning shows on ⋮ too, so it's there from every tab.
- BadgedBox(badge = { if (others > 0) Badge() }) { Icon(Icons.Default.MoreVert, contentDescription = "More options") }
- }
- DropdownMenu(open, onDismissRequest = { open = false }, shape = MaterialTheme.shapes.large) {
- Row(Modifier.padding(start = 12.dp, end = 16.dp, top = 4.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
- Cookie(device, 40.dp)
- Spacer(Modifier.width(12.dp))
+ val c = MaterialTheme.colorScheme
+ val others = state.device.access?.others.orEmpty().size
+ val fresh = state.historyNew
+ IconButton(onClick = { open = true }) {
+ // The access warning shows on ⋮ too, so it's there from every tab; it outranks a new change.
+ BadgedBox(badge = { MenuDot(others > 0, fresh) }) { Icon(Icons.Default.MoreVert, contentDescription = "More options") }
+ }
+ if (!open) return
+ val sheet = rememberModalBottomSheetState(skipPartiallyExpanded = true)
+ val scope = rememberCoroutineScope()
+ // The sheet slides away before what was picked opens.
+ val pick = { then: () -> Unit -> scope.launch { sheet.hide() }.invokeOnCompletion { open = false; then() } }
+ ModalBottomSheet(onDismissRequest = { open = false }, sheetState = sheet) {
+ Column(Modifier.padding(start = 16.dp, end = 16.dp, bottom = 16.dp)) {
+ Row(Modifier.padding(start = 4.dp, bottom = 16.dp), verticalAlignment = Alignment.CenterVertically) {
+ Cookie(device, 48.dp)
+ Spacer(Modifier.width(16.dp))
Column {
- Text(name(device), style = MaterialTheme.typography.titleSmall)
- val made = makerLine(device)
- if (made.isNotEmpty()) Text(made, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(name(device), style = MaterialTheme.typography.titleLarge)
+ val health = state.device.snapshot?.takeIf { device.state == DeviceState.Online }?.let { Copy.health(it, heaviest(it, state.device.apps)).text }
+ val line = listOf(makerLine(device), health.orEmpty()).filter { it.isNotEmpty() }.joinToString(" · ")
+ if (line.isNotEmpty()) Text(line, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
}
}
- MenuBlock {
- DropdownMenuItem(text = { Text("Rename this TV") }, leadingIcon = { Icon(Icons.Default.Edit, null) }, onClick = { open = false; renaming = true })
- DropdownMenuItem(text = { Text("Forget this TV") }, leadingIcon = { Icon(Icons.Default.Delete, null) }, onClick = { open = false; forgetting = true })
- DropdownMenuItem(
- text = {
- Column {
- Text(Copy.WHO_HAS_ACCESS)
- if (others > 0) Text(Copy.othersConnected(others), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error)
- }
- },
- leadingIcon = {
- BadgedBox(badge = { if (state.device.access?.warning == true) Badge() }) { Icon(AccessIcons.Shield, null) }
- },
- onClick = { open = false; actions.whoHasAccess() },
- )
- DropdownMenuItem(text = { Text("Advanced") }, leadingIcon = { Icon(Icons.Default.List, null) }, onClick = { open = false; actions.advanced() })
- }
- Spacer(Modifier.height(4.dp))
- MenuBlock {
- DropdownMenuItem(text = { Text("Settings") }, leadingIcon = { Icon(Icons.Default.Settings, null) }, onClick = { open = false; actions.settings() })
- DropdownMenuItem(text = { Text("About & licences") }, leadingIcon = { Icon(Icons.Default.Info, null) }, onClick = { open = false; about = true })
- }
+ val off = HistoryBook.leftDisabled(state.device.history).size
+ SheetGroup(
+ { MenuRow(Icons.Default.Edit, "Rename this TV") { pick { renaming = true } } },
+ { MenuRow(HistoryIcons.History, Copy.HISTORY, Copy.stillOff(off).takeIf { off > 0 }, dot = { if (fresh) MenuDot(false, true) }) { pick(actions.history) } },
+ {
+ MenuRow(
+ AccessIcons.Shield, Copy.WHO_HAS_ACCESS,
+ Copy.othersConnected(others).takeIf { others > 0 }, subColor = c.error,
+ dot = { if (state.device.access?.warning == true) MenuDot(true, false) },
+ ) { pick(actions.whoHasAccess) }
+ },
+ { MenuRow(Icons.Default.List, Copy.ADVANCED_MONITOR) { pick(actions.advanced) } },
+ )
+ Text("Tellyscope", style = MaterialTheme.typography.labelLarge, color = c.onSurfaceVariant, modifier = Modifier.padding(start = 16.dp, top = 16.dp, bottom = 8.dp))
+ SheetGroup(
+ { MenuRow(Icons.Default.Settings, "Settings") { pick(actions.settings) } },
+ { MenuRow(Icons.Default.Info, "About & licences") { pick { about = true } } },
+ )
+ Spacer(Modifier.height(16.dp))
+ // Apart and in red, so it isn't one slip from an everyday item.
+ SheetGroup({ MenuRow(Icons.Default.Delete, "Forget this TV", tint = c.error) { pick { forgetting = true } } })
+ }
+ }
+}
+
+/** ⋮'s dot: red for [warning], else the primary colour for something [fresh]; nothing otherwise. */
+@Composable
+private fun MenuDot(warning: Boolean, fresh: Boolean) {
+ if (warning) Badge() else if (fresh) Badge(containerColor = MaterialTheme.colorScheme.primary)
+}
+
+/** One group of the sheet: rows 2 dp apart, rounded at the group's ends. */
+@Composable
+private fun SheetGroup(vararg rows: @Composable () -> Unit) {
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ rows.forEachIndexed { i, row ->
+ Surface(color = MaterialTheme.colorScheme.surfaceContainerHighest, shape = groupShape(i, rows.size)) { row() }
+ }
+ }
+}
+
+@Composable
+private fun MenuRow(
+ icon: ImageVector,
+ text: String,
+ sub: String? = null,
+ subColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
+ /** Icon and text in this colour, for Forget; else the usual ones. */
+ tint: Color? = null,
+ dot: @Composable () -> Unit = {},
+ onClick: () -> Unit,
+) {
+ Row(
+ Modifier.fillMaxWidth().clickable(onClick = onClick).heightIn(min = 56.dp).padding(horizontal = 16.dp, vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ BadgedBox(badge = { dot() }) { Icon(icon, contentDescription = null, tint = tint ?: MaterialTheme.colorScheme.onSurfaceVariant) }
+ Spacer(Modifier.width(16.dp))
+ Column {
+ Text(text, style = MaterialTheme.typography.bodyLarge, color = tint ?: MaterialTheme.colorScheme.onSurface)
+ sub?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = subColor) }
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt b/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt
new file mode 100644
index 0000000..d1a9966
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt
@@ -0,0 +1,207 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.foundation.layout.Arrangement
+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.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.shape.RoundedCornerShape
+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.Delete
+import androidx.compose.material.icons.filled.Home
+import androidx.compose.material.icons.filled.PlayArrow
+import androidx.compose.material.icons.filled.Settings
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Card
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.FilledTonalButton
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+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.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.graphics.Color
+import androidx.compose.ui.graphics.PathFillType
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.graphics.vector.PathParser
+import androidx.compose.ui.unit.dp
+import app.tellyscope.data.Action
+import app.tellyscope.data.HistoryBook
+import app.tellyscope.data.HistoryEntry
+
+/**
+ * Every change Tellyscope made on the TV, newest first, each with its Undo, and Restore everything
+ * on top while apps it turned off are still off. Opened from ⋮ and from "See changes".
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun HistoryScreen(
+ state: UiState,
+ onUndo: (HistoryEntry) -> Unit,
+ onRestoreAll: () -> Unit,
+ back: () -> Unit,
+ snackbar: SnackbarHostState = remember { SnackbarHostState() },
+) {
+ val device = state.selected ?: return
+ val ui = state.device
+ Scaffold(
+ snackbarHost = { SnackbarHost(snackbar) },
+ topBar = {
+ TopAppBar(
+ title = {
+ Column {
+ Text(Copy.HISTORY)
+ Text(name(device), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ },
+ 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),
+ ) {
+ item {
+ if (ui.history.isEmpty()) EmptyState(HistoryIcons.History, "Nothing changed yet", "Anything you stop, disable or turn on shows up here, with a way to undo it.")
+ else HistoryList(ui.history, state.clock(), onUndo, restoring = ui.busy == RESTORING, onRestoreAll = onRestoreAll, busy = ui.busy != null)
+ }
+ }
+ }
+}
+
+/**
+ * The Restore card while apps Tellyscope turned off are still off, then one row per change. While
+ * anything runs on the TV, a restore included, Undo and Restore wait for it.
+ */
+@Composable
+internal fun HistoryList(
+ history: List<HistoryEntry>,
+ now: Long,
+ onUndo: (HistoryEntry) -> Unit,
+ restoring: Boolean = false,
+ onRestoreAll: () -> Unit = {},
+ busy: Boolean = restoring,
+) {
+ var confirming by rememberSaveable { mutableStateOf(false) }
+ val off = HistoryBook.leftDisabled(history).size
+ if (confirming) RestoreDialog(off, onRestore = { confirming = false; onRestoreAll() }, onDismiss = { confirming = false })
+ var disabling by remember { mutableStateOf<HistoryEntry?>(null) }
+ disabling?.let { h ->
+ UndoDisableDialog(h, onDisable = { disabling = null; onUndo(h) }, onDismiss = { disabling = null })
+ }
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ if (off > 0) {
+ Card(
+ Modifier.fillMaxWidth().padding(bottom = 14.dp),
+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow),
+ shape = MaterialTheme.shapes.large,
+ ) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
+ Text(Copy.stillOffTitle(off), style = MaterialTheme.typography.titleSmall)
+ Text(Copy.STILL_OFF_TEXT, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Spacer(Modifier.size(8.dp))
+ FilledTonalButton(onClick = { confirming = true }, enabled = !busy) {
+ if (restoring) {
+ CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Spacer(Modifier.width(8.dp))
+ Text("Turning apps back on…")
+ } else {
+ Text("Restore everything ($off)")
+ }
+ }
+ }
+ }
+ }
+ history.forEachIndexed { i, h ->
+ Surface(color = MaterialTheme.colorScheme.surfaceContainerLow, shape = groupShape(i, history.size), modifier = Modifier.fillMaxWidth()) {
+ Row(Modifier.padding(start = 16.dp, end = 4.dp, top = 8.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
+ Icon(HistoryIcons.of(h.action), contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant)
+ Spacer(Modifier.width(16.dp))
+ Column(Modifier.weight(1f)) {
+ Text(Copy.done(h.action, h.label), style = MaterialTheme.typography.bodyLarge)
+ Text(Copy.ago(h.at, now), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ when {
+ // Same button as Undo, switched off: the row keeps its shape and reads as done.
+ h.undoneAt != null -> TextButton(
+ onClick = {},
+ enabled = false,
+ colors = ButtonDefaults.textButtonColors(disabledContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
+ ) {
+ Icon(Icons.Default.Check, contentDescription = null, Modifier.size(18.dp))
+ Spacer(Modifier.width(4.dp))
+ Text("Undone")
+ }
+ h.undo != null -> TextButton(onClick = { if (h.undo == Action.Disable) disabling = h else onUndo(h) }, enabled = !busy) { Text(Copy.undo(h.undo)) }
+ }
+ }
+ }
+ }
+ }
+}
+
+/** A row of a grouped list: the group's ends are rounded, the rows between nearly square. */
+internal fun groupShape(i: Int, n: Int) = RoundedCornerShape(
+ topStart = if (i == 0) 16.dp else 4.dp,
+ topEnd = if (i == 0) 16.dp else 4.dp,
+ bottomStart = if (i == n - 1) 16.dp else 4.dp,
+ bottomEnd = if (i == n - 1) 16.dp else 4.dp,
+)
+
+internal object HistoryIcons {
+ // Material's history: a clock with an arrow round it. Absolute commands only, as in TileIcons.
+ val History = icon(
+ "History",
+ "M13 3A9 9 0 0 0 4 12H1L4.89 15.89L4.96 16.03L9 12H6C6 8.13 9.13 5 13 5S20 8.13 20 12S16.87 19 13 19" +
+ "C11.07 19 9.32 18.21 8.06 16.94L6.64 18.36A8.954 8.954 0 0 0 13 21A9 9 0 0 0 13 3Z" +
+ "M12 8V13L16.28 15.54L17 14.33L13.5 12.25V8Z",
+ )
+ // Material's block, stop_circle and check_circle outlines: a ring, its inside cut out by even-odd.
+ private const val RING = "M12 2A10 10 0 1 0 12 22A10 10 0 1 0 12 2ZM12 4A8 8 0 1 1 12 20A8 8 0 1 1 12 4Z"
+ val Block = icon("Block", RING + "M16.9 5.69L18.31 7.1L7.1 18.31L5.69 16.9Z", PathFillType.EvenOdd)
+ val Stopped = icon("Stopped", RING + "M8 8H16V16H8Z", PathFillType.EvenOdd)
+ val TurnedOn = icon("TurnedOn", RING + "M16.59 7.58L10 14.17L6.41 10.59L5 12L10 17L18 9Z", PathFillType.EvenOdd)
+
+ fun of(action: Action): ImageVector = when (action) {
+ Action.Disable -> Block
+ Action.Stop -> Stopped
+ Action.Enable -> TurnedOn
+ Action.Open -> Icons.Default.PlayArrow
+ Action.Uninstall, Action.ClearCaches -> Icons.Default.Delete
+ Action.Home, Action.HomeBack -> Icons.Default.Home
+ Action.Change -> Icons.Default.Settings
+ }
+
+ private fun icon(name: String, path: String, fill: PathFillType = PathFillType.NonZero) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
+ .addPath(PathParser().parsePathString(path).toNodes(), pathFillType = fill, fill = SolidColor(Color.Black))
+ .build()
+}
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
index 257780e..2d2771b 100644
--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
@@ -518,19 +518,22 @@ private fun RemoteMenu(screenControl: Boolean, off: Boolean, live: Boolean, show
) {
IconButton(onClick = { open = true }) { Icon(Icons.Default.MoreVert, contentDescription = "More options") }
}
+ // One block, like the dock's menu and the TV menu's groups.
DropdownMenu(open, onDismissRequest = { open = false }, shape = MaterialTheme.shapes.large) {
- if (screenControl) DropdownMenuItem(
- text = { Text(if (off) Copy.SCREEN_ON else Copy.SCREEN_OFF) },
- leadingIcon = { Icon(RemoteIcons.TvOff, null) },
- enabled = live,
- onClick = { open = false; actions.screenOff(!off) },
- )
- DropdownMenuItem(
- text = { Text(Copy.REMOTE_RESTART) },
- leadingIcon = { Icon(RemoteIcons.RestartAlt, null) },
- enabled = live,
- onClick = { open = false; onRestart() },
- )
+ MenuBlock {
+ if (screenControl) DropdownMenuItem(
+ text = { Text(if (off) Copy.SCREEN_ON else Copy.SCREEN_OFF) },
+ leadingIcon = { Icon(RemoteIcons.TvOff, null) },
+ enabled = live,
+ onClick = { open = false; actions.screenOff(!off) },
+ )
+ DropdownMenuItem(
+ text = { Text(Copy.REMOTE_RESTART) },
+ leadingIcon = { Icon(RemoteIcons.RestartAlt, null) },
+ enabled = live,
+ onClick = { open = false; onRestart() },
+ )
+ }
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 3b46554..d5925df 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -48,6 +48,7 @@ import app.tellyscope.data.TvSettings
import app.tellyscope.data.TvTweaks
import app.tellyscope.data.Update
import app.tellyscope.data.FoldBook
+import app.tellyscope.data.SeenBook
import app.tellyscope.data.UpdateCheck
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableDeferred
@@ -229,7 +230,11 @@ data class UiState(
val foldedSystem: Set<AppsTab> = emptySet(),
/** The report screen; null when it's closed. */
val report: ReportUi? = null,
+ /** When each TV's History was last opened, by id. */
+ val historySeen: Map<String, Long> = emptyMap(),
) {
+ /** The selected TV has a change since its History was last opened: ⋮ shows a dot. */
+ val historyNew: Boolean get() = selectedId?.let { id -> device.history.any { it.at > (historySeen[id] ?: 0L) } } == true
val selected: Device? get() = devices.firstOrNull { it.id == selectedId }
}
@@ -301,6 +306,7 @@ class TellyscopeViewModel(
private val keyHaptics: KeyHaptics? = null,
/** App-wide prompts the user turned off: [DEBLOAT_GATE]. */
private val gates: FoldBook? = null,
+ private val historySeen: SeenBook? = null,
/** This build and phone, for reports. */
private val appFacts: AppFacts = AppFacts("unknown", "unknown phone"),
) : ViewModel() {
@@ -379,6 +385,9 @@ class TellyscopeViewModel(
gates?.let { g ->
viewModelScope.launch(Dispatchers.IO) { _state.update { it.copy(debloatGate = DEBLOAT_GATE !in g.folded()) } }
}
+ historySeen?.let { h ->
+ viewModelScope.launch(Dispatchers.IO) { _state.update { it.copy(historySeen = h.seen()) } }
+ }
folds?.let { f ->
viewModelScope.launch(Dispatchers.IO) {
val folded = f.folded().mapNotNull { name -> AppsTab.entries.firstOrNull { it.name == name } }.toSet()
@@ -1534,6 +1543,16 @@ class TellyscopeViewModel(
viewModelScope.launch(Dispatchers.IO) { gates?.set(DEBLOAT_GATE, true) }
}
+ /** History opened: its newest change is seen, so ⋮ loses its dot until the next one. */
+ fun historyOpened() {
+ val s = _state.value
+ val id = s.selectedId ?: return
+ val at = s.device.history.maxOfOrNull { it.at } ?: return
+ if (at <= (s.historySeen[id] ?: 0L)) return
+ _state.update { it.copy(historySeen = it.historySeen + (id to at)) }
+ viewModelScope.launch(Dispatchers.IO) { historySeen?.set(id, at) }
+ }
+
fun screenOffTipSeen() {
_state.update { it.copy(screenOffTip = false) }
viewModelScope.launch(Dispatchers.IO) { keyHaptics?.screenOffTipSeen = true }
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index ca2e07e..c1c2748 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -52,6 +52,7 @@ import app.tellyscope.data.DeviceState
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.HistoryEntry
import app.tellyscope.data.TvSettings
+import app.tellyscope.data.TvAccess
import app.tellyscope.data.TvTweaks
import app.tellyscope.data.ListEntry
import app.tellyscope.data.PickedApp
@@ -75,9 +76,11 @@ import app.tellyscope.ui.DebloatGate
import app.tellyscope.ui.DebloatScreen
import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceTabsScreen
+import app.tellyscope.ui.RESTORING
import app.tellyscope.ui.TvTab
import app.tellyscope.data.LastKnown
import app.tellyscope.ui.Copy
+import app.tellyscope.ui.HistoryScreen
import app.tellyscope.ui.TweaksBlock
import app.tellyscope.ui.DeviceUi
import app.tellyscope.ui.DisableDialog
@@ -122,6 +125,7 @@ import java.nio.file.Files
import kotlin.random.Random
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
@@ -378,16 +382,16 @@ class ScreenshotTest {
@Test fun md3_tweaks_offline_dark() { shot("75_md3_tweaks_offline", dark = true) { DeviceTabsScreen(offlineMd3(), DeviceActions(), startTab = TvTab.Tweaks) } }
@Config(qualifiers = "w411dp-h640dp-xxhdpi")
@Test fun md3_tweaks_collapsed_dark() = collapsed("66_md3_tweaks_collapsed", true, "Connected", TvTab.Tweaks)
- // "See changes" on Overview still lands on Tweaks at Recent changes, the end space notwithstanding.
- @Test fun seeChangesLandsOnRecentChanges() {
+ // "See changes" on Overview opens History, and Tweaks no longer lists the changes.
+ @Test fun seeChangesOpensHistory() {
+ var opened = 0
compose.mainClock.autoAdvance = false
- compose.setContent { TellyscopeTheme(dynamic = false) { DeviceTabsScreen(md3State(), DeviceActions()) } }
+ compose.setContent { TellyscopeTheme(dynamic = false) { DeviceTabsScreen(md3State(), DeviceActions(history = { opened++ })) } }
compose.mainClock.advanceTimeBy(1_000)
compose.onNode(hasScrollAction()).performScrollToNode(hasText("See changes"))
compose.onNodeWithText("See changes").performClick()
compose.mainClock.advanceTimeBy(1_000)
- compose.onNodeWithText("Recent changes").assertIsDisplayed()
- compose.onAllNodesWithText("Connected").onFirst().assertExists() // folded into the bar
+ assertEquals(1, opened)
}
@Config(qualifiers = "w411dp-h640dp-xxhdpi")
@Test fun md3_tweaks_collapsed() = collapsed("66_md3_tweaks_collapsed", false, "Connected", TvTab.Tweaks)
@@ -575,20 +579,21 @@ class ScreenshotTest {
compose.mainClock.autoAdvance = false
compose.setContent {
TellyscopeTheme(dark = false, dynamic = false) {
- DeviceTabsScreen(tabsState(), DeviceActions(advanced = { calls += "advanced" }, settings = { calls += "settings" }))
+ DeviceTabsScreen(tabsState(), DeviceActions(advanced = { calls += "advanced" }, settings = { calls += "settings" }, history = { calls += "history" }))
}
}
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithContentDescription("More options").performClick()
compose.mainClock.advanceTimeBy(1_000)
- // Both blocks are there: this TV's items, then the app's. Rename, Forget and About open dialogs.
- for (i in listOf("Rename this TV", "Forget this TV", "Advanced", "Settings", "About & licences")) compose.onNodeWithText(i).assertHasClickAction()
+ // Every group is there: this TV's items, the app's, then Forget. Rename, Forget and About open dialogs.
+ for (i in listOf("Rename this TV", Copy.HISTORY, Copy.ADVANCED_MONITOR, "Settings", "About & licences", "Forget this TV")) compose.onNodeWithText(i).assertHasClickAction()
compose.onNodeWithText(item).performClick()
compose.mainClock.advanceTimeBy(1_000)
return calls
}
- @Test fun tabs_menuAdvancedOpensAdvanced() = assertEquals(listOf("advanced"), pickFromMenu("Advanced"))
+ @Test fun tabs_menuAdvancedOpensAdvanced() = assertEquals(listOf("advanced"), pickFromMenu(Copy.ADVANCED_MONITOR))
+ @Test fun tabs_menuHistoryOpensHistory() = assertEquals(listOf("history"), pickFromMenu(Copy.HISTORY))
@Test fun tabs_menuSettingsOpensSettings() = assertEquals(listOf("settings"), pickFromMenu("Settings"))
private fun settings(opened: MutableList<String> = mutableListOf()) = @Composable {
@@ -630,6 +635,37 @@ class ScreenshotTest {
shot("45_tabs_app_menu", dark, screen = true, before = open) { DeviceTabsScreen(tabsState(), DeviceActions()) }
}
+ // Someone else connected: red on ⋮ and on Who has access, and History keeps its own dot.
+ private fun appMenuWarning(dark: Boolean) {
+ val other = TvAccess(listOf(app.tellyscope.data.AccessClient("192.0.2.47", 1, app.tellyscope.data.AccessClient.Who.Other)), emptyList())
+ val open = { compose.onNodeWithContentDescription("More options").performClick(); compose.mainClock.advanceTimeBy(1_000); Unit }
+ shot("45_tabs_app_menu_warning", dark, screen = true, before = open) { DeviceTabsScreen(tabsState().let { it.copy(device = it.device.copy(access = other)) }, DeviceActions()) }
+ compose.onNodeWithText(Copy.othersConnected(1)).assertExists()
+ }
+ @Test fun tabs_appMenuWarning() = appMenuWarning(false)
+ @Test fun tabs_appMenuWarning_dark() = appMenuWarning(true)
+
+ // ⋮'s dot is for a change newer than the last look at History, and goes once History has seen it.
+ @Test fun historyDotUntilSeen() {
+ val s = tabsState()
+ assertTrue(s.historyNew)
+ val newest = s.device.history.maxOf { it.at }
+ assertFalse(s.copy(historySeen = mapOf(s.selectedId!! to newest)).historyNew)
+ assertTrue(s.copy(historySeen = mapOf(s.selectedId!! to newest - 1)).historyNew)
+ assertFalse(s.copy(device = s.device.copy(history = emptyList())).historyNew)
+ }
+
+ private fun history(name: String, dark: Boolean, state: () -> UiState) = shot(name, dark) { HistoryScreen(state(), {}, {}, {}) }
+ @Test fun history_list() = history("46_history", false, ::tabsState)
+ @Test fun history_list_dark() = history("46_history", true, ::tabsState)
+ @Test fun history_restoring() = history("47_history_restoring", false) { tabsState().let { it.copy(device = it.device.copy(busy = RESTORING)) } }
+ @Test fun history_restoring_dark() = history("47_history_restoring", true) { tabsState().let { it.copy(device = it.device.copy(busy = RESTORING)) } }
+ @Test fun history_empty() {
+ history("48_history_empty", false) { deviceState() }
+ compose.onNodeWithText("Nothing changed yet").assertExists()
+ }
+ @Test fun history_empty_dark() = history("48_history_empty", true) { deviceState() }
+
@Test fun device_overview() {
shot("04_device") { DeviceTabsScreen(deviceState(), DeviceActions()) }
// Plain words on the main page: no Details expander, no MB per app; numbers live on Advanced.
@@ -1353,7 +1389,7 @@ class ScreenshotTest {
compose.onNodeWithText("Disable 4 apps?").assertExists()
}
- // Phone-sized, like every README shot: Recent changes (item 1 on Tweaks) scrolled to the top.
+ // Phone-sized, like every README shot: the History screen.
@Test fun readme_history() {
val history = listOf(
HistoryEntry(4, xgimi.ip, now - 40_000, Action.Disable, "com.google.android.tvrecommendations", "TV Recommendations", Action.Enable, null),
@@ -1361,7 +1397,7 @@ class ScreenshotTest {
HistoryEntry(2, xgimi.ip, now - 5 * 60_000, Action.Stop, "com.netflix.ninja", "Netflix", Action.Open, null),
HistoryEntry(1, xgimi.ip, now - 2 * 3_600_000, Action.Stop, "com.google.android.youtube.tv", "YouTube", Action.Open, now - 3_500_000),
)
- shot("22_readme_history", before = { compose.onNode(hasScrollAction()).performScrollToIndex(1); Unit }) { DeviceTabsScreen(deviceState { copy(history = history) }, DeviceActions(), startTab = TvTab.Tweaks) }
+ shot("22_readme_history") { HistoryScreen(deviceState { copy(history = history) }, {}, {}, {}) }
compose.onNodeWithText("Restore everything (2)").assertExists()
}
@Test fun readme_install() {
diff --git a/app/src/test/java/app/tellyscope/SeenBookTest.kt b/app/src/test/java/app/tellyscope/SeenBookTest.kt
new file mode 100644
index 0000000..8f1f977
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/SeenBookTest.kt
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.SeenBook
+import org.junit.Assert.assertEquals
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+
+class SeenBookTest {
+ @get:Rule val tmp = TemporaryFolder()
+
+ @Test fun `when History was last opened is kept per TV across restarts`() {
+ val file = tmp.root.resolve("history-seen.properties")
+ SeenBook(file).set("tv-a", 100L)
+ SeenBook(file).set("tv-b", 200L)
+ SeenBook(file).set("tv-a", 300L)
+ assertEquals(mapOf("tv-a" to 300L, "tv-b" to 200L), SeenBook(file).seen())
+ }
+
+ @Test fun `a TV whose History was never opened isn't listed`() {
+ assertEquals(emptyMap<String, Long>(), SeenBook(tmp.root.resolve("none.properties")).seen())
+ }
+}