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.

Apps shows a loader while the TV's app list is read

jesse-agent-2322b333cb1fee6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc059d2..dc6be29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ until this file has a section for its version.
## Unreleased
+- **Improved:** Apps shows it's loading while the TV's app list is read. [#PR](../../pull/PR)
- **Improved:** Opening a TV reads its apps once, in one go, so Apps fills in sooner. [#173](../../pull/173)
- **Improved:** App icons load once per TV and no longer slow the screen down. [#175](../../pull/175)
- **Improved:** Tellyscope stops polling your TV while it's in the background. [#172](../../pull/172)
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 4101e5b..d2e74be 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -260,6 +260,10 @@ object Copy {
const val SYSTEM = "System"
const val SYSTEM_WHY = "Needed by the TV · can't be changed"
+ /** Apps, while the TV's app list is being read. */
+ const val READING_APPS = "Reading the TV's apps…"
+ const val READING_APPS_LINE = "This takes a few seconds."
+
/** Running, with no word from the TV. */
const val TV_OFFLINE = "TV offline"
const val RUNNING_OFFLINE = "Running apps show here once the TV is connected."
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
index f111242..2501198 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
@@ -319,10 +319,12 @@ fun DeviceTabsScreen(
fun rows(apps: List<AppInfo>) = items(apps, key = { it.packageName }) { app ->
AppRow(app, procs, ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app), locked = ui.busy != null)
}
+ // Until the first read lands, an empty list means "not yet", not "none".
+ val loading = ui.appsLoading && !offline
if (searching) {
// One flat list of every matching app, whichever button it sits under; each row says
// whether it's running, off or protected.
- if (found.isEmpty()) item { EmptyLine(q) }
+ if (found.isEmpty()) item { if (loading) AppsLoading() else EmptyLine(q) }
rows(found)
} else {
stickyHeader(key = "appsTabs") {
@@ -338,7 +340,11 @@ fun DeviceTabsScreen(
if (split != null) {
if (split.apps.isEmpty() && split.system.isEmpty()) item {
// Away, the TV can't say what's running, rather than nothing is.
- if (appsTab == AppsTab.Running && live == null) EmptyState(DeviceIcons.Tv, Copy.TV_OFFLINE, Copy.RUNNING_OFFLINE) else EmptyLine(q)
+ when {
+ loading -> AppsLoading()
+ appsTab == AppsTab.Running && live == null -> EmptyState(DeviceIcons.Tv, Copy.TV_OFFLINE, Copy.RUNNING_OFFLINE)
+ else -> EmptyLine(q)
+ }
}
rows(split.apps)
if (split.system.isNotEmpty()) {
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index ed73e89..1997fa6 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -91,6 +91,8 @@ data class ScanUi(
data class DeviceUi(
val snapshot: Snapshot? = null,
val apps: List<AppInfo> = emptyList(),
+ /** The first read of [apps] after opening the TV is still out; ends on success, empty or error. */
+ val appsLoading: Boolean = false,
val network: NetworkInfo? = null,
val history: List<HistoryEntry> = emptyList(),
/** Package whose action row is open, and the action awaiting confirmation. */
@@ -551,6 +553,8 @@ class TellyscopeViewModel(
private fun watch(device: Device) {
if (paused || device.state != DeviceState.Online) return
val id = device.id
+ // Only a page with no list yet says it's loading; back from the background, the list stays up.
+ updateDevice(id) { it.copy(appsLoading = it.apps.isEmpty()) }
liveJob = viewModelScope.launch {
source.live(id).collect { snap ->
lastSnapshot[id] = snap
@@ -571,9 +575,10 @@ class TellyscopeViewModel(
source.apps(id)
} catch (e: Exception) {
apps.completeExceptionally(e)
+ updateDevice(id) { it.copy(appsLoading = false) }
throw e
}
- updateDevice(id) { it.copy(apps = read) }
+ updateDevice(id) { it.copy(apps = read, appsLoading = false) }
apps.complete(read)
pruneDock(id, read)
val tweaks = source.tweaks(id)
diff --git a/app/src/main/java/app/tellyscope/ui/TvHeader.kt b/app/src/main/java/app/tellyscope/ui/TvHeader.kt
index ea903e8..a2e1f4d 100644
--- a/app/src/main/java/app/tellyscope/ui/TvHeader.kt
+++ b/app/src/main/java/app/tellyscope/ui/TvHeader.kt
@@ -23,6 +23,7 @@ import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AssistChip
+import androidx.compose.material3.ContainedLoadingIndicator
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
@@ -343,3 +344,16 @@ internal fun EmptyState(icon: ImageVector, title: String, line: String) {
Text(line, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant, textAlign = TextAlign.Center)
}
}
+
+/** Where [EmptyState] would sit, while the TV's app list is still on its way. */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+internal fun AppsLoading() {
+ Column(Modifier.fillMaxWidth().padding(top = 96.dp, bottom = 24.dp), horizontalAlignment = Alignment.CenterHorizontally) {
+ ContainedLoadingIndicator(Modifier.size(56.dp))
+ Spacer(Modifier.height(16.dp))
+ Text(Copy.READING_APPS, style = MaterialTheme.typography.titleSmall, textAlign = TextAlign.Center)
+ Spacer(Modifier.height(4.dp))
+ Text(Copy.READING_APPS_LINE, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center)
+ }
+}
diff --git a/app/src/test/java/app/tellyscope/AppsLoadingTest.kt b/app/src/test/java/app/tellyscope/AppsLoadingTest.kt
new file mode 100644
index 0000000..c1e8579
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/AppsLoadingTest.kt
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import androidx.lifecycle.viewModelScope
+import app.tellyscope.data.AppInfo
+import app.tellyscope.data.Device
+import app.tellyscope.data.DeviceSource
+import app.tellyscope.data.DeviceState
+import app.tellyscope.data.FakeDeviceSource
+import app.tellyscope.data.HistoryEntry
+import app.tellyscope.data.ScanHit
+import app.tellyscope.data.ScanKind
+import app.tellyscope.data.Snapshot
+import app.tellyscope.ui.TellyscopeViewModel
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.cancel
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.advanceTimeBy
+import kotlinx.coroutines.test.resetMain
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.setMain
+import org.junit.After
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+
+/** One TV whose app list takes three seconds, then arrives, comes back empty, or fails. */
+private class SlowApps(private val state: DeviceState = DeviceState.Online) :
+ DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {
+ var reply: () -> List<AppInfo> = { listOf(AppInfo("com.example", "App", null, false, true, null, "")) }
+
+ override suspend fun known() = listOf(Device("tv", ScanHit("tv", 5555, ScanKind.Classic, "tv", null), state, null, null, null, 0L))
+ override fun live(deviceId: String): Flow<Snapshot> = emptyFlow()
+ override suspend fun history(deviceId: String) = emptyList<HistoryEntry>()
+ override suspend fun apps(deviceId: String): List<AppInfo> {
+ delay(3_000)
+ return reply()
+ }
+}
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class AppsLoadingTest {
+ private val dispatcher = StandardTestDispatcher()
+ private val test = TestScope(dispatcher)
+ private lateinit var vm: TellyscopeViewModel
+
+ @Before fun setUp() = Dispatchers.setMain(dispatcher)
+
+ @After fun tearDown() {
+ vm.viewModelScope.cancel()
+ Dispatchers.resetMain()
+ }
+
+ private fun TestScope.open(source: SlowApps) {
+ vm = TellyscopeViewModel(source, clock = { 0L })
+ runCurrent()
+ assertEquals("tv", vm.state.value.selectedId)
+ }
+
+ @Test fun appsLoadUntilTheListArrives() = with(test) {
+ open(SlowApps())
+ assertTrue(vm.state.value.device.appsLoading)
+ advanceTimeBy(3_100)
+ assertFalse(vm.state.value.device.appsLoading)
+ assertEquals(listOf("com.example"), vm.state.value.device.apps.map { it.packageName })
+ }
+
+ @Test fun anEmptyListEndsTheLoading() = with(test) {
+ open(SlowApps().apply { reply = { emptyList() } })
+ advanceTimeBy(3_100)
+ assertFalse(vm.state.value.device.appsLoading)
+ }
+
+ @Test fun aFailedReadEndsTheLoading() = with(test) {
+ open(SlowApps().apply { reply = { throw IllegalStateException("the TV dropped") } })
+ assertTrue(vm.state.value.device.appsLoading)
+ advanceTimeBy(3_100)
+ assertFalse(vm.state.value.device.appsLoading)
+ }
+
+ @Test fun anOfflineTvIsNotLoading() = with(test) {
+ open(SlowApps(DeviceState.Offline))
+ assertFalse(vm.state.value.device.appsLoading)
+ }
+}
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index 5e866af..55bdd04 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -423,6 +423,14 @@ class ScreenshotTest {
compose.onNodeWithText(Copy.RUNNING_OFFLINE).assertExists()
}
@Test fun md3_apps_offline_dark() { shot("71_md3_apps_offline", dark = true) { DeviceTabsScreen(offlineMd3(), DeviceActions(), startTab = TvTab.Apps) } }
+ // Just opened: the list is still on its way, so Apps says so rather than "Nothing here yet."
+ private fun appsLoading() = md3State().let { it.copy(device = it.device.copy(apps = emptyList(), appsLoading = true)) }
+ @Test fun md3_apps_loading() {
+ shot("78_md3_apps_loading") { DeviceTabsScreen(appsLoading(), DeviceActions(), startTab = TvTab.Apps) }
+ compose.onNodeWithText(Copy.READING_APPS).assertExists()
+ compose.onNodeWithText(Copy.TV_OFFLINE).assertDoesNotExist()
+ }
+ @Test fun md3_apps_loading_dark() { shot("78_md3_apps_loading", dark = true) { DeviceTabsScreen(appsLoading(), DeviceActions(), startTab = TvTab.Apps) } }
// Folded, the System header stays with its count and the protected apps go.
private fun foldedBuiltIn() = md3State().copy(foldedSystem = setOf(AppsTab.BuiltIn))
@Test fun md3_apps_builtin_folded() = appsTab("72_md3_apps_builtin_folded", false, "Built-in", ::foldedBuiltIn)