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.
Swipe between tabs; Shell keeps the keyboard up after Enter
jesse-agent-23216cb35bf62f2
diff --git a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.ktindex 7133128..482b473 100644--- a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt@@ -131,13 +131,14 @@ fun AdvancedScreen() { pad ->Column(Modifier.fillMaxSize().padding(pad)) {Header(state, Modifier.padding(horizontal = 16.dp), onShell = { shellFrom = it; shellOpen = true })+ val tabs = listOf(R.string.advanced_this_tv, R.string.advanced_cpu, R.string.advanced_ram, R.string.advanced_network)PrimaryTabRow(selectedTabIndex = tab, Modifier.padding(top = 12.dp)) {- listOf(R.string.advanced_this_tv, R.string.advanced_cpu, R.string.advanced_ram, R.string.advanced_network).forEachIndexed { i, label ->+ tabs.forEachIndexed { i, label ->Tab(selected = tab == i, onClick = { tab = i }, text = { Text(stringResource(label), maxLines = 1) })}}LazyColumn(- Modifier.fillMaxSize(),+ Modifier.fillMaxSize().swipeTabs(tab, tabs.size) { tab = it },contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 32.dp),verticalArrangement = Arrangement.spacedBy(12.dp),) {diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.ktindex 25c9841..57a7478 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt@@ -294,7 +294,9 @@ fun DeviceTabsScreen(null}LazyColumn(- Modifier.fillMaxSize().padding(pad),+ Modifier.fillMaxSize().padding(pad)+ // Sideways swipes step through Running, Installed and Built-in, as the buttons do.+ .then(if (tab == TvTab.Apps && !searching) Modifier.swipeTabs(appsTab.ordinal, AppsTab.entries.size) { appsTab = AppsTab.entries[it] } else Modifier),state = list,// No top padding: the Apps tabs pin at the list's top edge, flush under the bar; the hero carries the 4dp.contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 96.dp),diff --git a/app/src/main/java/app/tellyscope/ui/ShellScreen.kt b/app/src/main/java/app/tellyscope/ui/ShellScreen.ktindex 9de8210..9e7ff0f 100644--- a/app/src/main/java/app/tellyscope/ui/ShellScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/ShellScreen.kt@@ -162,7 +162,9 @@ private fun Terminal(device: Device, online: Boolean, terminal: ShellTerminal, s}// The line being typed sits under the output, as in a terminal. While a command runs it stays// composed but blank and read-only, so the field keeps focus and the keyboard stays open.- item {+ // Its own key keeps it the same field as the output above it grows: by position, Enter's new+ // line would take its slot and dispose the focused field, closing the keyboard.+ item(key = "prompt") {Row(verticalAlignment = Alignment.Top) {when {state.running -> {}diff --git a/app/src/main/java/app/tellyscope/ui/SwipeTabs.kt b/app/src/main/java/app/tellyscope/ui/SwipeTabs.ktnew file mode 100644index 0000000..baef4d5--- /dev/null+++ b/app/src/main/java/app/tellyscope/ui/SwipeTabs.kt@@ -0,0 +1,44 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.ui++import androidx.compose.foundation.gestures.detectHorizontalDragGestures+import androidx.compose.runtime.getValue+import androidx.compose.runtime.rememberUpdatedState+import androidx.compose.ui.Modifier+import androidx.compose.ui.composed+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.platform.LocalLayoutDirection+import androidx.compose.ui.unit.LayoutDirection+import androidx.compose.ui.unit.dp+import kotlin.math.abs++/** A sideways swipe past this moves one tab; a shorter one does nothing. */+private val SWIPE_TAB = 48.dp++/** The tab a sideways swipe of [dx] lands on from [index] of [count]: the next one going left, the previous one going right, none past either end. */+internal fun swipedTab(index: Int, count: Int, dx: Float, rtl: Boolean, far: Float): Int? {+ if (abs(dx) < far) return null+ return (index + if ((dx < 0) != rtl) 1 else -1).takeIf { it in 0 until count }+}++/**+ * Swiping sideways over a tab's content moves to the next or previous tab, the same as tapping it.+ * Only a drag that goes sideways before it goes down is taken, so the list under it still scrolls.+ */+internal fun Modifier.swipeTabs(index: Int, count: Int, onSelect: (Int) -> Unit): Modifier = composed {+ val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl+ val current by rememberUpdatedState(index)+ val select by rememberUpdatedState(onSelect)+ pointerInput(count, rtl) {+ val far = SWIPE_TAB.toPx()+ var dx = 0f+ detectHorizontalDragGestures(+ onDragStart = { dx = 0f },+ onDragEnd = { swipedTab(current, count, dx, rtl, far)?.let(select) },+ ) { change, amount ->+ change.consume()+ dx += amount+ }+ }+}diff --git a/app/src/test/java/app/tellyscope/SwipeTabsTest.kt b/app/src/test/java/app/tellyscope/SwipeTabsTest.ktnew file mode 100644index 0000000..774275c--- /dev/null+++ b/app/src/test/java/app/tellyscope/SwipeTabsTest.kt@@ -0,0 +1,26 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import app.tellyscope.ui.swipedTab+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNull+import org.junit.Test++class SwipeTabsTest {+ @Test fun aSwipeLeftGoesToTheNextTabAndRightToThePrevious() {+ assertEquals(2, swipedTab(1, 4, dx = -80f, rtl = false, far = 48f))+ assertEquals(0, swipedTab(1, 4, dx = 80f, rtl = false, far = 48f))+ }++ @Test fun rightToLeftLayoutsSwipeTheOtherWay() {+ assertEquals(0, swipedTab(1, 4, dx = -80f, rtl = true, far = 48f))+ assertEquals(2, swipedTab(1, 4, dx = 80f, rtl = true, far = 48f))+ }++ @Test fun aShortSwipeOrOnePastTheEndStays() {+ assertNull(swipedTab(1, 4, dx = -20f, rtl = false, far = 48f))+ assertNull(swipedTab(3, 4, dx = -80f, rtl = false, far = 48f))+ assertNull(swipedTab(0, 4, dx = 80f, rtl = false, far = 48f))+ }+}