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.

Remote: the clear button becomes a backspace

jesse-agent-821f96e811fd6ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c61b38e..720332e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@ until this file has a section for its version.
- **Fixed:** A launcher you installed shows as protected only while it is Home. [#158](../../pull/158)
- **New:** Uninstall the launcher on Home: Home switches back first, then it goes. [#158](../../pull/158)
-- **Fixed:** The Remote's clear button empties the TV's text box in apps that ignored it. [#157](../../pull/157)
+- **Improved:** The Remote's clear button is now a backspace; hold it to keep deleting. [#157](../../pull/157)
- **Improved:** The launcher picker drops letter tiles and says we're not affiliated. [#156](../../pull/156)
- **Improved:** A USB camera shows a camera icon and its name once, under Input. [#154](../../pull/154)
- **Improved:** On Fire TV, the Remote's Home opens your default launcher. [#153](../../pull/153)
diff --git a/README.md b/README.md
index 949dc35..13d9a9d 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Debloat your Android TV, install apps, and browse and transfer files on it, all
<table>
<tr>
<td width="25%"><img src="docs/screenshots/tv-page.png" alt="A TV's page: the TV at a glance, its vitals, and the Install, Debloat and Send buttons"></td>
- <td width="25%"><img src="docs/screenshots/remote.png" alt="The Remote: Screen off in the top bar, a D-pad, icon keys for Back, Home, Menu, mute and volume, a dock of four TV apps, and typing on the TV with a button to clear its text box"></td>
+ <td width="25%"><img src="docs/screenshots/remote.png" alt="The Remote: Screen off in the top bar, a D-pad, icon keys for Back, Home, Menu, mute and volume, a dock of four TV apps, and typing on the TV with a backspace key"></td>
<td width="25%"><img src="docs/screenshots/debloat.png" alt="Debloat: the TV's model on top, then the apps it will turn off, each with its package name"></td>
<td width="25%"><img src="docs/screenshots/install.png" alt="Installing Kodi on the TV from an APK on the phone: the dialog says it is not on this TV yet"></td>
</tr>
@@ -86,7 +86,7 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
- **Connected devices.** The Overview lists what's paired with or plugged into the TV: Bluetooth remotes and headphones, USB keyboards and drives with their free space, HDMI-CEC devices such as a soundbar, and where the sound goes now.
- **Connection requests.** When another device asks to debug the TV, Tellyscope shows the TV's "Allow debugging?" prompt on your phone, with the device's key fingerprint, so you can **Allow** or **Deny** it without the remote. **Always allow this device** appears when the TV's own prompt offers it.
- **Files.** Send a file from your phone into the TV's Download or Movies folder, or save one from there to your phone. Two buttons under the TV pick the folder, and stay pinned under the bar as you scroll. An empty folder says so in the middle of the page. A file with the same name gets a " (1)" instead of being overwritten, and a cancelled copy leaves nothing half-written behind.
-- **Remote.** A D-pad and icon keys for Back, Home, Menu, mute and volume, laid out like Google TV's phone remote, plus typing on the TV. The backspace button next to Send empties the TV's text box and the one on your phone. Each key gives a short tick; **Vibrate on key press** in Settings turns it off. The D-pad's centre pauses a playing video. **Add to dock** puts up to four of the TV's apps under the volume keys, each one tap from opening on the TV. Long-press one to change or remove it, or keep holding and move it to reorder. An app uninstalled from the TV leaves the dock by itself, and a snackbar says so. The restart button in the top bar asks first, then waits for the TV to come back: **Hide** keeps the wait in the top bar, and after a minute **Retry** waits another one. **Screen off** in the top bar turns off the TV's picture while Tellyscope stays connected, say to listen to music; any key or closing the Remote turns it back on. It needs Android 13 or older.
+- **Remote.** A D-pad and icon keys for Back, Home, Menu, mute and volume, laid out like Google TV's phone remote, plus typing on the TV. The backspace key next to Send deletes one character on the TV, and holding it keeps deleting. Each key gives a short tick; **Vibrate on key press** in Settings turns it off. The D-pad's centre pauses a playing video. **Add to dock** puts up to four of the TV's apps under the volume keys, each one tap from opening on the TV. Long-press one to change or remove it, or keep holding and move it to reorder. An app uninstalled from the TV leaves the dock by itself, and a snackbar says so. The restart button in the top bar asks first, then waits for the TV to come back: **Hide** keeps the wait in the top bar, and after a minute **Retry** waits another one. **Screen off** in the top bar turns off the TV's picture while Tellyscope stays connected, say to listen to music; any key or closing the Remote turns it back on. It needs Android 13 or older.
## Setting up your TV
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt b/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
index 37709c0..4a0e757 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
@@ -33,9 +33,6 @@ class KeyHelper(val session: AdbSession, private val dex: ByteArray) : AutoClose
/** Types [text], already checked with [Remote.typeable]; answers like [press]. */
suspend fun type(text: String): Boolean? = send("t$text")
- /** Empties the focused text box on the TV (see [Remote.clearText]). Answers like [press]. */
- suspend fun clear(): Boolean? = send("c")
-
/** Turns the TV's picture off or on; the TV stays awake and connected. Answers like [press]. */
suspend fun screen(on: Boolean): Boolean? = send(if (on) "p2" else "p0")
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
index 6ce2310..6baee33 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
@@ -20,6 +20,8 @@ enum class RemoteKey(val code: Int, val repeats: Boolean = false) {
VOLUME_UP(24, repeats = true),
VOLUME_DOWN(25, repeats = true),
MUTE(164),
+ /** Backspace in the focused text box. */
+ DEL(67, repeats = true),
}
class Remote(private val session: AdbSession, private val keys: KeyHelper? = null) {
@@ -56,13 +58,6 @@ class Remote(private val session: AdbSession, private val keys: KeyHelper? = nul
/** Types [text] into whatever box has focus on the TV, through [keys] like [press]. Check [typeable] first. */
suspend fun type(text: String): Boolean = keys?.type(text) ?: (session.shell(typeCommand(text)).exitCode == 0)
- /**
- * Empties the focused text box on the TV: End, then [MAX_TEXT] Deletes, one Send's worth. The
- * key helper selects all and deletes first, which also clears longer text where the box takes
- * Ctrl+A; `input` can't send Ctrl+A on older Android. Throws if the link is gone.
- */
- suspend fun clearText(): Boolean = keys?.clear() ?: (session.shell(CLEAR_COMMAND).exitCode == 0)
-
/**
* Turns the TV's picture off or back on, leaving the TV awake so the link stays up. Only the
* key helper can: false when it isn't running or the TV refused. Throws if the link is gone.
@@ -96,9 +91,6 @@ class Remote(private val session: AdbSession, private val keys: KeyHelper? = nul
companion object {
const val MAX_TEXT = 200
- /** End, then a Delete per character. Keys.DELETES matches [MAX_TEXT]. */
- internal val CLEAR_COMMAND = "input keyevent 123" + " 67".repeat(MAX_TEXT)
-
/** `pkg/.Activity` or `pkg/pkg.Activity`; a nested class has a `$`, which the single quotes keep. */
private val COMPONENT = Regex("[A-Za-z0-9_.]+/[A-Za-z0-9_.$]+")
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
index f79997c..79cdd8a 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/RemoteTest.kt
@@ -45,18 +45,17 @@ class RemoteTest {
assertEquals("input keyevent 3", sh.ran.last())
}
- @Test fun clearGoesThroughTheHelperWhileItRuns() = runBlocking { // see KeyHelperTest
- val sh = FakeShell().apply { execOutput = "ready\n1\n" }
- assertTrue(Remote(sh, KeyHelper(sh, byteArrayOf(1))).clearText())
- assertEquals("c\n", sh.execInput.readUtf8())
- assertTrue(sh.ran.none { it.startsWith("input") })
+ @Test fun backspaceIsOneDelete() = runTest {
+ val sh = FakeShell()
+ assertTrue(Remote(sh).press(RemoteKey.DEL))
+ assertEquals(listOf("input keyevent 67"), sh.ran)
}
- @Test fun clearFallsBackToInputWhenTheHelperCannotStart() = runBlocking { // see KeyHelperTest
- val sh = FakeShell().apply { execOutput = "" }
- assertTrue(Remote(sh, KeyHelper(sh, byteArrayOf(1))).clearText())
- val codes = sh.ran.last().removePrefix("input keyevent ").split(' ')
- assertEquals(listOf("123") + List(Remote.MAX_TEXT) { "67" }, codes) // End, then a Delete per character
+ @Test fun backspaceGoesThroughTheHelperWhileItRuns() = runBlocking { // see KeyHelperTest
+ val sh = FakeShell().apply { execOutput = "ready\n1\n" }
+ assertTrue(Remote(sh, KeyHelper(sh, byteArrayOf(1))).press(RemoteKey.DEL))
+ assertEquals("67\n", sh.execInput.readUtf8())
+ assertTrue(sh.ran.none { it.startsWith("input") })
}
@Test fun fireHomeStartsTheDefaultLauncher() = runTest {
diff --git a/app/src/helper/java/app/tellyscope/helper/Keys.java b/app/src/helper/java/app/tellyscope/helper/Keys.java
index 5c1c870..c36cf52 100644
--- a/app/src/helper/java/app/tellyscope/helper/Keys.java
+++ b/app/src/helper/java/app/tellyscope/helper/Keys.java
@@ -29,10 +29,6 @@ import java.lang.reflect.Method;
public final class Keys {
/** InputManager's INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH: answers once the focused app is done with it. */
private static final int WAIT_FOR_FINISH = 2;
- /** INJECT_INPUT_EVENT_MODE_ASYNC: queued in order, no wait. */
- private static final int ASYNC = 0;
- /** Deletes after End: one Send's worth, Remote.MAX_TEXT. */
- private static final int DELETES = 200;
public static void main(String[] args) throws Exception {
Object manager;
@@ -62,11 +58,6 @@ public final class Keys {
out.flush();
continue;
}
- if (line.equals("c")) {
- out.print(clear(manager, inject) ? "1\n" : "0\n");
- out.flush();
- continue;
- }
if (line.startsWith("t")) {
out.print(type(manager, inject, keymap, line.substring(1)) ? "1\n" : "0\n");
out.flush();
@@ -122,43 +113,9 @@ public final class Keys {
}
}
- /**
- * Ctrl+A and Delete, then End and {@link #DELETES} Deletes for the boxes that ignore Ctrl+A.
- * The Deletes are queued without waiting and only the last one waits for the app: keys reach
- * it in order, so that answer covers them all and the batch stays well inside the answer wait.
- */
- private static boolean clear(Object manager, Method inject) {
- try {
- int ctrl = KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
- long now = SystemClock.uptimeMillis();
- boolean ok = send(manager, inject, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CTRL_LEFT, ctrl)
- && send(manager, inject, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A, ctrl)
- && send(manager, inject, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A, ctrl);
- // Ctrl comes back up even when A wasn't taken, so the TV isn't left holding it.
- ok = send(manager, inject, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_CTRL_LEFT, 0) && ok;
- long del = SystemClock.uptimeMillis();
- ok = ok
- && send(manager, inject, del, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0)
- && send(manager, inject, del, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL, 0);
- for (int i = 0; ok && i <= DELETES; i++) {
- int code = i == 0 ? KeyEvent.KEYCODE_MOVE_END : KeyEvent.KEYCODE_DEL;
- long down = SystemClock.uptimeMillis();
- ok = send(manager, inject, down, KeyEvent.ACTION_DOWN, code, 0, ASYNC)
- && send(manager, inject, down, KeyEvent.ACTION_UP, code, 0, i == DELETES ? WAIT_FOR_FINISH : ASYNC);
- }
- return ok;
- } catch (Throwable t) {
- return false;
- }
- }
-
private static boolean send(Object manager, Method inject, long downTime, int action, int code, int meta) throws Exception {
- return send(manager, inject, downTime, action, code, meta, WAIT_FOR_FINISH);
- }
-
- private static boolean send(Object manager, Method inject, long downTime, int action, int code, int meta, int mode) throws Exception {
KeyEvent e = new KeyEvent(downTime, SystemClock.uptimeMillis(), action, code, 0, meta,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
- return (Boolean) inject.invoke(manager, e, mode);
+ return (Boolean) inject.invoke(manager, e, WAIT_FOR_FINISH);
}
}
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 942e995..1dff39c 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -276,7 +276,6 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
actions = RemoteActions(
press = vm::press,
type = vm::type,
- clearText = vm::clearText,
reboot = vm::reboot,
back = { remote = false },
retryRestart = vm::retryRestart,
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 32ec7c4..27c39ba 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -710,7 +710,6 @@ class AdbDeviceSource(context: Context) : DeviceSource {
override suspend fun type(deviceId: String, text: String) = busy(deviceId) { remote(deviceId).type(text) }
- override suspend fun clearText(deviceId: String) = busy(deviceId) { remote(deviceId).clearText() }
override suspend fun screen(deviceId: String, on: Boolean) = busy(deviceId) { remote(deviceId).screen(on) }
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index 96fc3f3..00ff155 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -147,9 +147,6 @@ interface DeviceSource {
/** Types into the focused box on the TV. The caller checks [app.tellyscope.adb.Remote.typeable] first. */
suspend fun type(deviceId: String, text: String): Boolean
- /** Empties the focused text box on the TV. False when this TV can't, or refused. Throws when it's gone. */
- suspend fun clearText(deviceId: String): Boolean = false
-
/**
* Turns the TV's picture off or back on; the TV stays awake and connected. False when this TV
* can't (no key helper, or the TV refused). Throws when it's gone.
diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
index 575bfa4..feeb61b 100644
--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
@@ -314,11 +314,6 @@ class FakeDeviceSource(
return true
}
- override suspend fun clearText(deviceId: String): Boolean {
- delay(100)
- return true
- }
-
override suspend fun screen(deviceId: String, on: Boolean): Boolean {
delay(100)
return true
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index e91f64f..ea7d24f 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -423,8 +423,7 @@ object Copy {
const val REBOOT_IGNORED = "The TV didn't restart. Use its own remote or power button instead."
const val REMOTE_OFFLINE = "The TV is offline. The remote works again once it reconnects."
const val TYPE_HINT = "Select a text box on the TV, like a search box, then type here."
- const val CLEAR_TV_TEXT = "Clear the TV's text box"
- const val CLEAR_REFUSED = "The TV's text box didn't clear. Select it on the TV first, then try again."
+ const val BACKSPACE = "Backspace on the TV"
const val SCREEN_OFF = "Screen off"
const val SCREEN_ON = "Turn the screen back on"
const val SCREEN_OFF_WAKE = "tap any key to wake"
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
index 687f356..cf5956a 100644
--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
@@ -60,6 +60,7 @@ import androidx.compose.material3.FilledIconToggleButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
+import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LoadingIndicator
@@ -142,8 +143,6 @@ data class RemoteActions(
val press: suspend (RemoteKey) -> Boolean = { true },
/** Returns why the text can't be typed, or null once it's sent. */
val type: (String) -> String? = { null },
- /** Empties the text box on the TV; the Remote empties the phone's field with it. */
- val clearText: () -> Unit = {},
val reboot: () -> Unit = {},
val back: () -> Unit = {},
/** A restart running late: try the TV again and wait another minute. */
@@ -274,7 +273,7 @@ fun RemoteScreen(
}
// Clear space above and below, so a thumb aiming at a volume key doesn't open an app.
DockSection(state.device.dock, state.device.apps, name(device), live, actions, Modifier.padding(vertical = 4.dp))
- Keyboard(live, actions.type, actions.clearText)
+ Keyboard(live, actions.type, actions.press)
} }
}
}
@@ -373,7 +372,7 @@ private fun KeySurface(
@Composable
@OptIn(ExperimentalMaterial3Api::class)
-private fun Keyboard(enabled: Boolean, type: (String) -> String?, clearText: () -> Unit) {
+private fun Keyboard(enabled: Boolean, type: (String) -> String?, press: suspend (RemoteKey) -> Boolean) {
var text by rememberSaveable { mutableStateOf("") }
var error by rememberSaveable { mutableStateOf<String?>(null) }
fun send() {
@@ -392,15 +391,13 @@ private fun Keyboard(enabled: Boolean, type: (String) -> String?, clearText: ()
keyboardActions = KeyboardActions(onSend = { send() }),
trailingIcon = {
Row {
- TooltipBox(
- positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
- tooltip = { PlainTooltip { Text(Copy.CLEAR_TV_TEXT) } },
- state = rememberTooltipState(),
- ) {
- IconButton(onClick = { text = ""; error = null; clearText() }, enabled = enabled) {
- Icon(RemoteIcons.Backspace, contentDescription = Copy.CLEAR_TV_TEXT)
- }
- }
+ // A key, not a button: holding it repeats like the D-pad. Each Delete also takes the
+ // last character off the phone's field.
+ KeySurface(
+ RemoteKey.DEL, Copy.BACKSPACE, enabled,
+ { key -> text = text.dropLast(1); error = null; press(key) },
+ CircleShape, Color.Transparent, Modifier.size(48.dp),
+ ) { Icon(RemoteIcons.Backspace, null, tint = LocalContentColor.current.copy(alpha = if (enabled) 1f else 0.38f)) }
IconButton(onClick = ::send, enabled = enabled && text.isNotEmpty()) {
Icon(Icons.AutoMirrored.Filled.Send, contentDescription = "Send to the TV")
}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 9aa53cf..2b7a35e 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -1462,22 +1462,6 @@ class TellyscopeViewModel(
return null
}
- /** Empties the focused text box on the TV. */
- fun clearText() {
- val id = _state.value.selectedId ?: return
- viewModelScope.launch {
- keys.withLock {
- _notice.value = try {
- if (source.clearText(id)) null else Copy.CLEAR_REFUSED
- } catch (e: CancellationException) {
- throw e
- } catch (_: Exception) {
- Copy.REMOTE_LOST
- }
- }
- }
- }
-
/** The TV shows its own update screen; Tellyscope can't see what it finds, so it only says where to look. */
fun checkUpdates() {
val id = _state.value.selectedId ?: return
diff --git a/app/src/test/java/app/tellyscope/ClearTextTest.kt b/app/src/test/java/app/tellyscope/ClearTextTest.kt
deleted file mode 100644
index 47e0521..0000000
--- a/app/src/test/java/app/tellyscope/ClearTextTest.kt
+++ /dev/null
@@ -1,86 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-only
-
-package app.tellyscope
-
-import androidx.lifecycle.viewModelScope
-import app.tellyscope.data.Device
-import app.tellyscope.data.DeviceSource
-import app.tellyscope.data.DeviceState
-import app.tellyscope.data.FakeDeviceSource
-import app.tellyscope.data.ScanHit
-import app.tellyscope.data.ScanKind
-import app.tellyscope.data.Snapshot
-import app.tellyscope.ui.Copy
-import app.tellyscope.ui.TellyscopeViewModel
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.cancel
-import kotlinx.coroutines.flow.emptyFlow
-import kotlinx.coroutines.test.StandardTestDispatcher
-import kotlinx.coroutines.test.TestScope
-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.assertNull
-import org.junit.Before
-import org.junit.Test
-import java.io.IOException
-
-/** One TV; [answer] is what clearing its text box does: true, false, or throw for a lost link. */
-private class TextBox : DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {
- var clears = 0
- var answer: () -> Boolean = { true }
-
- override suspend fun known() = listOf(
- Device("tv", ScanHit("tv", 5555, ScanKind.Classic, "tv", null), DeviceState.Online, null, null, null, 0L, nickname = "Projector"),
- )
-
- override fun live(deviceId: String) = emptyFlow<Snapshot>()
-
- override suspend fun clearText(deviceId: String): Boolean {
- clears++
- return answer()
- }
-}
-
-@OptIn(ExperimentalCoroutinesApi::class)
-class ClearTextTest {
- private val dispatcher = StandardTestDispatcher()
- private val test = TestScope(dispatcher)
- private val tv = TextBox()
- private lateinit var vm: TellyscopeViewModel
-
- @Before fun setUp() = Dispatchers.setMain(dispatcher)
-
- @After fun tearDown() {
- if (::vm.isInitialized) vm.viewModelScope.cancel()
- Dispatchers.resetMain()
- }
-
- private fun clear() = with(test) {
- vm = TellyscopeViewModel(tv, clock = { 0L })
- runCurrent()
- vm.clearText()
- runCurrent()
- }
-
- @Test fun aClearedBoxSaysNothing() {
- clear()
- assertEquals(1, tv.clears)
- assertNull(vm.notice.value)
- }
-
- @Test fun aBoxThatDidntClearSaysSo() {
- tv.answer = { false }
- clear()
- assertEquals(Copy.CLEAR_REFUSED, vm.notice.value)
- }
-
- @Test fun aLostLinkSaysTheRemoteLostTheTv() {
- tv.answer = { throw IOException("gone") }
- clear()
- assertEquals(Copy.REMOTE_LOST, vm.notice.value)
- }
-}
diff --git a/app/src/test/java/app/tellyscope/RemoteRepeatTest.kt b/app/src/test/java/app/tellyscope/RemoteRepeatTest.kt
index ebed9b6..477e767 100644
--- a/app/src/test/java/app/tellyscope/RemoteRepeatTest.kt
+++ b/app/src/test/java/app/tellyscope/RemoteRepeatTest.kt
@@ -37,6 +37,18 @@ class RemoteRepeatTest {
assertEquals(1 + 1000 / REPEAT_EVERY_MS.toInt(), presses)
}
+ @Test fun backspaceDeletesOnceOnATap() = runTest {
+ var presses = 0
+ repeatWhileHeld(RemoteKey.DEL, held = { false }) { presses++; true }
+ assertEquals(1, presses)
+ }
+
+ @Test fun heldBackspaceRepeatsUntilReleased() = runTest {
+ var presses = 0
+ repeatWhileHeld(RemoteKey.DEL, held = { testScheduler.currentTime < 400 + 500 }) { presses++; true }
+ assertEquals(1 + 500 / REPEAT_EVERY_MS.toInt(), presses)
+ }
+
@Test fun okNeverRepeats() = runTest {
var presses = 0
repeatWhileHeld(RemoteKey.OK, held = { true }) { presses++; true }