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.

Add Remote buttons for 23 streaming services

jesse-agent-2325eac69e64aa5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 078accf..1ee901f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@ until this file has a section for its version.
## Unreleased
+- **New:** Remote buttons open Netflix, YouTube, Plex and 20 more streaming apps. [#PRNUM](../../pull/PRNUM)
+ - Hold a button, or use ⋮ › Remote buttons, to pick up to three (four on a tablet).
+ - Screen off and Restart TV moved into ⋮ at the top of the Remote.
- **Improved:** On the Remote, tap outside the text box to close the keyboard. [#222](../../pull/222)
- **Improved:** Debloat ticks a whole group of apps in one tap, from its heading. [#219](../../pull/219)
- Debloat no longer lists the TV's own home app, so it can't be turned off there.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index cda382b..4bc1267 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -30,10 +30,11 @@ You don't have to trust ours. Fork tellyscope-devices, edit the lists in your fo
## Bundled lists
-The lists the app ships with live in [`app/src/main/resources/lists/`](app/src/main/resources/lists/). Change one with a pull request, and the change reaches people with the next release. They are never fetched, so a custom debloat list source can't add to them. Each file is JSON on `"schema": 1`, and `LaunchersTest` checks that every entry reads.
+The lists the app ships with live in [`app/src/main/resources/lists/`](app/src/main/resources/lists/). Change one with a pull request, and the change reaches people with the next release. They are never fetched, so a custom debloat list source can't add to them. Each file is JSON on `"schema": 1`, and `LaunchersTest` or `StreamingTest` checks that every entry reads.
- [`launchers.json`](app/src/main/resources/lists/launchers.json) lists the third-party launchers Tellyscope knows. Set `"accessibility": true` only for a launcher that keeps Home with its own accessibility service: Make Home offers to turn that service on, and an accessibility service can read the screen. Check the APK's manifest for a service with `BIND_ACCESSIBILITY_SERVICE`, and put the version you checked in `"checked"`. `LaunchersTest` names every such launcher on purpose, so add yours there too and a reviewer sees it. A launcher with an `"about"` line is offered in **Install a home screen**, in the file's order; keep that line short and plain.
- [`labels.json`](app/src/main/resources/lists/labels.json) holds the names shown for common TV apps when the TV can't tell us (old Android, or a maker that blocks it). Add a package to the right group with the name its own APK shows.
+- [`streaming.json`](app/src/main/resources/lists/streaming.json) lists the streaming services the Remote can have a button for, by group. Each has its `"packages"` (the usual TV app first), a `"color"` as `#RRGGBB` (with `"color2"` for a gradient) and a `"logo"`: a transparent PNG at four times its size in dp, in [`lists/logos/`](app/src/main/resources/lists/logos/), at most 72 × 30 dp. Add `"dark"` only when the colour is under 3:1 against the dark sheet; the pill fills with it in dark mode. `StreamingTest` checks every entry, logo and dark fill. The logos are their owners' trademarks, so add the source of a new one to [NOTICE](NOTICE).
## README screenshots
diff --git a/NOTICE b/NOTICE
index 31a65f2..2677451 100644
--- a/NOTICE
+++ b/NOTICE
@@ -27,8 +27,9 @@ The TV and HDMI (streaming stick) device icons use the path data of the
Apps, Files and Tweaks tabs those of "apps", "folder" and "tune", the
Upload files button that of "upload", the empty Movies folder that of
"movie", the links in Settings that of "open_in_new", and the Remote's
-restart, waiting, can't-reach and dock menu icons those of "restart_alt",
-"hourglass_top", "link_off", "swap_horiz" and "remove_circle_outline".
+restart, waiting and can't-reach icons and the Remote buttons sheet's drag
+handle those of "restart_alt", "hourglass_top", "link_off" and
+"drag_handle".
Report a problem, Help add this TV and Add the rest use those of
"bug_report", "add_to_queue" and "content_copy".
The access warning, Who has access and Remove all other access use those
@@ -78,8 +79,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------------------
-App icons in app/src/test/resources/dock-icons/ (screenshot tests only, not in
+Streaming service logos in app/src/main/resources/lists/logos/
+The names and logos of the services in lists/streaming.json are trademarks of
+their owners. They are not covered by the GNU General Public License: they are
+not part of Tellyscope's source, and no licence to them is given. Tellyscope
+shows them only to name the app a Remote button opens, and isn't affiliated
+with or endorsed by any of their owners. They are drawn from Wikimedia
+Commons, Simple Icons (https://simpleicons.org) and the services' own
+projects.
+
+--------------------------------------------------------------------------------
+App icon in app/src/test/resources/dock-icons/ (screenshot tests only, not in
the app)
-The YouTube, Netflix, Jellyfin and Spotify names and logos belong to their
-owners. They are shown only to illustrate the Remote's dock in the README's
-screenshot.
+The YouTube name and logo belong to its owner. It is shown only to illustrate
+the Apps list in a screenshot.
diff --git a/app/src/main/java/app/tellyscope/data/DockBook.kt b/app/src/main/java/app/tellyscope/data/DockBook.kt
index f2f8821..6ee5ded 100644
--- a/app/src/main/java/app/tellyscope/data/DockBook.kt
+++ b/app/src/main/java/app/tellyscope/data/DockBook.kt
@@ -5,7 +5,7 @@ package app.tellyscope.data
import java.io.File
/**
- * The apps on each TV's Remote dock, in order, keyed like [NameBook] so the dock follows the TV
+ * The services on each TV's Remote buttons, in order, keyed like [NameBook] so the dock follows the TV
* across DHCP changes. `key \t package \t label` per line; null file keeps it in memory (tests,
* the fake source).
*/
@@ -53,33 +53,11 @@ class DockBook(private val file: File? = null) {
}
}
-/** The dock's rules, kept apart from the screen so they can be tested on their own. */
+/** The saved buttons' rules, kept apart from the screen so they can be tested on their own. */
object Dock {
- /** One row of four along the Remote's bottom edge; the Add tile goes once it's full. */
+ /** The most buttons the Remote shows, on a screen 600 dp or wider; a phone shows three of them. */
const val MAX = 4
- /**
- * The apps the picker offers: ones a launcher can open, already-docked ones included (shown as Added).
- * A built-in app with only a phone-style icon (Camera, WebView, a maker's updater) is left out; one
- * the user installed stays, whatever kind of icon it has.
- */
- fun choices(apps: List<AppInfo>): List<AppInfo> = apps.filter { it.launchable && it.enabled && (it.tvHome || !it.system) }
-
- fun add(dock: List<Docked>, app: AppInfo): List<Docked> =
- if (dock.size >= MAX || dock.any { it.packageName == app.packageName }) dock else dock + Docked(app.packageName, app.label)
-
- /** Puts [app] in [old]'s place; an app already elsewhere on the dock moves here instead. */
- fun replace(dock: List<Docked>, old: String, app: AppInfo): List<Docked> =
- dock.mapNotNull {
- when (it.packageName) {
- old -> Docked(app.packageName, app.label)
- app.packageName -> null
- else -> it
- }
- }
-
- fun remove(dock: List<Docked>, pkg: String): List<Docked> = dock.filterNot { it.packageName == pkg }
-
fun move(dock: List<Docked>, from: Int, to: Int): List<Docked> {
if (from !in dock.indices || to !in dock.indices || from == to) return dock
return dock.toMutableList().apply { add(to, removeAt(from)) }
diff --git a/app/src/main/java/app/tellyscope/data/Launchers.kt b/app/src/main/java/app/tellyscope/data/Launchers.kt
index 1887289..a4d14d3 100644
--- a/app/src/main/java/app/tellyscope/data/Launchers.kt
+++ b/app/src/main/java/app/tellyscope/data/Launchers.kt
@@ -66,6 +66,11 @@ fun parseLabels(text: String): Map<String, String> = try {
object BundledLists {
val launchers: List<KnownLauncher> by lazy { parseLaunchers(read("launchers.json")) }
val labels: Map<String, String> by lazy { parseLabels(read("labels.json")) }
+ val streaming: List<StreamingService> by lazy { parseStreaming(read("streaming.json")) }
+
+ /** A service's logo, a PNG at four times its size in dp; null if it isn't bundled. */
+ fun logo(name: String): ByteArray? =
+ BundledLists::class.java.getResourceAsStream("/lists/logos/$name.png")?.use { it.readBytes() }
private fun read(name: String): String =
checkNotNull(BundledLists::class.java.getResourceAsStream("/lists/$name")) { "lists/$name isn't bundled" }
diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.kt
index e28feb6..b5e0143 100644
--- a/app/src/main/java/app/tellyscope/data/Model.kt
+++ b/app/src/main/java/app/tellyscope/data/Model.kt
@@ -157,7 +157,7 @@ data class AppInfo(
/** Where an install from the Play Store stands, read every few seconds while the TV shows the Store. */
enum class StoreState { Installed, InStore, Elsewhere }
-/** An app on the Remote's dock. [label] is kept so it can be named after the app is gone. */
+/** The app a Remote button opens. [label] is kept so it can be named after the app is gone. */
data class Docked(val packageName: String, val label: String)
data class Socket(val app: String, val remote: String, val state: String)
diff --git a/app/src/main/java/app/tellyscope/data/Streaming.kt b/app/src/main/java/app/tellyscope/data/Streaming.kt
new file mode 100644
index 0000000..684b4d4
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/data/Streaming.kt
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.data
+
+import org.json.JSONObject
+
+/**
+ * A streaming service the Remote can have a button for, from the bundled `lists/streaming.json`.
+ * [packages] are its TV apps, the usual one first; a button opens the first one the TV has.
+ * [color] is the pill's brand colour in both themes, a gradient towards [color2] when there is one.
+ * [logo] names `lists/logos/<logo>.png`. [dark] fills the pill instead in dark mode, for a brand
+ * colour that would sink into the sheet; the logo turns white or black on it.
+ */
+data class StreamingService(
+ val name: String,
+ val packages: List<String>,
+ val color: Long,
+ val color2: Long? = null,
+ val logo: String,
+ val dark: Long? = null,
+ val group: String = "",
+) {
+ /** The app to open on a TV with [installed] packages: the first of ours it has, else the usual one. */
+ fun packageOn(installed: Collection<String>): String = packages.firstOrNull { it in installed } ?: packages.first()
+}
+
+private val HEX = Regex("#[0-9A-Fa-f]{6}")
+private val LOGO = Regex("[a-z0-9]+")
+
+private fun JSONObject.colorOrNull(k: String): Long? =
+ optStringOrNull(k)?.takeIf { HEX.matches(it) }?.let { 0xFF000000 or it.substring(1).toLong(16) }
+
+/**
+ * Empty unless it is schema 1. A service without a name, a package, a `#RRGGBB` colour or a logo
+ * name is dropped, and so are packages that aren't package names.
+ */
+fun parseStreaming(text: String): List<StreamingService> = try {
+ val o = JSONObject(text)
+ if (o.optInt("schema") != 1) emptyList() else o.getJSONArray("groups").objectsOrSkip { it }.flatMap { g ->
+ val group = g.getString("name")
+ g.getJSONArray("services").objectsOrSkip { s ->
+ val pkgs = s.optJSONArray("packages")?.let { a -> (0 until a.length()).map { a.optString(it) } }.orEmpty().filter { PACKAGE.matches(it) }
+ StreamingService(
+ name = s.getString("name"),
+ packages = pkgs,
+ color = s.colorOrNull("color") ?: return@objectsOrSkip null,
+ color2 = s.colorOrNull("color2"),
+ logo = s.getString("logo").takeIf { LOGO.matches(it) } ?: return@objectsOrSkip null,
+ dark = s.colorOrNull("dark"),
+ group = group,
+ ).takeIf { it.name.isNotBlank() && it.packages.isNotEmpty() }
+ }
+ }
+} catch (_: org.json.JSONException) {
+ emptyList()
+}
+
+/** The Remote's row of streaming buttons, kept apart from the screen so it can be tested on its own. */
+object RemoteButtons {
+ /**
+ * Alpha: every service can be picked, installed or not, and a button stays when its app isn't on
+ * the TV, so the whole list can be tried on one TV. False: the picker lists only what the TV has.
+ */
+ const val ANY_SERVICE = true
+
+ /** Three buttons fit a phone; 600 dp and wider, a foldable or tablet, fits four. */
+ fun cap(widthDp: Int): Int = if (widthDp >= 600) Dock.MAX else 3
+
+ /** The service a dock entry stands for, by any of its packages. */
+ fun serviceOf(entry: Docked, services: List<StreamingService>): StreamingService? =
+ services.firstOrNull { entry.packageName in it.packages }
+
+ /** The buttons to show, in order: only dock entries that are a known service, at most [cap]. */
+ fun shown(dock: List<Docked>, services: List<StreamingService>, cap: Int): List<StreamingService> =
+ dock.mapNotNull { serviceOf(it, services) }.distinct().take(cap)
+
+ /** What the picker offers, in the file's order. */
+ fun choices(services: List<StreamingService>, apps: List<AppInfo>): List<StreamingService> {
+ if (ANY_SERVICE) return services
+ val installed = apps.mapTo(HashSet()) { it.packageName }
+ return services.filter { s -> s.packages.any { it in installed } }
+ }
+
+ /** Ticks or unticks [service]; a tick past [cap] does nothing. */
+ fun toggle(dock: List<Docked>, service: StreamingService, services: List<StreamingService>, cap: Int, apps: List<AppInfo>): List<Docked> {
+ val mine = dock.filter { serviceOf(it, services) != null }
+ if (mine.any { it.packageName in service.packages }) return mine.filterNot { it.packageName in service.packages }
+ if (mine.size >= cap) return mine
+ return mine + Docked(service.packageOn(apps.map { it.packageName }), service.name)
+ }
+
+ /**
+ * How a pill is drawn on a sheet of colour [sheet]: [fill] (to [fill2]), an [outline], and [ink]
+ * for the logo, or null to draw it in its own colours.
+ */
+ data class Look(val fill: Long, val fill2: Long?, val outline: Boolean, val ink: Long?)
+
+ /**
+ * A brand colour under 3:1 against the sheet (the weaker end of a gradient) would sink into it.
+ * In light mode it gets an outline; in dark mode it takes its [StreamingService.dark] fill,
+ * with a white logo where white reads at 4.5:1 and black otherwise. A white-only logo on black
+ * has no dark fill and stands on its own.
+ */
+ fun look(s: StreamingService, sheet: Long, dark: Boolean): Look {
+ val plain = Look(s.color, s.color2, outline = false, ink = null)
+ val weakest = listOfNotNull(s.color, s.color2).minOf { contrast(it, sheet) }
+ if (weakest >= 3.0) return plain
+ if (!dark) return plain.copy(outline = true)
+ val fill = s.dark ?: return plain
+ return Look(fill, null, outline = false, ink = if (contrast(WHITE, fill) >= 4.5) WHITE else BLACK)
+ }
+
+ const val WHITE = 0xFFFFFFFF
+ const val BLACK = 0xFF000000
+
+ /** WCAG contrast between two opaque colours. */
+ fun contrast(a: Long, b: Long): Double {
+ val (x, y) = luminance(a) to luminance(b)
+ return (maxOf(x, y) + 0.05) / (minOf(x, y) + 0.05)
+ }
+
+ private fun luminance(argb: Long): Double {
+ fun ch(shift: Int): Double {
+ val c = ((argb shr shift) and 0xFFL) / 255.0
+ return if (c <= 0.04045) c / 12.92 else Math.pow((c + 0.055) / 1.055, 2.4)
+ }
+ return 0.2126 * ch(16) + 0.7152 * ch(8) + 0.0722 * ch(0)
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 677e39f..15e78ff 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -518,25 +518,18 @@ object Copy {
fun restartLost(name: String) = "Still can't reach $name"
fun backOnline(name: String) = "Back online. $name reconnected."
- // Dock
-
- const val ADD_TO_DOCK = "Add to dock"
- const val DOCK_EMPTY = "Dock up to four TV apps, one tap to open."
- const val DOCK_PICK_TITLE = "Add an app to the dock"
- const val DOCK_PICK_HINT = "Tap an app to add it."
- const val DOCK_ADDED = "Added"
- const val DOCK_NO_APPS = "Still reading the TV's apps. Open this again in a moment."
- const val DOCK_CHANGE = "Change app"
- const val DOCK_REMOVE = "Remove from dock"
- const val DOCK_REORDER = "Keep holding and move to reorder"
-
- fun dockPickFrom(name: String) = "Apps installed on $name"
- fun dockSwap(label: String) = "Put another app in $label's place"
+ // Remote buttons
+
+ const val REMOTE_BUTTONS = "Remote buttons"
+ const val MORE = "More options"
+
+ fun buttonsHint(cap: Int) = "Pick up to $cap. Drag to set the order. To pick another, untick one first."
+ fun notOnTv(name: String) = "$name isn't on this TV. Install it from the Play Store on the TV."
fun cantOpen(label: String) = "The TV couldn't open $label. If it's turned off, turn it on in Apps."
fun leftDock(labels: List<String>) =
- if (labels.size == 1) "${labels[0]} was uninstalled, so it left the dock."
- else "${labels.size} apps were uninstalled, so they left the dock."
+ if (labels.size == 1) "${labels[0]} was uninstalled, so its button left the Remote."
+ else "${labels.size} apps were uninstalled, so their buttons left the Remote."
fun restarting(minutes: Long) =
if (minutes < 3) "Tellyscope reconnects on its own when the TV is back, usually within a couple of minutes."
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
index da7c4e8..d0d8689 100644
--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
@@ -2,12 +2,10 @@
package app.tellyscope.ui
-import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
-import androidx.compose.foundation.gestures.drag
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -28,8 +26,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.isImeVisible
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
@@ -56,8 +52,6 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
-import androidx.compose.material3.ListItem
-import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LoadingIndicator
import androidx.compose.material3.MaterialShapes
import androidx.compose.material3.MaterialTheme
@@ -84,7 +78,6 @@ import androidx.compose.runtime.mutableFloatStateOf
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
import androidx.compose.runtime.staticCompositionLocalOf
@@ -92,21 +85,15 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
-import androidx.compose.ui.draw.shadow
-import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
-import androidx.compose.ui.graphics.graphicsLayer
-import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.PathParser
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.pointer.PointerEventPass
-import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
-import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInWindow
@@ -118,7 +105,6 @@ import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.onClick
-import androidx.compose.ui.semantics.onLongClick
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.ImeAction
@@ -128,23 +114,39 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.coerceIn
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
-import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.border
+import androidx.compose.foundation.combinedClickable
+import androidx.compose.foundation.gestures.detectDragGestures
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.foundation.selection.toggleable
+import androidx.compose.material.icons.filled.Edit
+import androidx.compose.material.icons.filled.MoreVert
+import androidx.compose.material3.Checkbox
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.ColorFilter
+import androidx.compose.ui.graphics.asImageBitmap
+import androidx.compose.ui.graphics.luminance
+import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.LocalDensity
+import android.graphics.BitmapFactory
+import app.tellyscope.data.BundledLists
+import app.tellyscope.data.RemoteButtons
+import app.tellyscope.data.StreamingService
import app.tellyscope.adb.RemoteKey
import app.tellyscope.data.AppInfo
import app.tellyscope.data.DeviceState
import app.tellyscope.data.Dock
import app.tellyscope.data.Docked
-import kotlin.math.abs
import kotlin.math.roundToInt
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import androidx.compose.foundation.layout.fillMaxHeight
-import androidx.compose.material3.BottomSheetDefaults
-import androidx.compose.material3.FilledIconButton
-import androidx.compose.material3.FilledTonalIconButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
@@ -206,7 +208,7 @@ private const val SHORT_PHONE_DP = 760
/**
* The remote, as a sheet over the TV's page with the ⋮ sheet's header. It never scrolls, which would
* fight the drag that closes it: the D-pad takes the height that's left, so a short phone, large text
- * or the keyboard shrink it instead of pushing the dock off-screen.
+ * or the keyboard shrink it instead of pushing the buttons off-screen.
*/
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Composable
@@ -236,7 +238,7 @@ fun RemoteScreen(
}
// Set once the D-pad hits its floor, and cleared once there's room for the hint again.
var tight by remember { mutableStateOf(false) }
- // While typing, the keyboard needs the room: volume, the hint and the dock step aside for the D-pad.
+ // While typing, the keyboard needs the room: volume, the hint and the buttons step aside for the D-pad.
val typing = WindowInsets.isImeVisible
val focus = LocalFocusManager.current
// The text box in window coordinates, so a tap on it (or its ⌫ and Send) keeps the keyboard up.
@@ -244,11 +246,13 @@ fun RemoteScreen(
var origin by remember { mutableStateOf(Offset.Zero) }
val rowGap = if (tight || typing) 12.dp else 20.dp
val short = LocalConfiguration.current.screenHeightDp < SHORT_PHONE_DP
+ val cap = RemoteButtons.cap(LocalConfiguration.current.screenWidthDp)
+ var editing by rememberSaveable { mutableStateOf(false) }
+ if (editing) ButtonsSheet(state.device.dock, state.device.apps, cap, actions.setDock, onDismiss = { editing = false })
ModalBottomSheet(
onDismissRequest = actions.back,
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
- dragHandle = { HandleRow(screenControl, screenOff, live, showTip = state.screenOffTip, actions, onRestart = { confirmReboot = true }) },
) {
// A tap anywhere else puts the keyboard away once the finger lifts, so nothing moves under a
// press; the key that was tapped still does its job. Watched on the way down, never consumed.
@@ -269,7 +273,9 @@ fun RemoteScreen(
Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
- RemoteHeader(state, device, restart, screenOff, onRestartTap = { hidden = null })
+ RemoteHeader(state, device, restart, screenOff, onRestartTap = { hidden = null }) {
+ HeaderMenu(screenControl, screenOff, live, showTip = state.screenOffTip, actions, onRestart = { confirmReboot = true }, onButtons = { editing = true })
+ }
CompositionLocalProvider(LocalKeyHaptics provides state.keyHaptics) { Column(
Modifier.weight(1f).alpha(if (live) 1f else 0.38f),
horizontalAlignment = Alignment.CenterHorizontally,
@@ -333,7 +339,7 @@ fun RemoteScreen(
if (!typing) {
Spacer(Modifier.height(if (tight) 8.dp else 16.dp))
CompositionLocalProvider(LocalKeyHaptics provides state.keyHaptics) {
- DockBand(state.device.dock, state.device.apps, name(device), live, actions)
+ ButtonsRow(RemoteButtons.shown(state.device.dock, BundledLists.streaming, cap), state.device.apps, live, actions, onEdit = { editing = true })
}
}
}
@@ -342,14 +348,17 @@ fun RemoteScreen(
}
}
-/** The ⋮ sheet's header: the TV, and a second line for its state, a screen that's off or a restart. */
+/**
+ * The ⋮ sheet's header: the TV, and a second line for its state, a screen that's off or a restart.
+ * [menu] sits at its end, centred on the name and its line.
+ */
@Composable
-private fun RemoteHeader(state: UiState, device: Device, restart: Restart?, screenOff: Boolean, onRestartTap: () -> Unit) {
+private fun RemoteHeader(state: UiState, device: Device, restart: Restart?, screenOff: Boolean, onRestartTap: () -> Unit, menu: @Composable () -> Unit) {
val c = MaterialTheme.colorScheme
Row(Modifier.fillMaxWidth().padding(start = 4.dp, bottom = 4.dp), verticalAlignment = Alignment.CenterVertically) {
Cookie(device, 48.dp)
Spacer(Modifier.width(16.dp))
- Column {
+ Column(Modifier.weight(1f)) {
Text(name(device), style = MaterialTheme.typography.titleLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)
when {
restart != null -> RestartStatus(late = restart.phase(state.clock()) != Restart.Phase.Waiting, onClick = onRestartTap)
@@ -362,6 +371,8 @@ private fun RemoteHeader(state: UiState, device: Device, restart: Restart?, scre
}
}
}
+ // Out by the button's own padding, so the glyph's edge lines up with the keys and buttons below.
+ Box(Modifier.offset(x = 12.dp)) { menu() }
}
}
@@ -422,7 +433,7 @@ private fun RoundKey(
icon: @Composable () -> Unit,
) = KeySurface(key, label, enabled, press, CircleShape, MaterialTheme.colorScheme.secondaryContainer, modifier.size(size), icon)
-/** Off in Settings, a key press or a dock tap doesn't vibrate. */
+/** Off in Settings, a key press or a button tap doesn't vibrate. */
private val LocalKeyHaptics = staticCompositionLocalOf { true }
/**
@@ -598,12 +609,13 @@ private fun StatusShape(icon: ImageVector, container: Color, content: Color) {
}
/**
- * The sheet's drag handle, with Screen off (or on again) and Restart beside it, so the TV's name
- * keeps the header's full width. Explains Screen off on the first visit.
+ * The header's ⋮: Screen off (or on again), Restart TV, then Remote buttons. It drops below the ⋮,
+ * so the TV's name stays readable. Explains Screen off on the first visit.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-private fun HandleRow(screenControl: Boolean, off: Boolean, live: Boolean, showTip: Boolean, actions: RemoteActions, onRestart: () -> Unit) {
+private fun HeaderMenu(screenControl: Boolean, off: Boolean, live: Boolean, showTip: Boolean, actions: RemoteActions, onRestart: () -> Unit, onButtons: () -> Unit) {
+ var open by remember { mutableStateOf(false) }
val tip = rememberTooltipState(isPersistent = true)
LaunchedEffect(showTip, screenControl) {
if (showTip && screenControl) {
@@ -611,27 +623,50 @@ private fun HandleRow(screenControl: Boolean, off: Boolean, live: Boolean, showT
actions.screenOffTipSeen()
}
}
- Box(Modifier.fillMaxWidth().padding(end = 12.dp)) {
- BottomSheetDefaults.DragHandle(Modifier.align(Alignment.Center))
- Row(Modifier.align(Alignment.CenterEnd).padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- if (screenControl) TooltipBox(
- positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Below),
- tooltip = {
- PlainTooltip {
- Column(Modifier.padding(vertical = 4.dp)) {
- Text(Copy.SCREEN_OFF, style = MaterialTheme.typography.labelLarge)
- Text(Copy.SCREEN_OFF_TIP)
- }
+ Box {
+ TooltipBox(
+ positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Below),
+ tooltip = {
+ PlainTooltip {
+ Column(Modifier.padding(vertical = 4.dp)) {
+ Text(Copy.SCREEN_OFF, style = MaterialTheme.typography.labelLarge)
+ Text(Copy.SCREEN_OFF_TIP)
}
- },
- state = tip,
- enableUserInput = false,
- ) {
- // Filled while the picture is off: the one thing to press to get it back.
- if (off) FilledIconButton(onClick = { actions.screenOff(false) }, enabled = live) { Icon(RemoteIcons.Tv, contentDescription = Copy.SCREEN_ON) }
- else FilledTonalIconButton(onClick = { actions.screenOff(true) }, enabled = live) { Icon(RemoteIcons.TvOff, contentDescription = Copy.SCREEN_OFF) }
+ }
+ },
+ state = tip,
+ enableUserInput = false,
+ ) {
+ IconButton(onClick = { open = true }) { Icon(Icons.Default.MoreVert, contentDescription = Copy.MORE) }
+ }
+ DropdownMenu(open, onDismissRequest = { open = false }, shape = MaterialTheme.shapes.large) {
+ if (screenControl) {
+ // While the picture is off, the item turns it back on.
+ if (off) DropdownMenuItem(
+ text = { Text(Copy.SCREEN_ON) },
+ leadingIcon = { Icon(RemoteIcons.Tv, null) },
+ enabled = live,
+ onClick = { open = false; actions.screenOff(false) },
+ )
+ else DropdownMenuItem(
+ text = { Text(Copy.SCREEN_OFF) },
+ leadingIcon = { Icon(RemoteIcons.TvOff, null) },
+ enabled = live,
+ onClick = { open = false; actions.screenOff(true) },
+ )
}
- FilledTonalIconButton(onClick = onRestart, enabled = live) { Icon(RemoteIcons.RestartAlt, contentDescription = Copy.REMOTE_RESTART) }
+ DropdownMenuItem(
+ text = { Text(Copy.REMOTE_RESTART) },
+ leadingIcon = { Icon(RemoteIcons.RestartAlt, null) },
+ enabled = live,
+ onClick = { open = false; onRestart() },
+ )
+ HorizontalDivider(Modifier.padding(vertical = 4.dp))
+ DropdownMenuItem(
+ text = { Text(Copy.REMOTE_BUTTONS) },
+ leadingIcon = { Icon(Icons.Default.Edit, null) },
+ onClick = { open = false; onButtons() },
+ )
}
}
}
@@ -656,246 +691,196 @@ private fun RestartStatus(late: Boolean, onClick: () -> Unit) {
}
/**
- * The strip under the keys: up to [Dock.MAX] apps, each centred in an equal share of it so a tap
- * can't land on the wrong one, with an Add tile in the next free slot. A tap opens the app on the TV; a long press opens its menu, and moving while still
- * holding drags it to another slot.
+ * The row under the keys: up to [cap] streaming buttons, sharing it equally, or one pill to pick some.
+ * A tap opens the service on the TV; holding one opens the picker, as ⋮ › Remote buttons does.
*/
@Composable
-private fun DockBand(dock: List<Docked>, apps: List<AppInfo>, tvName: String, enabled: Boolean, actions: RemoteActions) {
- // Null: closed. Empty: adding. A package: swapping that app for another.
- var picking by rememberSaveable { mutableStateOf<String?>(null) }
- picking?.let { swap ->
- DockPicker(
- dock, apps, tvName, swapping = dock.firstOrNull { it.packageName == swap },
- onPick = { app ->
- picking = null
- actions.setDock(if (swap.isEmpty()) Dock.add(dock, app) else Dock.replace(dock, swap, app))
- },
- onDismiss = { picking = null },
- )
- }
- Surface(color = MaterialTheme.colorScheme.surfaceContainerHigh, shape = MaterialTheme.shapes.extraLarge) {
- Box(Modifier.padding(horizontal = 4.dp, vertical = 8.dp).alpha(if (enabled) 1f else 0.38f)) {
- DockRow(dock, apps, enabled, actions, onAdd = { picking = "" }, onSwap = { picking = it.packageName })
- }
- }
-}
-
-@Composable
-private fun DockRow(dock: List<Docked>, apps: List<AppInfo>, enabled: Boolean, actions: RemoteActions, onAdd: () -> Unit, onSwap: (Docked) -> Unit) {
- var menu by remember { mutableStateOf<String?>(null) }
- // The app being dragged, and how far; the others make room for it as it goes.
- var lifted by remember { mutableStateOf<String?>(null) }
- var dragX by remember { mutableFloatStateOf(0f) }
- BoxWithConstraints(Modifier.fillMaxWidth().height(48.dp)) {
- val slot = constraints.maxWidth / Dock.MAX.toFloat()
- fun from() = dock.indexOfFirst { it.packageName == lifted }
- fun to() = (from() + (dragX / slot).roundToInt()).coerceIn(0, dock.lastIndex)
- val order = if (from() < 0) dock else Dock.move(dock, from(), to())
- if (dock.size < Dock.MAX) {
- AddTile(enabled, onAdd, Modifier.width(maxWidth / Dock.MAX).offset { IntOffset((dock.size * slot).roundToInt(), 0) })
- }
- if (dock.isEmpty()) Text(
- Copy.DOCK_EMPTY,
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.align(Alignment.CenterStart).padding(start = maxWidth / Dock.MAX, end = 8.dp),
- )
- dock.forEachIndexed { i, app -> key(app.packageName) {
- val up = app.packageName == lifted
- val x by animateFloatAsState(order.indexOf(app) * slot, label = "dock slot")
- val info = apps.firstOrNull { it.packageName == app.packageName }
- ?: AppInfo(app.packageName, app.label, null, false, true, null, "")
- Box(
- Modifier
- .width(maxWidth / Dock.MAX)
- .offset { IntOffset((if (up) i * slot + dragX else x).roundToInt(), 0) }
- .zIndex(if (up) 1f else 0f),
- ) {
- val moves = listOfNotNull(
- CustomAccessibilityAction("Move left") { actions.setDock(Dock.move(dock, i, i - 1)); true }.takeIf { i > 0 },
- CustomAccessibilityAction("Move right") { actions.setDock(Dock.move(dock, i, i + 1)); true }.takeIf { i < dock.lastIndex },
- )
- DockTile(
- info, up, enabled, moves,
- onOpen = { actions.launch(app) },
- onHold = { menu = app.packageName; lifted = app.packageName; dragX = 0f },
- onDrag = { dx ->
- dragX = dx
- // A real move means reordering, so the menu gets out of the way.
- if (abs(dx) > slot / 4) menu = null
- },
- onDrop = {
- if (from() >= 0 && to() != from()) actions.setDock(Dock.move(dock, from(), to()))
- lifted = null
- dragX = 0f
- },
- onMenu = { menu = app.packageName },
- )
- DropdownMenu(menu == app.packageName, onDismissRequest = { menu = null }, shape = MaterialTheme.shapes.large) {
- Row(Modifier.padding(start = 12.dp, end = 16.dp, top = 4.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
- AppIcon(info, Modifier.size(32.dp))
- Spacer(Modifier.width(12.dp))
- Text(app.label, style = MaterialTheme.typography.titleSmall)
- }
- MenuBlock {
- DropdownMenuItem(
- text = { Text(Copy.DOCK_CHANGE) },
- leadingIcon = { Icon(RemoteIcons.SwapHoriz, null) },
- onClick = { menu = null; onSwap(app) },
- )
- DropdownMenuItem(
- text = { Text(Copy.DOCK_REMOVE, color = MaterialTheme.colorScheme.error) },
- leadingIcon = { Icon(RemoteIcons.RemoveCircle, null, tint = MaterialTheme.colorScheme.error) },
- onClick = { menu = null; actions.setDock(Dock.remove(dock, app.packageName)) },
- )
- }
- Text(
- Copy.DOCK_REORDER,
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 4.dp),
- )
- }
+private fun ButtonsRow(buttons: List<StreamingService>, apps: List<AppInfo>, enabled: Boolean, actions: RemoteActions, onEdit: () -> Unit) {
+ val installed = remember(apps) { apps.mapTo(HashSet()) { it.packageName } }
+ Row(Modifier.fillMaxWidth().height(48.dp).alpha(if (enabled) 1f else 0.38f), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ if (buttons.isEmpty()) AddButtons(enabled, onEdit, Modifier.weight(1f))
+ buttons.forEach { s ->
+ key(s.name) {
+ ServiceButton(s, enabled, onOpen = { actions.launch(Docked(s.packageOn(installed), s.name)) }, onHold = onEdit, Modifier.weight(1f))
}
- } }
+ }
}
}
-/** One docked app: its icon, centred in the whole slot it answers to, lifted a size up while held. Its name is for TalkBack and the menu. */
+/** One streaming button: its pill, 40 dp tall in a 48 dp tall target. Its name is for TalkBack. */
@Composable
-private fun DockTile(
- app: AppInfo,
- lifted: Boolean,
- enabled: Boolean,
- /** Reordering for a screen reader, which can't drag. */
- moves: List<CustomAccessibilityAction>,
- onOpen: () -> Unit,
- onHold: () -> Unit,
- onDrag: (Float) -> Unit,
- onDrop: () -> Unit,
- onMenu: () -> Unit,
-) {
+private fun ServiceButton(s: StreamingService, enabled: Boolean, onOpen: () -> Unit, onHold: () -> Unit, modifier: Modifier = Modifier) {
val haptic = LocalHapticFeedback.current
val haptics = LocalKeyHaptics.current
- val scale by animateFloatAsState(if (lifted) 1.1f else 1f, label = "dock lift")
- // The gesture outlives a recomposition; it must call the newest handlers, which see the newest dock.
- val open by rememberUpdatedState(onOpen)
- val hold by rememberUpdatedState(onHold)
- val move by rememberUpdatedState(onDrag)
- val drop by rememberUpdatedState(onDrop)
Box(
- Modifier
- .fillMaxSize()
- .graphicsLayer { scaleX = scale; scaleY = scale }
- .semantics {
- role = Role.Button
- contentDescription = app.label
- if (enabled) {
- onClick("Open on the TV") { onOpen(); true }
- onLongClick("Change or remove") { onMenu(); true }
- customActions = moves
- }
- }
- .pointerInput(enabled, haptics) {
- if (!enabled) return@pointerInput
- awaitEachGesture {
- val down = awaitFirstDown()
- // Up before the long-press time is a tap; still down after it is a hold.
- var up: PointerInputChange? = null
- val held = withTimeoutOrNull(viewConfiguration.longPressTimeoutMillis) { up = waitForUpOrCancellation(); false } ?: true
- if (!held) {
- up?.let {
- it.consume()
- if (haptics) haptic.performHapticFeedback(HapticFeedbackType.VirtualKey)
- open()
- }
- return@awaitEachGesture
- }
- haptic.performHapticFeedback(HapticFeedbackType.LongPress)
- hold()
- var dx = 0f
- drag(down.id) { change ->
- dx += change.positionChange().x
- change.consume()
- move(dx)
- }
- drop()
- }
- },
+ modifier
+ .fillMaxHeight()
+ .combinedClickable(
+ enabled = enabled,
+ role = Role.Button,
+ onClickLabel = Copy.OPEN_ON_TV,
+ onLongClickLabel = Copy.REMOTE_BUTTONS,
+ onLongClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress); onHold() },
+ onClick = { if (haptics) haptic.performHapticFeedback(HapticFeedbackType.VirtualKey); onOpen() },
+ )
+ .semantics { contentDescription = s.name },
contentAlignment = Alignment.Center,
) {
- Box(Modifier.shadow(if (lifted) 6.dp else 0.dp, MaterialTheme.shapes.medium)) { AppIcon(app, word = true) }
+ ServicePill(s, Modifier.fillMaxWidth().height(40.dp))
}
}
-/** The next free slot: a dashed outline the size of an app icon, centred in the whole slot. */
+/** Nothing picked yet: an outlined pill the size of a button, the way into the picker. */
@Composable
-private fun AddTile(enabled: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) {
- val outline = MaterialTheme.colorScheme.outline
- val shape = MaterialTheme.shapes.medium
+private fun AddButtons(enabled: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) {
+ val c = MaterialTheme.colorScheme
+ Surface(
+ onClick = onClick,
+ enabled = enabled,
+ shape = CircleShape,
+ color = Color.Transparent,
+ border = BorderStroke(1.dp, c.outline),
+ modifier = modifier.fillMaxHeight(),
+ ) {
+ Row(horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
+ Icon(Icons.Default.Add, contentDescription = null, tint = c.primary, modifier = Modifier.size(20.dp))
+ Spacer(Modifier.width(8.dp))
+ Text(Copy.REMOTE_BUTTONS, style = MaterialTheme.typography.labelLarge, color = c.onSurfaceVariant)
+ }
+ }
+}
+
+/**
+ * A service's brand pill, the same colour in both themes like a button on a real remote, drawn by
+ * [RemoteButtons.look] against the sheet behind it.
+ */
+@Composable
+private fun ServicePill(s: StreamingService, modifier: Modifier = Modifier) {
+ val c = MaterialTheme.colorScheme
+ val dark = c.surface.luminance() < 0.5f
+ val look = RemoteButtons.look(s, c.surfaceContainerLow.toArgb().toLong() and 0xFFFFFFFF, dark)
+ val logo = remember(s.logo) { BundledLists.logo(s.logo)?.let { BitmapFactory.decodeByteArray(it, 0, it.size) }?.asImageBitmap() }
+ val fill = look.fill2?.let { Brush.linearGradient(listOf(Color(look.fill), Color(it))) } ?: SolidColor(Color(look.fill))
Box(
modifier
- .fillMaxHeight()
- .clickable(enabled = enabled, onClickLabel = Copy.ADD_TO_DOCK, role = Role.Button, onClick = onClick)
- .semantics(mergeDescendants = true) { contentDescription = Copy.ADD_TO_DOCK },
+ .clip(CircleShape)
+ .background(fill)
+ .then(if (look.outline) Modifier.border(1.dp, c.outline, CircleShape) else Modifier),
contentAlignment = Alignment.Center,
) {
- Box(
- Modifier.size(40.dp).drawBehind {
- val corner = shape.topStart.toPx(size, this)
- drawRoundRect(
- outline,
- cornerRadius = CornerRadius(corner),
- style = Stroke(1.dp.toPx(), pathEffect = PathEffect.dashPathEffect(floatArrayOf(4.dp.toPx(), 4.dp.toPx()))),
- )
- },
- contentAlignment = Alignment.Center,
- ) { Icon(Icons.Default.Add, contentDescription = null, tint = MaterialTheme.colorScheme.primary) }
+ if (logo != null) {
+ // Drawn at four times its size in dp.
+ Image(
+ logo, contentDescription = null,
+ modifier = Modifier.size((logo.width / 4f).dp, (logo.height / 4f).dp),
+ colorFilter = look.ink?.let { ColorFilter.tint(Color(it)) },
+ )
+ } else {
+ Text(s.name, style = MaterialTheme.typography.labelLarge, color = Color(look.ink ?: RemoteButtons.WHITE), maxLines = 1)
+ }
}
}
-/** The apps a launcher can open, to add to the dock or to put in [swapping]'s place. Docked ones show as Added. */
+/**
+ * Which services get a button, and in what order: ticked ones first, dragged by their handle to
+ * reorder, then the rest by group. Past [cap] the others wait for one to be unticked.
+ */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-private fun DockPicker(dock: List<Docked>, apps: List<AppInfo>, tvName: String, swapping: Docked?, onPick: (AppInfo) -> Unit, onDismiss: () -> Unit) {
- val choices = Dock.choices(apps)
+private fun ButtonsSheet(dock: List<Docked>, apps: List<AppInfo>, cap: Int, setDock: (List<Docked>) -> Unit, onDismiss: () -> Unit) {
+ val services = BundledLists.streaming
+ val ticked = dock.mapNotNull { RemoteButtons.serviceOf(it, services) }.distinct()
+ val rest = RemoteButtons.choices(services, apps) - ticked.toSet()
+ val toggle = { s: StreamingService -> setDock(RemoteButtons.toggle(dock, s, services, cap, apps)) }
+ // One entry per ticked service, in the same order, so a ticked row's index moves its entry.
+ val mine = dock.filter { RemoteButtons.serviceOf(it, services) != null }.distinctBy { RemoteButtons.serviceOf(it, services) }
+ // The ticked row being dragged, and how far.
+ var lifted by remember { mutableStateOf<String?>(null) }
+ var dragY by remember { mutableFloatStateOf(0f) }
+ val rowPx = with(LocalDensity.current) { SHEET_ROW.toPx() }
ModalBottomSheet(onDismissRequest = onDismiss) {
Column(Modifier.padding(horizontal = 24.dp).padding(bottom = 8.dp)) {
- Text(swapping?.let { Copy.dockSwap(it.label) } ?: Copy.DOCK_PICK_TITLE, style = MaterialTheme.typography.titleLarge)
- Text(Copy.dockPickFrom(tvName), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ Text(Copy.REMOTE_BUTTONS, style = MaterialTheme.typography.titleLarge)
+ Text(Copy.buttonsHint(cap), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
- if (choices.isEmpty()) {
- Text(
- Copy.DOCK_NO_APPS,
- style = MaterialTheme.typography.bodyMedium,
- modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
- )
- return@ModalBottomSheet
- }
- LazyColumn {
- items(choices, key = { it.packageName }) { app ->
- val added = dock.any { it.packageName == app.packageName }
- ListItem(
- headlineContent = { Text(app.label) },
- leadingContent = { AppIcon(app) },
- trailingContent = if (added) ({ Text(Copy.DOCK_ADDED, style = MaterialTheme.typography.labelMedium) }) else null,
- colors = ListItemDefaults.colors(containerColor = Color.Transparent),
- modifier = Modifier.alpha(if (added) 0.38f else 1f).clickable(enabled = !added) { onPick(app) },
- )
+ Column(Modifier.verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) {
+ ticked.forEachIndexed { i, s ->
+ key(s.name) {
+ val up = lifted == s.name
+ val moves = listOfNotNull(
+ CustomAccessibilityAction("Move up") { setDock(Dock.move(mine, i, i - 1)); true }.takeIf { i > 0 },
+ CustomAccessibilityAction("Move down") { setDock(Dock.move(mine, i, i + 1)); true }.takeIf { i < ticked.lastIndex },
+ )
+ ServiceRow(
+ s, checked = true, enabled = true, onToggle = { toggle(s) },
+ modifier = Modifier
+ .offset { IntOffset(0, if (up) dragY.roundToInt() else 0) }
+ .zIndex(if (up) 1f else 0f)
+ .background(if (up) MaterialTheme.colorScheme.surfaceContainerHigh else Color.Transparent)
+ .semantics { customActions = moves },
+ ) {
+ Icon(
+ RemoteIcons.DragHandle, contentDescription = null,
+ modifier = Modifier.size(48.dp).padding(12.dp).pointerInput(s.name, ticked.size) {
+ detectDragGestures(
+ onDragStart = { lifted = s.name; dragY = 0f },
+ onDragEnd = {
+ val to = (i + (dragY / rowPx).roundToInt()).coerceIn(0, ticked.lastIndex)
+ if (to != i) setDock(Dock.move(mine, i, to))
+ lifted = null
+ dragY = 0f
+ },
+ onDragCancel = { lifted = null; dragY = 0f },
+ ) { change, amount -> change.consume(); dragY += amount.y }
+ },
+ )
+ }
+ }
}
- item {
- Text(
- Copy.DOCK_PICK_HINT,
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
- )
+ rest.forEachIndexed { i, s ->
+ if (i == 0 || rest[i - 1].group != s.group) {
+ Text(
+ s.group,
+ style = MaterialTheme.typography.labelLarge,
+ color = MaterialTheme.colorScheme.primary,
+ modifier = Modifier.padding(start = 24.dp, end = 24.dp, top = 16.dp, bottom = 4.dp),
+ )
+ }
+ key(s.name) { ServiceRow(s, checked = false, enabled = ticked.size < cap, onToggle = { toggle(s) }) }
}
}
}
}
+private val SHEET_ROW = 56.dp
+
+/** A row of the picker: its tick, its pill and its name, and [trailing] for a ticked one's drag handle. */
+@Composable
+private fun ServiceRow(
+ s: StreamingService,
+ checked: Boolean,
+ enabled: Boolean,
+ onToggle: () -> Unit,
+ modifier: Modifier = Modifier,
+ trailing: @Composable () -> Unit = {},
+) {
+ Row(
+ modifier
+ .fillMaxWidth()
+ .height(SHEET_ROW)
+ .toggleable(checked, enabled = enabled, role = Role.Checkbox, onValueChange = { onToggle() })
+ .alpha(if (enabled) 1f else 0.38f)
+ .padding(start = 12.dp, end = 12.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Checkbox(checked, onCheckedChange = null, enabled = enabled, modifier = Modifier.size(48.dp))
+ ServicePill(s, Modifier.width(80.dp).height(40.dp))
+ Spacer(Modifier.width(16.dp))
+ Text(s.name, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
+ trailing()
+ }
+}
+
private object RemoteIcons {
// Absolute commands only: Compose's path parser misplaces a relative move after a close.
val TvOff = icon(
@@ -946,13 +931,7 @@ private object RemoteIcons {
"M4.27 3L3 4.27L7.73 9L3 9L3 15L7 15L12 20L12 13.27L16.25 17.52C15.58 18.04 14.83 18.45 14 18.7L14 20.76C15.38 20.45 16.63 19.81 17.69 18.95" +
"L19.73 21L21 19.73L12 10.73L4.27 3Z M12 4L9.91 6.09L12 8.18L12 4Z",
)
- val SwapHoriz = icon("SwapHoriz", "M6.99 11L3 15L6.99 19L6.99 16L14 16L14 14L6.99 14L6.99 11Z M21 9L17.01 5L17.01 8L10 8L10 10L17.01 10L17.01 13L21 9Z")
- val RemoveCircle = icon(
- "RemoveCircle",
- "M7 11L7 13L17 13L17 11L7 11Z" +
- "M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2Z" +
- "M12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20Z",
- )
+ val DragHandle = icon("DragHandle", "M20 9L4 9L4 11L20 11L20 9Z M4 15L20 15L20 13L4 13L4 15Z")
private fun icon(name: String, path: String) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
.addPath(PathParser().parsePathString(path).toNodes(), pathFillType = PathFillType.NonZero, fill = SolidColor(Color.Black))
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 63aa7d4..a92c3fa 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -36,6 +36,7 @@ import app.tellyscope.data.NetworkInfo
import app.tellyscope.data.NotAnApp
import app.tellyscope.data.PhoneStorage
import app.tellyscope.data.PickedApp
+import app.tellyscope.data.RemoteButtons
import app.tellyscope.data.ResetApp
import app.tellyscope.data.ResetFailure
import app.tellyscope.data.ResetPart
@@ -1814,8 +1815,16 @@ class TellyscopeViewModel(
viewModelScope.launch { source.setDock(id, dock) }
}
- /** A dock tap: opens the app on the TV, without a history entry. */
- fun launch(app: Docked) = open(app.packageName, app.label)
+ /** A Remote button: opens the app on the TV, without a history entry. */
+ fun launch(app: Docked) {
+ // An empty list hasn't been read yet, so the TV gets to try.
+ val apps = _state.value.device.apps
+ if (apps.isNotEmpty() && apps.none { it.packageName == app.packageName }) {
+ _notice.value = Copy.notOnTv(app.label)
+ return
+ }
+ open(app.packageName, app.label)
+ }
private fun open(pkg: String, label: String) {
val id = _state.value.selectedId ?: return
@@ -1832,8 +1841,12 @@ class TellyscopeViewModel(
}
}
- /** An app uninstalled, here or on the TV itself, leaves the dock, and the snackbar says so. */
+ /**
+ * An app uninstalled, here or on the TV itself, takes its button off the Remote, and the snackbar
+ * says so. Not in the alpha, where any service can have a button.
+ */
private suspend fun pruneDock(id: String, apps: List<AppInfo>) {
+ if (RemoteButtons.ANY_SERVICE) return
val (kept, gone) = Dock.prune(source.dock(id), apps)
if (gone.isEmpty()) return
source.setDock(id, kept)
diff --git a/app/src/main/resources/lists/logos/appletv.png b/app/src/main/resources/lists/logos/appletv.png
new file mode 100644
index 0000000..508ef1f
Binary files /dev/null and b/app/src/main/resources/lists/logos/appletv.png differ
diff --git a/app/src/main/resources/lists/logos/crunchyroll.png b/app/src/main/resources/lists/logos/crunchyroll.png
new file mode 100644
index 0000000..78629d9
Binary files /dev/null and b/app/src/main/resources/lists/logos/crunchyroll.png differ
diff --git a/app/src/main/resources/lists/logos/dazn.png b/app/src/main/resources/lists/logos/dazn.png
new file mode 100644
index 0000000..af2c80e
Binary files /dev/null and b/app/src/main/resources/lists/logos/dazn.png differ
diff --git a/app/src/main/resources/lists/logos/disney.png b/app/src/main/resources/lists/logos/disney.png
new file mode 100644
index 0000000..5c92b5c
Binary files /dev/null and b/app/src/main/resources/lists/logos/disney.png differ
diff --git a/app/src/main/resources/lists/logos/emby.png b/app/src/main/resources/lists/logos/emby.png
new file mode 100644
index 0000000..8b30cd5
Binary files /dev/null and b/app/src/main/resources/lists/logos/emby.png differ
diff --git a/app/src/main/resources/lists/logos/hbomax.png b/app/src/main/resources/lists/logos/hbomax.png
new file mode 100644
index 0000000..e4b034a
Binary files /dev/null and b/app/src/main/resources/lists/logos/hbomax.png differ
diff --git a/app/src/main/resources/lists/logos/hulu.png b/app/src/main/resources/lists/logos/hulu.png
new file mode 100644
index 0000000..455ab69
Binary files /dev/null and b/app/src/main/resources/lists/logos/hulu.png differ
diff --git a/app/src/main/resources/lists/logos/jellyfin.png b/app/src/main/resources/lists/logos/jellyfin.png
new file mode 100644
index 0000000..1087483
Binary files /dev/null and b/app/src/main/resources/lists/logos/jellyfin.png differ
diff --git a/app/src/main/resources/lists/logos/jiohotstar.png b/app/src/main/resources/lists/logos/jiohotstar.png
new file mode 100644
index 0000000..4da42ac
Binary files /dev/null and b/app/src/main/resources/lists/logos/jiohotstar.png differ
diff --git a/app/src/main/resources/lists/logos/kodi.png b/app/src/main/resources/lists/logos/kodi.png
new file mode 100644
index 0000000..67ee077
Binary files /dev/null and b/app/src/main/resources/lists/logos/kodi.png differ
diff --git a/app/src/main/resources/lists/logos/netflix.png b/app/src/main/resources/lists/logos/netflix.png
new file mode 100644
index 0000000..3f5e710
Binary files /dev/null and b/app/src/main/resources/lists/logos/netflix.png differ
diff --git a/app/src/main/resources/lists/logos/paramount.png b/app/src/main/resources/lists/logos/paramount.png
new file mode 100644
index 0000000..6512788
Binary files /dev/null and b/app/src/main/resources/lists/logos/paramount.png differ
diff --git a/app/src/main/resources/lists/logos/peacock.png b/app/src/main/resources/lists/logos/peacock.png
new file mode 100644
index 0000000..7e67b44
Binary files /dev/null and b/app/src/main/resources/lists/logos/peacock.png differ
diff --git a/app/src/main/resources/lists/logos/plex.png b/app/src/main/resources/lists/logos/plex.png
new file mode 100644
index 0000000..ead390f
Binary files /dev/null and b/app/src/main/resources/lists/logos/plex.png differ
diff --git a/app/src/main/resources/lists/logos/plutotv.png b/app/src/main/resources/lists/logos/plutotv.png
new file mode 100644
index 0000000..ae3fe5d
Binary files /dev/null and b/app/src/main/resources/lists/logos/plutotv.png differ
diff --git a/app/src/main/resources/lists/logos/primevideo.png b/app/src/main/resources/lists/logos/primevideo.png
new file mode 100644
index 0000000..3215865
Binary files /dev/null and b/app/src/main/resources/lists/logos/primevideo.png differ
diff --git a/app/src/main/resources/lists/logos/sonyliv.png b/app/src/main/resources/lists/logos/sonyliv.png
new file mode 100644
index 0000000..0f4d057
Binary files /dev/null and b/app/src/main/resources/lists/logos/sonyliv.png differ
diff --git a/app/src/main/resources/lists/logos/spotify.png b/app/src/main/resources/lists/logos/spotify.png
new file mode 100644
index 0000000..e2ee91f
Binary files /dev/null and b/app/src/main/resources/lists/logos/spotify.png differ
diff --git a/app/src/main/resources/lists/logos/tubi.png b/app/src/main/resources/lists/logos/tubi.png
new file mode 100644
index 0000000..29ec74d
Binary files /dev/null and b/app/src/main/resources/lists/logos/tubi.png differ
diff --git a/app/src/main/resources/lists/logos/twitch.png b/app/src/main/resources/lists/logos/twitch.png
new file mode 100644
index 0000000..91fc5da
Binary files /dev/null and b/app/src/main/resources/lists/logos/twitch.png differ
diff --git a/app/src/main/resources/lists/logos/wholphin.png b/app/src/main/resources/lists/logos/wholphin.png
new file mode 100644
index 0000000..6a016cd
Binary files /dev/null and b/app/src/main/resources/lists/logos/wholphin.png differ
diff --git a/app/src/main/resources/lists/logos/youtube.png b/app/src/main/resources/lists/logos/youtube.png
new file mode 100644
index 0000000..b6f6980
Binary files /dev/null and b/app/src/main/resources/lists/logos/youtube.png differ
diff --git a/app/src/main/resources/lists/logos/zee5.png b/app/src/main/resources/lists/logos/zee5.png
new file mode 100644
index 0000000..d37c330
Binary files /dev/null and b/app/src/main/resources/lists/logos/zee5.png differ
diff --git a/app/src/main/resources/lists/streaming.json b/app/src/main/resources/lists/streaming.json
new file mode 100644
index 0000000..f830a3e
--- /dev/null
+++ b/app/src/main/resources/lists/streaming.json
@@ -0,0 +1,53 @@
+{
+ "schema": 1,
+ "groups": [
+ {
+ "name": "Global",
+ "services": [
+ { "name": "Netflix", "packages": ["com.netflix.ninja"], "color": "#000000", "logo": "netflix", "dark": "#E50914" },
+ { "name": "YouTube", "packages": ["com.google.android.youtube.tv"], "color": "#FFFFFF", "logo": "youtube" },
+ { "name": "Prime Video", "packages": ["com.amazon.amazonvideo.livingroom", "com.amazon.amazonvideo.livingroom.nvidia"], "color": "#0F171E", "logo": "primevideo", "dark": "#00A8E1" },
+ { "name": "Spotify", "packages": ["com.spotify.tv.android"], "color": "#000000", "logo": "spotify", "dark": "#1ED760" },
+ { "name": "Disney+", "packages": ["com.disney.disneyplus"], "color": "#0B1446", "logo": "disney", "dark": "#00B4FF" },
+ { "name": "HBO Max", "packages": ["com.wbd.stream", "com.hbo.hbonow"], "color": "#000000", "logo": "hbomax" },
+ { "name": "Apple TV", "packages": ["com.apple.atve.androidtv.appletv"], "color": "#000000", "logo": "appletv" },
+ { "name": "Paramount+", "packages": ["com.cbs.ott"], "color": "#0064FF", "logo": "paramount" },
+ { "name": "Crunchyroll", "packages": ["com.crunchyroll.crunchyroid"], "color": "#F47521", "logo": "crunchyroll" },
+ { "name": "Twitch", "packages": ["tv.twitch.android.app"], "color": "#9146FF", "logo": "twitch" }
+ ]
+ },
+ {
+ "name": "US",
+ "services": [
+ { "name": "Hulu", "packages": ["com.hulu.livingroomplus"], "color": "#1CE783", "logo": "hulu" },
+ { "name": "Peacock", "packages": ["com.peacocktv.peacockandroid"], "color": "#000000", "logo": "peacock", "dark": "#FFDC23" },
+ { "name": "Tubi", "packages": ["com.tubitv", "com.tubitv.ott"], "color": "#5B1EB8", "logo": "tubi", "dark": "#FFFF13" },
+ { "name": "Pluto TV", "packages": ["tv.pluto.android"], "color": "#000000", "logo": "plutotv", "dark": "#FFDE2B" }
+ ]
+ },
+ {
+ "name": "India",
+ "services": [
+ { "name": "JioHotstar", "packages": ["in.startv.hotstar"], "color": "#0F1F7A", "logo": "jiohotstar" },
+ { "name": "Zee5", "packages": ["com.graymatrix.did"], "color": "#3B0A5C", "logo": "zee5", "dark": "#EC2B8D" },
+ { "name": "SonyLIV", "packages": ["com.sonyliv"], "color": "#000000", "logo": "sonyliv" }
+ ]
+ },
+ {
+ "name": "Sports",
+ "services": [
+ { "name": "DAZN", "packages": ["com.dazn"], "color": "#000000", "logo": "dazn" }
+ ]
+ },
+ {
+ "name": "Self-hosted",
+ "services": [
+ { "name": "Plex", "packages": ["com.plexapp.android"], "color": "#E5A00D", "logo": "plex" },
+ { "name": "Jellyfin", "packages": ["org.jellyfin.androidtv"], "color": "#AA5CC3", "color2": "#00A4DC", "logo": "jellyfin" },
+ { "name": "Wholphin", "packages": ["com.github.damontecres.wholphin"], "color": "#000B25", "logo": "wholphin", "dark": "#3C73AB" },
+ { "name": "Kodi", "packages": ["org.xbmc.kodi"], "color": "#1C2B3A", "logo": "kodi", "dark": "#17B2E7" },
+ { "name": "Emby", "packages": ["tv.emby.embyatv"], "color": "#52B54B", "logo": "emby" }
+ ]
+ }
+ ]
+}
diff --git a/app/src/test/java/app/tellyscope/DockTest.kt b/app/src/test/java/app/tellyscope/DockTest.kt
index 6feece0..3934cab 100644
--- a/app/src/test/java/app/tellyscope/DockTest.kt
+++ b/app/src/test/java/app/tellyscope/DockTest.kt
@@ -19,21 +19,8 @@ class DockTest {
private val netflix = Docked("com.netflix.ninja", "Netflix")
private val smarttube = Docked("org.smarttube.stable", "SmartTube")
- @Test fun addStopsAtFourAndNeverTwice() {
- val four = (1..4).map { Docked("com.example.app$it", "App $it") }
- assertEquals(four, Dock.add(four, app("com.example.app5")))
- assertEquals(listOf(youtube), Dock.add(listOf(youtube), app(youtube.packageName)))
- assertEquals(listOf(youtube, Docked("com.example.kodi", "kodi")), Dock.add(listOf(youtube), app("com.example.kodi")))
- }
-
- @Test fun changeKeepsTheSlot() {
- val dock = listOf(youtube, netflix, smarttube)
- assertEquals(listOf(youtube, Docked("com.example.kodi", "kodi"), smarttube), Dock.replace(dock, netflix.packageName, app("com.example.kodi")))
- }
-
- @Test fun removeAndMove() {
+ @Test fun move() {
val dock = listOf(youtube, netflix, smarttube)
- assertEquals(listOf(youtube, smarttube), Dock.remove(dock, netflix.packageName))
assertEquals(listOf(netflix, smarttube, youtube), Dock.move(dock, 0, 2))
assertEquals(listOf(smarttube, youtube, netflix), Dock.move(dock, 2, 0))
assertEquals(dock, Dock.move(dock, 1, 3)) // off the end: nothing moves
@@ -50,18 +37,6 @@ class DockTest {
assertEquals(dock to emptyList<Docked>(), Dock.prune(dock, emptyList()))
}
- @Test fun thePickerOffersAppsALauncherCanOpen() {
- val apps = listOf(app("com.a"), app("com.b", launchable = false), app("com.c", enabled = false))
- assertEquals(listOf("com.a"), Dock.choices(apps).map { it.packageName })
- }
-
- @Test fun thePickerLeavesOutBuiltInPhoneStyleApps() {
- val camera = AppInfo("com.android.camera2", "Camera", null, true, true, null, "", launchable = true, tvHome = false)
- val settings = AppInfo("com.android.tv.settings", "Settings", null, true, true, null, "", launchable = true, tvHome = true)
- val sideloaded = app("com.example.phoneapp").copy(tvHome = false)
- assertEquals(listOf("com.android.tv.settings", "com.example.phoneapp"), Dock.choices(listOf(camera, settings, sideloaded)).map { it.packageName })
- }
-
@Test fun theBookKeepsOrderAcrossARestartAndFollowsARekey() {
val file = File(Files.createTempDirectory("dock").toFile(), "docks.tsv")
DockBook(file).apply {
diff --git a/app/src/test/java/app/tellyscope/RestartAndDockTest.kt b/app/src/test/java/app/tellyscope/RestartAndDockTest.kt
index 1349230..50f40d0 100644
--- a/app/src/test/java/app/tellyscope/RestartAndDockTest.kt
+++ b/app/src/test/java/app/tellyscope/RestartAndDockTest.kt
@@ -11,6 +11,7 @@ import app.tellyscope.data.DeviceState
import app.tellyscope.data.Docked
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.HistoryEntry
+import app.tellyscope.data.RemoteButtons
import app.tellyscope.data.ScanHit
import app.tellyscope.data.ScanKind
import app.tellyscope.data.Snapshot
@@ -126,13 +127,13 @@ class RestartAndDockTest {
assertNull(vm.state.value.restarting["tv"])
}
- @Test fun anAppUninstalledOnTheTvLeavesTheDock() = with(test) {
- tv.dock = listOf(Docked("com.youtube", "YouTube"), Docked("org.smarttube", "SmartTube"), Docked("com.kodi", "Kodi"))
- tv.apps = listOf(app("com.youtube", "YouTube"), app("com.kodi", "Kodi", enabled = false))
+ @Test fun anUninstalledAppKeepsItsButtonInTheAlpha() = with(test) {
+ assertTrue(RemoteButtons.ANY_SERVICE)
+ tv.dock = listOf(Docked("com.youtube", "YouTube"), Docked("org.smarttube", "SmartTube"))
+ tv.apps = listOf(app("com.youtube", "YouTube"))
start()
- assertEquals(listOf("YouTube", "Kodi"), vm.state.value.device.dock.map { it.label })
- assertEquals(listOf("YouTube", "Kodi"), tv.dock.map { it.label })
- assertEquals(Copy.leftDock(listOf("SmartTube")), vm.notice.value)
+ assertEquals(listOf("YouTube", "SmartTube"), vm.state.value.device.dock.map { it.label })
+ assertEquals(listOf("YouTube", "SmartTube"), tv.dock.map { it.label })
}
@Test fun aDockTapOpensTheAppWithoutHistory() = with(test) {
@@ -147,6 +148,15 @@ class RestartAndDockTest {
assertEquals(Copy.cantOpen("Kodi"), vm.notice.value)
}
+ @Test fun aButtonForAnAppNotOnTheTvSaysSoWithoutTrying() = with(test) {
+ tv.apps = listOf(app("com.youtube", "YouTube"))
+ start()
+ vm.launch(Docked("com.netflix.ninja", "Netflix"))
+ runCurrent()
+ assertEquals(Copy.notOnTv("Netflix"), vm.notice.value)
+ assertEquals(emptyList<String>(), tv.launched)
+ }
+
@Test fun theDockIsSavedPerTv() = with(test) {
start()
vm.setDock(listOf(Docked("com.youtube", "YouTube")))
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index 3e8fe72..0f780bc 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -1095,7 +1095,7 @@ class ScreenshotTest {
compose.onNodeWithText("OK").assertDoesNotExist()
}
- // Screen off (0.9): the header says how to wake it, so nothing below moves; the filled button turns it back on.
+ // Screen off (0.9): the header says how to wake it, so nothing below moves; the ⋮ menu turns it back on.
private fun screenOffState() = remoteState().let { it.copy(screenOff = setOf(it.selectedId!!)) }
@Test fun remote_screenOff() = shot("13_remote_screen_off", screen = true) { RemoteScreen(screenOffState(), RemoteActions()) }
@Test fun remote_screenOff_dark() = shot("13_remote_screen_off", dark = true, screen = true) { RemoteScreen(screenOffState(), RemoteActions()) }
@@ -1104,26 +1104,30 @@ class ScreenshotTest {
@Test fun screenOffSaysWhatATapDoes() {
var off by mutableStateOf(false)
compose.setContent { TellyscopeTheme(dynamic = false) { RemoteScreen(if (off) screenOffState() else remoteState(), RemoteActions()) } }
- compose.onNodeWithContentDescription(Copy.SCREEN_OFF).assertExists()
+ compose.onNodeWithContentDescription(Copy.MORE).performClick()
+ compose.onNodeWithText(Copy.SCREEN_OFF).assertExists()
+ compose.onNodeWithText(Copy.SCREEN_ON).assertDoesNotExist()
off = true
- compose.onNodeWithContentDescription(Copy.SCREEN_ON).assertExists()
+ compose.onNodeWithText(Copy.SCREEN_ON).assertExists()
compose.onNodeWithText(Copy.SCREEN_OFF_WAKE, substring = true).assertExists()
}
@Test fun android14HasNoScreenOff() {
val s = remoteState().let { st -> st.copy(devices = st.devices.map { if (it.id == st.selectedId) it.copy(android = "14") else it }) }
compose.setContent { TellyscopeTheme(dynamic = false) { RemoteScreen(s, RemoteActions()) } }
- compose.onNodeWithContentDescription(Copy.SCREEN_OFF).assertDoesNotExist()
- compose.onNodeWithContentDescription(Copy.REMOTE_RESTART).assertExists()
+ compose.onNodeWithContentDescription(Copy.MORE).performClick()
+ compose.onNodeWithText(Copy.SCREEN_OFF).assertDoesNotExist()
+ compose.onNodeWithText(Copy.REMOTE_RESTART).assertExists()
}
- /** The Remote never scrolls: on a short phone the D-pad shrinks and the dock stays on screen. */
+ /** The Remote never scrolls: on a short phone the D-pad shrinks and the buttons stay on screen, three of them. */
@Config(qualifiers = "w360dp-h640dp-xxhdpi")
@Test fun remoteFitsAShortPhone() {
val four = docked + listOf(Docked("org.jellyfin.androidtv", "Jellyfin"), Docked("com.spotify.tv.android", "Spotify"))
compose.setContent { TellyscopeTheme(dynamic = false) { RemoteScreen(remoteState(apps = four), RemoteActions()) } }
compose.onAllNodes(hasScrollAction()).assertCountEquals(0)
- listOf("OK", "Volume up", "Spotify").forEach { compose.onNodeWithContentDescription(it).assertIsDisplayed() }
+ listOf("OK", "Volume up", "Jellyfin").forEach { compose.onNodeWithContentDescription(it).assertIsDisplayed() }
+ compose.onNodeWithContentDescription("Spotify").assertDoesNotExist()
}
@Config(qualifiers = "w360dp-h640dp-xxhdpi")
@@ -1132,23 +1136,21 @@ class ScreenshotTest {
@Test fun remote_dockEmpty() = shot("12_remote_dock_empty", screen = true) { RemoteScreen(remoteState(apps = emptyList()), RemoteActions()) }
/**
- * The apps' own icons, for the README's Remote shot only. Test resources, so they never reach the
- * APK; the names and logos belong to their owners (see NOTICE).
+ * An app's own icon, for the Apps list shot only. Test resources, so it never reaches the APK; the
+ * name and logo belong to its owner (see NOTICE).
*/
private fun realIcon(pkg: String): ByteArray? = javaClass.classLoader?.getResourceAsStream("dock-icons/$pkg.png")?.use { it.readBytes() }
@Test fun remote_dockFull() {
- val four = docked + listOf(Docked("org.jellyfin.androidtv", "Jellyfin"), Docked("com.spotify.tv.android", "Spotify"))
- val spotify = AppInfo("com.spotify.tv.android", "Spotify", null, false, true, null, "", launchable = true)
- val state = deviceState { copy(dock = four, apps = (apps + spotify).map { a -> realIcon(a.packageName)?.let { a.copy(icon = it) } ?: a }) }
- shot("12_remote_dock_full", screen = true) { RemoteScreen(state, RemoteActions()) }
- // A full row has no Add tile.
- compose.onNodeWithContentDescription(Copy.ADD_TO_DOCK).assertDoesNotExist()
+ val three = docked + Docked("org.jellyfin.androidtv", "Jellyfin")
+ shot("12_remote_dock_full", screen = true) { RemoteScreen(remoteState(apps = three), RemoteActions()) }
+ // A full row has no Remote buttons pill.
+ compose.onNodeWithText(Copy.REMOTE_BUTTONS).assertDoesNotExist()
}
/**
* Banner-only apps as letter tiles, in the colours the helper picks from their banners, beside
- * a real square icon and an app with no icon at all: the Apps list and the dock.
+ * a real square icon and an app with no icon at all, in the Apps list.
*/
private fun tilesState(): UiState {
val projectivy = "com.spocky.projengmenu"
@@ -1162,26 +1164,33 @@ class ScreenshotTest {
else -> a
}
} + spotify + mine
- val dock = listOf(Docked(projectivy, "Projectivy"), Docked(spotify.packageName, "Spotify"), Docked("com.google.android.youtube.tv", "YouTube"), Docked(mine.packageName, "My App"))
- return s.copy(device = s.device.copy(apps = apps, dock = dock))
+ return s.copy(device = s.device.copy(apps = apps))
}
@Test fun tiles_apps() = shot("13_tiles_apps") { DeviceTabsScreen(tilesState(), DeviceActions(), startTab = TvTab.Apps) }
@Test fun tiles_apps_dark() = shot("13_tiles_apps", dark = true) { DeviceTabsScreen(tilesState(), DeviceActions(), startTab = TvTab.Apps) }
- @Test fun tiles_dock() = shot("13_tiles_dock", screen = true) { RemoteScreen(tilesState(), RemoteActions()) }
+ // Holding a button opens the picker.
+ @Test fun remote_dockPicker() = shot(
+ "12_remote_dock_picker", screen = true,
+ before = { compose.onNodeWithContentDescription("Netflix").performSemanticsAction(SemanticsActions.OnLongClick) },
+ ) { RemoteScreen(remoteState(), RemoteActions()) }
- @Test fun tiles_dock_dark() = shot("13_tiles_dock", dark = true, screen = true) { RemoteScreen(tilesState(), RemoteActions()) }
+ @Test fun remote_dockPicker_dark() = shot(
+ "12_remote_dock_picker", dark = true, screen = true,
+ before = { compose.onNodeWithContentDescription("Netflix").performSemanticsAction(SemanticsActions.OnLongClick) },
+ ) { RemoteScreen(remoteState(), RemoteActions()) }
- @Test fun remote_dockPicker() = shot("12_remote_dock_picker", screen = true, before = { compose.onNodeWithContentDescription(Copy.ADD_TO_DOCK).performClick() }) {
+ @Test fun remote_menu() = shot("12_remote_menu", screen = true, before = { compose.onNodeWithContentDescription(Copy.MORE).performClick() }) {
RemoteScreen(remoteState(), RemoteActions())
}
- @Test fun remote_dockMenu() = shot(
- "12_remote_dock_menu", screen = true,
- before = { compose.onNodeWithContentDescription("Netflix").performSemanticsAction(SemanticsActions.OnLongClick) },
- ) { RemoteScreen(remoteState(), RemoteActions()) }
+ @Test fun theEmptyPillOpensThePicker() {
+ compose.setContent { TellyscopeTheme(dynamic = false) { RemoteScreen(remoteState(apps = emptyList()), RemoteActions()) } }
+ compose.onNodeWithText(Copy.REMOTE_BUTTONS).performClick()
+ compose.onNodeWithText(Copy.buttonsHint(3)).assertExists()
+ }
@Test fun remote_restarting() = shot("13_remote_restarting", screen = true) {
RemoteScreen(remoteState(restart = Restart(now - 25_000, down = true)), RemoteActions())
diff --git a/app/src/test/java/app/tellyscope/StreamingTest.kt b/app/src/test/java/app/tellyscope/StreamingTest.kt
new file mode 100644
index 0000000..9299a14
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/StreamingTest.kt
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.AppInfo
+import app.tellyscope.data.BundledLists
+import app.tellyscope.data.Docked
+import app.tellyscope.data.RemoteButtons
+import app.tellyscope.data.StreamingService
+import app.tellyscope.data.parseStreaming
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import java.io.File
+import javax.imageio.ImageIO
+
+/** org.json is Android's, so this runs under Robolectric. */
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [35])
+class StreamingTest {
+ private val services = BundledLists.streaming
+
+ @Test fun theBundledListReadsWholeAndEveryLogoIsThere() {
+ val text = File("src/main/resources/lists/streaming.json").readText()
+ val parsed = parseStreaming(text)
+ assertEquals(Regex("\"packages\"").findAll(text).count(), parsed.size) // nothing dropped
+ assertEquals(parsed.size, parsed.map { it.name }.toSet().size)
+ val pkgs = parsed.flatMap { it.packages }
+ assertEquals(pkgs.size, pkgs.toSet().size) // no package belongs to two services
+ parsed.forEach { s ->
+ val png = ImageIO.read(checkNotNull(BundledLists.logo(s.logo)) { "lists/logos/${s.logo}.png is missing" }.inputStream())
+ // Four times the size in dp, and it has to fit the smallest pill, 80 x 40 dp.
+ assertTrue("${s.logo} is ${png.width}x${png.height}", png.width <= 72 * 4 && png.height <= 30 * 4)
+ }
+ }
+
+ @Test fun aServiceWithoutAColourOrAPackageIsDropped() {
+ val text = """{ "schema": 1, "groups": [ { "name": "G", "services": [
+ { "name": "A", "packages": ["com.a"], "color": "#112233", "logo": "a" },
+ { "name": "B", "packages": ["com.b"], "color": "red", "logo": "b" },
+ { "name": "C", "packages": ["not a package"], "color": "#112233", "logo": "c" },
+ { "name": "D", "packages": ["com.d"], "color": "#112233", "logo": "../d" }
+ ] } ] }"""
+ assertEquals(listOf("A"), parseStreaming(text).map { it.name })
+ assertEquals(0xFF112233, parseStreaming(text).single().color)
+ assertEquals(emptyList<StreamingService>(), parseStreaming(text.replace("\"schema\": 1", "\"schema\": 2")))
+ }
+
+ private fun service(name: String) = services.first { it.name == name }
+
+ @Test fun aPhoneShowsThreeAndAWideScreenFour() {
+ assertEquals(3, RemoteButtons.cap(411))
+ assertEquals(4, RemoteButtons.cap(600))
+ val dock = listOf("Netflix", "YouTube", "Plex", "Kodi").map { Docked(service(it).packages.first(), it) }
+ assertEquals(listOf("Netflix", "YouTube", "Plex"), RemoteButtons.shown(dock, services, 3).map { it.name })
+ assertEquals(4, RemoteButtons.shown(dock, services, 4).size)
+ // An app docked before the buttons, that isn't a service, doesn't show.
+ assertEquals(listOf("Netflix"), RemoteButtons.shown(listOf(Docked("com.example.app", "App"), dock[0]), services, 3).map { it.name })
+ }
+
+ @Test fun aTickAddsInOrderUpToTheCapAndAnUntickRemoves() {
+ var dock = emptyList<Docked>()
+ listOf("Netflix", "Plex", "Kodi", "Emby").forEach { dock = RemoteButtons.toggle(dock, service(it), services, 3, emptyList()) }
+ assertEquals(listOf("Netflix", "Plex", "Kodi"), dock.map { it.label })
+ dock = RemoteButtons.toggle(dock, service("Plex"), services, 3, emptyList())
+ assertEquals(listOf("Netflix", "Kodi"), dock.map { it.label })
+ }
+
+ @Test fun aButtonOpensTheVariantTheTvHas() {
+ val prime = service("Prime Video")
+ val nvidia = AppInfo("com.amazon.amazonvideo.livingroom.nvidia", "Prime Video", null, false, true, null, "", launchable = true)
+ assertEquals(nvidia.packageName, RemoteButtons.toggle(emptyList(), prime, services, 3, listOf(nvidia)).single().packageName)
+ assertEquals(prime.packages.first(), prime.packageOn(emptyList()))
+ }
+
+ @Test fun theAlphaOffersEveryService() {
+ assertTrue(RemoteButtons.ANY_SERVICE)
+ assertEquals(services, RemoteButtons.choices(services, emptyList()))
+ }
+
+ private val lightSheet = 0xFFEEF5F4
+ private val darkSheet = 0xFF161D1D
+
+ @Test fun aPaleColourGetsAnOutlineInLightMode() {
+ assertTrue(RemoteButtons.look(service("YouTube"), lightSheet, dark = false).outline)
+ assertTrue(RemoteButtons.look(service("Jellyfin"), lightSheet, dark = false).outline) // by its paler end
+ assertFalse(RemoteButtons.look(service("Netflix"), lightSheet, dark = false).outline)
+ assertNull(RemoteButtons.look(service("YouTube"), lightSheet, dark = false).ink)
+ }
+
+ @Test fun aDarkPillTakesItsAccentInDarkModeWithAReadableLogo() {
+ val netflix = RemoteButtons.look(service("Netflix"), darkSheet, dark = true)
+ assertEquals(0xFFE50914, netflix.fill)
+ assertEquals(RemoteButtons.WHITE, netflix.ink)
+ assertEquals(RemoteButtons.BLACK, RemoteButtons.look(service("Spotify"), darkSheet, dark = true).ink)
+ // A white-only logo on black has no accent: it stays as it is, with no edge.
+ val hbo = RemoteButtons.look(service("HBO Max"), darkSheet, dark = true)
+ assertEquals(service("HBO Max").color, hbo.fill)
+ assertFalse(hbo.outline)
+ assertNull(hbo.ink)
+ // Bright enough already: unchanged.
+ assertEquals(service("Plex").color, RemoteButtons.look(service("Plex"), darkSheet, dark = true).fill)
+ }
+
+ @Test fun everyDarkFillReadsAgainstTheSheet() {
+ services.mapNotNull { s -> s.dark?.let { s.name to it } }.forEach { (name, fill) ->
+ assertTrue(name, RemoteButtons.contrast(fill, darkSheet) >= 3.0)
+ }
+ }
+}
diff --git a/app/src/test/resources/dock-icons/com.netflix.ninja.png b/app/src/test/resources/dock-icons/com.netflix.ninja.png
deleted file mode 100644
index cddfeaf..0000000
Binary files a/app/src/test/resources/dock-icons/com.netflix.ninja.png and /dev/null differ
diff --git a/app/src/test/resources/dock-icons/com.spotify.tv.android.png b/app/src/test/resources/dock-icons/com.spotify.tv.android.png
deleted file mode 100644
index 42a9981..0000000
Binary files a/app/src/test/resources/dock-icons/com.spotify.tv.android.png and /dev/null differ
diff --git a/app/src/test/resources/dock-icons/org.jellyfin.androidtv.png b/app/src/test/resources/dock-icons/org.jellyfin.androidtv.png
deleted file mode 100644
index 38e6c34..0000000
Binary files a/app/src/test/resources/dock-icons/org.jellyfin.androidtv.png and /dev/null differ