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.

Keep each TV's app and debloat lists across a switch

jesse-agent-232d3d29bac8785
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 685ffe4..84ff410 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -407,6 +407,9 @@ class TellyscopeViewModel(
/** Last stats per TV, so an offline page shows where it stood instead of blanks. Lives as long as the app. */
private val lastSnapshot = mutableMapOf<String, Snapshot>()
+ /** Each TV's app list and debloat list as last shown, so switching back shows them while fresh reads replace them. */
+ private val lastApps = mutableMapOf<String, List<AppInfo>>()
+ private val lastLists = mutableMapOf<String, Suggestions>()
/** Keys go out one at a time, in the order pressed. */
private val keys = Mutex()
@@ -647,10 +650,20 @@ class TellyscopeViewModel(
launcherJob?.cancel()
// A copy still running on this TV keeps its dialog, after a reconnect or a look at another TV.
val transfer = id?.let(transfers::get)
+ _state.value.let { s ->
+ // A forgotten TV is no longer in the list, and keeps nothing.
+ val old = s.selectedId?.takeIf { old -> s.devices.any { it.id == old } } ?: return@let
+ if (s.device.apps.isNotEmpty()) lastApps[old] = s.device.apps
+ s.device.lists?.let { lastLists[old] = it }
+ }
+ // Only an online TV gets its old lists back: the offline card stays as it was.
+ val online = _state.value.devices.firstOrNull { it.id == id }?.state == DeviceState.Online
// A removal survives the reconnect it causes; the TV coming back reselects it.
_state.update {
val removal = it.device.removal.takeIf { _ -> it.selectedId == id }
- it.copy(selectedId = id, device = DeviceUi(snapshot = id?.let(lastSnapshot::get), transfer = transfer, removal = removal), query = "")
+ val apps = if (online) id?.let(lastApps::get).orEmpty() else emptyList()
+ val lists = if (online) id?.let(lastLists::get) else null
+ it.copy(selectedId = id, device = DeviceUi(snapshot = id?.let(lastSnapshot::get), apps = apps, lists = lists, transfer = transfer, removal = removal), query = "")
}
val device = _state.value.selected ?: return
// History lives on the phone, so it shows (and undo is offered) even while the TV is off.
@@ -761,6 +774,8 @@ class TellyscopeViewModel(
fun forget(id: String) {
viewModelScope.launch {
source.forget(id)
+ lastApps.remove(id)
+ lastLists.remove(id)
val known = source.known()
val lists = runCatching { source.listSource() }.getOrNull()
_state.update { it.copy(devices = known, listSource = lists) }
@@ -1656,6 +1671,8 @@ class TellyscopeViewModel(
return@launch
}
val now = source.listSource()
+ // Every TV's list came from the old source.
+ lastLists.clear()
_state.update { it.copy(listSource = now, device = it.device.copy(lists = null)) }
_notice.value = Copy.listSource(now)
if (id != null) loadLists(id) { shownApps(id) }
diff --git a/app/src/test/java/app/tellyscope/ResultsLandOnTheirTvTest.kt b/app/src/test/java/app/tellyscope/ResultsLandOnTheirTvTest.kt
index 72b9c31..e811c83 100644
--- a/app/src/test/java/app/tellyscope/ResultsLandOnTheirTvTest.kt
+++ b/app/src/test/java/app/tellyscope/ResultsLandOnTheirTvTest.kt
@@ -138,6 +138,26 @@ class ResultsLandOnTheirTvTest {
assertEquals("tv-a", vm.done.value?.deviceId)
}
+ @Test fun switchingBackShowsTheLastListsUntilFreshOnesReplaceThem() = with(test) {
+ source.listKeep = setOf("kept")
+ vm = TellyscopeViewModel(source, clock = { 0L })
+ runCurrent()
+ vm.select("tv-b")
+ runCurrent()
+
+ source.appsDelayMs = 5_000
+ vm.select("tv-a")
+ runCurrent()
+ val page = vm.state.value.device
+ assertEquals(listOf("app-on-tv-a"), page.apps.map { it.packageName })
+ assertFalse(page.appsLoading)
+ assertEquals("tv-a", ((page.lists as Suggestions.Ready).list).id)
+
+ // The fresh read was still out; once it lands it replaces the shown list.
+ advanceTimeBy(5_100)
+ assertEquals(listOf("app-on-tv-a"), vm.state.value.device.apps.map { it.packageName })
+ }
+
@Test fun snackbarUndoGoesToTheTvItCameFrom() = with(test) {
vm = TellyscopeViewModel(source, clock = { 0L })
runCurrent()