diff --git a/AGENTS.md b/AGENTS.md index bbc83e04..214d7c7a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -122,6 +122,10 @@ keystores, passwords, tokens, or other credentials to the repository. the app is built to and is published on the website, so a change that contradicts it either fixes the change or amends the doctrine in the same pull request. +11. Keep the app fully navigable by remote control for Android TV and Google TV. + Ensure interactive elements maintain clear D-Pad focus rings, handle + DPAD/remote key events cleanly, and adapt layouts (e.g., width constraints + on settings and sheets) for wide 16:9 television viewing. ## Agent skills diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e037678..90dd3c27 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,7 @@ Navigation 3, native libmpv playback. Good first areas: - Bug fixes with a clear repro -- Tablet / large-screen layout improvements (current focus) +- Android TV / Google TV remote support and tablet / large-screen layout polish - Performance + battery efficiency improvements with measured before/after - Player UX polish (gestures, seekbar, subtitles, chapters) - File browser, SMB / FTP / WebDAV fixes @@ -94,6 +94,10 @@ the PR — maintainers can help. and string resources — do not introduce near-duplicates. - Verify alignment, insets (status / navigation / gesture areas), RTL mirroring, and light/dark themes for UI changes. +- Ensure 10-foot remote / D-Pad accessibility for UI changes: interactive + components must support keyboard and D-Pad focusability (`Modifier.focusable`), + provide prominent focus indication (focus rings / borders and subtle fills), + and handle DPAD/remote key events gracefully. - Kotlin + Compose conventions already in the tree win over personal style. - Run `git diff --check` before committing. diff --git a/README.md b/README.md index c684983e..c6c263e9 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ features or bugs. ## Features - Hardware-accelerated, high-quality video playback through libmpv +- Full Android TV and Google TV support with Leanback launcher banner, 10-foot D-Pad remote navigation, and landscape-optimized playback controls - Material 3 interface with light and dark themes - Picture-in-picture and background playback - Gesture controls, zoom, and screen orientation controls @@ -74,9 +75,9 @@ The repository may provide several APKs for different CPU architectures: | APK | Devices | | --- | --- | -| `universal` | Most devices; larger download | -| `arm64-v8a` | Modern 64-bit ARM devices; recommended for most phones | -| `armeabi-v7a` | Older 32-bit ARM devices | +| `universal` | Most devices, Android TV, and Google TV; larger download | +| `arm64-v8a` | Modern 64-bit ARM devices (phones, tablets, Android TV) | +| `armeabi-v7a` | Older 32-bit ARM devices (older phones and TV sticks) | | `x86` | 32-bit Intel/AMD devices | | `x86_64` | 64-bit Intel/AMD devices | diff --git a/UNRELEASED.md b/UNRELEASED.md index b4a6af65..751cb396 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -6,6 +6,9 @@ ### Added +- Android TV and Google TV support with Leanback launcher banner, 10-foot D-Pad remote navigation, clear visual focus rings, landscape enforcement, and dedicated TV playback controls. +- Comprehensive TV remote optimization for Modern player layout: auto-focused hero play/pause button, D-Pad Left/Right seekbar scrubbing, and interactive focus rings across transport controls, action pill buttons, and sheets. +- TV settings layout with centered content, D-Pad focus indicators on preference rows and choice sheets, and remote-navigable theme preview cards. - Theme Studio card opens My Canvas with full primary, secondary, and tertiary color customization, continuous HSV and hex color pickers, and live player controls and homepage previews. - Holding any custom theme in the theme picker allows editing its colors or deleting it. - The new r/mpvium subreddit joins Discord and Telegram in About and on the website. @@ -18,5 +21,7 @@ ### Fixed +- Downloaded and sideloaded media on Android TV is no longer suppressed from the Titles library by mobile transient folder thresholds. +- Main navigation rail on TV uses clean native Material 3 indicator pills without distorted selection outlines. - Modern player layout custom action buttons scale consistently with built-in controls. - Shader peek upscale chip no longer covers top-right player buttons when smart skip is absent. diff --git a/app/schemas/app.aryan447.mpvium.database.MpviumDatabase/10.json b/app/schemas/app.aryan447.mpvium.database.MpviumDatabase/10.json new file mode 100644 index 00000000..32dee804 --- /dev/null +++ b/app/schemas/app.aryan447.mpvium.database.MpviumDatabase/10.json @@ -0,0 +1,737 @@ +{ + "formatVersion": 1, + "database": { + "version": 10, + "identityHash": "1a9fe53b4f523ea3ce4c8bff613e2683", + "entities": [ + { + "tableName": "PlaybackStateEntity", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`mediaTitle` TEXT NOT NULL, `lastPosition` INTEGER NOT NULL, `playbackSpeed` REAL NOT NULL, `videoZoom` REAL NOT NULL, `sid` INTEGER NOT NULL, `secondarySid` INTEGER NOT NULL, `subDelay` INTEGER NOT NULL, `subSpeed` REAL NOT NULL, `aid` INTEGER NOT NULL, `audioDelay` INTEGER NOT NULL, `timeRemaining` INTEGER NOT NULL, `externalSubtitles` TEXT NOT NULL, `hasBeenWatched` INTEGER NOT NULL, PRIMARY KEY(`mediaTitle`))", + "fields": [ + { + "fieldPath": "mediaTitle", + "columnName": "mediaTitle", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastPosition", + "columnName": "lastPosition", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "playbackSpeed", + "columnName": "playbackSpeed", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "videoZoom", + "columnName": "videoZoom", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "sid", + "columnName": "sid", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "secondarySid", + "columnName": "secondarySid", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "subDelay", + "columnName": "subDelay", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "subSpeed", + "columnName": "subSpeed", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "aid", + "columnName": "aid", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "audioDelay", + "columnName": "audioDelay", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timeRemaining", + "columnName": "timeRemaining", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "externalSubtitles", + "columnName": "externalSubtitles", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "hasBeenWatched", + "columnName": "hasBeenWatched", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "mediaTitle" + ] + } + }, + { + "tableName": "RecentlyPlayedEntity", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `filePath` TEXT NOT NULL, `fileName` TEXT NOT NULL, `videoTitle` TEXT, `duration` INTEGER NOT NULL, `fileSize` INTEGER NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `launchSource` TEXT, `playlistId` INTEGER)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "filePath", + "columnName": "filePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fileName", + "columnName": "fileName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "videoTitle", + "columnName": "videoTitle", + "affinity": "TEXT" + }, + { + "fieldPath": "duration", + "columnName": "duration", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fileSize", + "columnName": "fileSize", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "width", + "columnName": "width", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "height", + "columnName": "height", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "launchSource", + "columnName": "launchSource", + "affinity": "TEXT" + }, + { + "fieldPath": "playlistId", + "columnName": "playlistId", + "affinity": "INTEGER" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + } + }, + { + "tableName": "video_metadata_cache", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`path` TEXT NOT NULL, `size` INTEGER NOT NULL, `dateModified` INTEGER NOT NULL, `duration` INTEGER NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `fps` REAL NOT NULL, `hasEmbeddedSubtitles` INTEGER NOT NULL, `subtitleCodec` TEXT NOT NULL, `lastScanned` INTEGER NOT NULL, PRIMARY KEY(`path`))", + "fields": [ + { + "fieldPath": "path", + "columnName": "path", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "size", + "columnName": "size", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dateModified", + "columnName": "dateModified", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "duration", + "columnName": "duration", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "width", + "columnName": "width", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "height", + "columnName": "height", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fps", + "columnName": "fps", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "hasEmbeddedSubtitles", + "columnName": "hasEmbeddedSubtitles", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "subtitleCodec", + "columnName": "subtitleCodec", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastScanned", + "columnName": "lastScanned", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "path" + ] + } + }, + { + "tableName": "network_connections", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `protocol` TEXT NOT NULL, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, `path` TEXT NOT NULL, `isAnonymous` INTEGER NOT NULL, `lastConnected` INTEGER NOT NULL, `autoConnect` INTEGER NOT NULL, `useHttps` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "protocol", + "columnName": "protocol", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "host", + "columnName": "host", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "port", + "columnName": "port", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "username", + "columnName": "username", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "password", + "columnName": "password", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "path", + "columnName": "path", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isAnonymous", + "columnName": "isAnonymous", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastConnected", + "columnName": "lastConnected", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "autoConnect", + "columnName": "autoConnect", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "useHttps", + "columnName": "useHttps", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + } + }, + { + "tableName": "PlaylistEntity", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `m3uSourceUrl` TEXT, `isM3uPlaylist` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "m3uSourceUrl", + "columnName": "m3uSourceUrl", + "affinity": "TEXT" + }, + { + "fieldPath": "isM3uPlaylist", + "columnName": "isM3uPlaylist", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + } + }, + { + "tableName": "PlaylistItemEntity", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `playlistId` INTEGER NOT NULL, `filePath` TEXT NOT NULL, `fileName` TEXT NOT NULL, `position` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, `lastPlayedAt` INTEGER NOT NULL, `playCount` INTEGER NOT NULL, `lastPosition` INTEGER NOT NULL, FOREIGN KEY(`playlistId`) REFERENCES `PlaylistEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "playlistId", + "columnName": "playlistId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "filePath", + "columnName": "filePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fileName", + "columnName": "fileName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "position", + "columnName": "position", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "addedAt", + "columnName": "addedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastPlayedAt", + "columnName": "lastPlayedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "playCount", + "columnName": "playCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastPosition", + "columnName": "lastPosition", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_PlaylistItemEntity_playlistId", + "unique": false, + "columnNames": [ + "playlistId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_PlaylistItemEntity_playlistId` ON `${TABLE_NAME}` (`playlistId`)" + } + ], + "foreignKeys": [ + { + "table": "PlaylistEntity", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "playlistId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "library_index", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`path` TEXT NOT NULL, `size` INTEGER NOT NULL, `mtimeMs` INTEGER NOT NULL, `parsedTitle` TEXT NOT NULL, `parsedYear` TEXT, `parsedSeason` INTEGER, `parsedEpisode` INTEGER, `parsedEpisodeTitle` TEXT, `parsedType` TEXT NOT NULL, `mediaStoreId` INTEGER NOT NULL, `displayName` TEXT NOT NULL, `durationMs` INTEGER NOT NULL, `dateAdded` INTEGER NOT NULL, `mimeType` TEXT NOT NULL, `bucketId` TEXT NOT NULL, `bucketDisplayName` TEXT NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `fps` REAL NOT NULL, `lastScanned` INTEGER NOT NULL, PRIMARY KEY(`path`))", + "fields": [ + { + "fieldPath": "path", + "columnName": "path", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "size", + "columnName": "size", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "mtimeMs", + "columnName": "mtimeMs", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "parsedTitle", + "columnName": "parsedTitle", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "parsedYear", + "columnName": "parsedYear", + "affinity": "TEXT" + }, + { + "fieldPath": "parsedSeason", + "columnName": "parsedSeason", + "affinity": "INTEGER" + }, + { + "fieldPath": "parsedEpisode", + "columnName": "parsedEpisode", + "affinity": "INTEGER" + }, + { + "fieldPath": "parsedEpisodeTitle", + "columnName": "parsedEpisodeTitle", + "affinity": "TEXT" + }, + { + "fieldPath": "parsedType", + "columnName": "parsedType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "mediaStoreId", + "columnName": "mediaStoreId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "displayName", + "columnName": "displayName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "durationMs", + "columnName": "durationMs", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dateAdded", + "columnName": "dateAdded", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "mimeType", + "columnName": "mimeType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bucketId", + "columnName": "bucketId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bucketDisplayName", + "columnName": "bucketDisplayName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "width", + "columnName": "width", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "height", + "columnName": "height", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fps", + "columnName": "fps", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "lastScanned", + "columnName": "lastScanned", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "path" + ] + } + }, + { + "tableName": "custom_series", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `year` TEXT, `posterPath` TEXT, `tmdbId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "year", + "columnName": "year", + "affinity": "TEXT" + }, + { + "fieldPath": "posterPath", + "columnName": "posterPath", + "affinity": "TEXT" + }, + { + "fieldPath": "tmdbId", + "columnName": "tmdbId", + "affinity": "INTEGER" + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + } + }, + { + "tableName": "custom_series_item", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `seriesId` INTEGER NOT NULL, `filePath` TEXT NOT NULL, `fileName` TEXT NOT NULL, `season` INTEGER NOT NULL, `episode` INTEGER NOT NULL, `position` INTEGER NOT NULL, FOREIGN KEY(`seriesId`) REFERENCES `custom_series`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "seriesId", + "columnName": "seriesId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "filePath", + "columnName": "filePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fileName", + "columnName": "fileName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "season", + "columnName": "season", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "episode", + "columnName": "episode", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "position", + "columnName": "position", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_custom_series_item_seriesId", + "unique": false, + "columnNames": [ + "seriesId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_custom_series_item_seriesId` ON `${TABLE_NAME}` (`seriesId`)" + }, + { + "name": "index_custom_series_item_filePath", + "unique": false, + "columnNames": [ + "filePath" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_custom_series_item_filePath` ON `${TABLE_NAME}` (`filePath`)" + } + ], + "foreignKeys": [ + { + "table": "custom_series", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "seriesId" + ], + "referencedColumns": [ + "id" + ] + } + ] + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1a9fe53b4f523ea3ce4c8bff613e2683')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index efdd597d..0c6147b0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,9 +25,42 @@ android:name="android.hardware.usb.host" android:required="false" /> + + + + + + + + + + + + @@ -48,6 +82,7 @@ + @@ -56,6 +91,7 @@ + // shorter duration before hiding anything from Movies. On Android TV, + // media is often transferred directly to Downloads, so landscape media + // above VERY_SHORT_MAX_MS stays visible in the movie library. + !isTv && transientSource && durationMs <= TRANSIENT_SOURCE_MAX_MS -> MovieLibraryKind.SHORT_VIDEO else -> MovieLibraryKind.MOVIE diff --git a/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/FolderCard.kt b/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/FolderCard.kt index 080a7773..e483521f 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/FolderCard.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/FolderCard.kt @@ -45,6 +45,7 @@ import app.aryan447.mpvium.domain.media.model.VideoFolder import app.aryan447.mpvium.preferences.AppearancePreferences import app.aryan447.mpvium.preferences.BrowserPreferences import app.aryan447.mpvium.preferences.preference.collectAsState +import app.aryan447.mpvium.ui.utils.tvFocusHighlight import kotlin.math.pow import org.koin.compose.koinInject @@ -127,6 +128,11 @@ fun FolderCard( Card( modifier = modifier .fillMaxWidth() + .tvFocusHighlight( + shape = if (expressive) RoundedCornerShape(cardCorner) else CardDefaults.shape, + interactionSource = cardInteraction, + scale = 1.03f, + ) .graphicsLayer { scaleX = pressScale scaleY = pressScale diff --git a/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/VideoCard.kt b/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/VideoCard.kt index bdd77308..7a469dec 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/VideoCard.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/browser/cards/VideoCard.kt @@ -51,6 +51,8 @@ import app.aryan447.mpvium.preferences.AppearancePreferences import app.aryan447.mpvium.preferences.BrowserPreferences import app.aryan447.mpvium.preferences.preference.collectAsState import androidx.compose.foundation.combinedClickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import app.aryan447.mpvium.ui.utils.tvFocusHighlight import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.withContext @@ -111,17 +113,23 @@ fun VideoCard( // Use override parameters if provided, otherwise use preferences val showSizeChip = overrideShowSizeChip ?: showSizeChipPref val showResolutionChip = overrideShowResolutionChip ?: showResolutionChipPref + val cardInteraction = remember { MutableInteractionSource() } Card( modifier = modifier - .then( - if (isGridMode) Modifier.fillMaxWidth() else Modifier.fillMaxWidth() + .fillMaxWidth() + .tvFocusHighlight( + shape = CardDefaults.shape, + interactionSource = cardInteraction, + scale = 1.03f, ) .combinedClickable( + interactionSource = cardInteraction, + indication = null, onClick = onClick, onLongClick = onLongClick, ), - colors = CardDefaults. cardColors(containerColor = Color. Transparent), + colors = CardDefaults.cardColors(containerColor = Color.Transparent), ) { if (isGridMode) { // GRID LAYOUT - Vertical arrangement diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerActivity.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerActivity.kt index 6db3a901..463a53f5 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerActivity.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerActivity.kt @@ -473,7 +473,9 @@ class PlayerActivity : // Only set orientation immediately if NOT in Video mode // For Video mode, wait for video-params/aspect to become available if (isAudioMode) { - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + if (!app.aryan447.mpvium.utils.DeviceUtils.isTv(this)) { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } window.statusBarColor = android.graphics.Color.TRANSPARENT window.navigationBarColor = android.graphics.Color.TRANSPARENT try { @@ -543,6 +545,12 @@ class PlayerActivity : return } + // When controls are visible on TV or phone, Back dismisses the controls first + if (viewModel.controlsShown.value) { + viewModel.hideControls() + return + } + // Check if auto PIP is enabled - enter PIP mode instead of finishing if (playerPreferences.autoPiPOnNavigation.get() && isReady) { pipHelper.enterPipMode() @@ -554,16 +562,21 @@ class PlayerActivity : } private fun setupPlayerControls() { + val isTv = app.aryan447.mpvium.utils.DeviceUtils.isTv(this) binding.controls.setContent { - MpviumTheme { - PlayerControls( - viewModel = viewModel, - onBackPress = { - isUserFinishing = true - finish() - }, - modifier = Modifier, - ) + androidx.compose.runtime.CompositionLocalProvider( + app.aryan447.mpvium.ui.utils.LocalIsTv provides isTv, + ) { + MpviumTheme { + PlayerControls( + viewModel = viewModel, + onBackPress = { + isUserFinishing = true + finish() + }, + modifier = Modifier, + ) + } } } } @@ -2775,6 +2788,11 @@ class PlayerActivity : * to the correct orientation, starting with landscape as fallback. */ private fun setOrientation() { + if (app.aryan447.mpvium.utils.DeviceUtils.isTv(this)) { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + return + } + if (viewModel.isAudioMode.value) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT return @@ -2834,47 +2852,97 @@ class PlayerActivity : keyCode: Int, event: KeyEvent?, ): Boolean { - val isTrackSheetOpen = - viewModel.sheetShown.value == Sheets.SubtitleTracks || - viewModel.sheetShown.value == Sheets.AudioTracks - val isNoSheetOpen = viewModel.sheetShown.value == Sheets.None + val isNoSheetOpen = viewModel.sheetShown.value == Sheets.None && viewModel.panelShown.value == Panels.None + val areControlsVisible = viewModel.controlsShown.value + + if (areControlsVisible) { + viewModel.keepControlsAlive() + } when (keyCode) { - KeyEvent.KEYCODE_DPAD_UP -> { + KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN -> { + if (!areControlsVisible && isNoSheetOpen) { + viewModel.showControls() + return true + } return super.onKeyDown(keyCode, event) } - KeyEvent.KEYCODE_DPAD_DOWN, - KeyEvent.KEYCODE_DPAD_RIGHT, - KeyEvent.KEYCODE_DPAD_LEFT, - -> { - if (isTrackSheetOpen) { + KeyEvent.KEYCODE_DPAD_RIGHT -> { + if (!isNoSheetOpen) { return super.onKeyDown(keyCode, event) } - if (isNoSheetOpen) { - when (keyCode) { - KeyEvent.KEYCODE_DPAD_RIGHT -> { - viewModel.handleRightDoubleTap() - return true - } + if (!areControlsVisible) { + viewModel.handleRightDoubleTap() + return true + } + return super.onKeyDown(keyCode, event) + } - KeyEvent.KEYCODE_DPAD_LEFT -> { - viewModel.handleLeftDoubleTap() - return true - } - } + KeyEvent.KEYCODE_DPAD_LEFT -> { + if (!isNoSheetOpen) { + return super.onKeyDown(keyCode, event) + } + + if (!areControlsVisible) { + viewModel.handleLeftDoubleTap() + return true } return super.onKeyDown(keyCode, event) } - KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> { - if (isTrackSheetOpen) { + KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> { + if (!isNoSheetOpen) { return super.onKeyDown(keyCode, event) } + if (!areControlsVisible) { + viewModel.pauseUnpause() + viewModel.showControls() + return true + } return super.onKeyDown(keyCode, event) } + KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> { + viewModel.pauseUnpause() + return true + } + + KeyEvent.KEYCODE_MEDIA_PLAY -> { + viewModel.unpause() + return true + } + + KeyEvent.KEYCODE_MEDIA_PAUSE -> { + viewModel.pause() + return true + } + + KeyEvent.KEYCODE_MEDIA_NEXT, KeyEvent.KEYCODE_CHANNEL_UP -> { + playNext() + return true + } + + KeyEvent.KEYCODE_MEDIA_PREVIOUS, KeyEvent.KEYCODE_CHANNEL_DOWN -> { + playPrevious() + return true + } + + KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_INFO -> { + if (areControlsVisible) { + viewModel.hideControls() + } else { + viewModel.showControls() + } + return true + } + + KeyEvent.KEYCODE_VOLUME_MUTE -> { + MPVLib.command("cycle", "mute") + return true + } + KeyEvent.KEYCODE_SPACE -> { viewModel.pauseUnpause() return true diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerViewModel.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerViewModel.kt index 46f88ac7..bf39cf14 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/PlayerViewModel.kt @@ -344,6 +344,13 @@ class PlayerViewModel( private val _controlsShown = MutableStateFlow(false) val controlsShown: StateFlow = _controlsShown.asStateFlow() + private val _controlsInteractionTimestamp = MutableStateFlow(0L) + val controlsInteractionTimestamp: StateFlow = _controlsInteractionTimestamp.asStateFlow() + + fun keepControlsAlive() { + _controlsInteractionTimestamp.value = android.os.SystemClock.uptimeMillis() + } + private val _seekBarShown = MutableStateFlow(false) val seekBarShown: StateFlow = _seekBarShown.asStateFlow() diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/ModernPlayerControls.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/ModernPlayerControls.kt index 374f7712..f9b0ce88 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/ModernPlayerControls.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/ModernPlayerControls.kt @@ -1,5 +1,6 @@ package app.aryan447.mpvium.ui.player.controls +import android.view.KeyEvent import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.Crossfade import androidx.compose.animation.animateContentSize @@ -7,6 +8,7 @@ import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.animateDpAsState +import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut @@ -19,9 +21,20 @@ import androidx.compose.foundation.Canvas import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.input.key.Key +import androidx.compose.ui.input.key.KeyEventType +import androidx.compose.ui.input.key.key +import androidx.compose.ui.input.key.onKeyEvent +import androidx.compose.ui.input.key.type import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -183,6 +196,7 @@ fun ModernPlayerControls( currentZoom: Float = 1f, aspect: VideoAspect = VideoAspect.Fit, decoder: app.aryan447.mpvium.ui.player.Decoder = app.aryan447.mpvium.ui.player.Decoder.SW, + playPauseFocusRequester: FocusRequester? = null, modifier: Modifier = Modifier, ) { val haptic = LocalHapticFeedback.current @@ -253,39 +267,23 @@ fun ModernPlayerControls( horizontalArrangement = Arrangement.spacedBy(14.dp), ) { // Close Button (✕) - Icon( - imageVector = Icons.Default.Close, + ModernActionIconButton( + icon = Icons.Default.Close, contentDescription = "Close", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - ) { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - resetControlsTimestamp() - onBackPress() - }, + onClick = { + resetControlsTimestamp() + onBackPress() + }, ) // PiP Button - Icon( - imageVector = Icons.Default.PictureInPictureAlt, + ModernActionIconButton( + icon = Icons.Default.PictureInPictureAlt, contentDescription = "Picture in Picture", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - ) { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - resetControlsTimestamp() - activity.enterPipModeHidingOverlay() - }, + onClick = { + resetControlsTimestamp() + activity.enterPipModeHidingOverlay() + }, ) } } @@ -329,6 +327,7 @@ fun ModernPlayerControls( surfaceColor = surfaceColor, borderStroke = borderStroke, showBackground = showButtonsBackground, + playPauseFocusRequester = playPauseFocusRequester, ) } @@ -1030,9 +1029,35 @@ fun ModernCenterTransportControls( surfaceColor: Color, borderStroke: BorderStroke, showBackground: Boolean = false, + playPauseFocusRequester: FocusRequester? = null, modifier: Modifier = Modifier, ) { val haptic = LocalHapticFeedback.current + val primary = MaterialTheme.colorScheme.primary + + val rewindInteraction = remember { MutableInteractionSource() } + val isRewindFocused by rewindInteraction.collectIsFocusedAsState() + val rewindScale by animateFloatAsState( + targetValue = if (isRewindFocused) 1.12f else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "rewindFocusScale", + ) + + val playPauseInteraction = remember { MutableInteractionSource() } + val isPlayPauseFocused by playPauseInteraction.collectIsFocusedAsState() + val playPauseScale by animateFloatAsState( + targetValue = if (isPlayPauseFocused) 1.12f else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "playPauseFocusScale", + ) + + val forwardInteraction = remember { MutableInteractionSource() } + val isForwardFocused by forwardInteraction.collectIsFocusedAsState() + val forwardScale by animateFloatAsState( + targetValue = if (isForwardFocused) 1.12f else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "forwardFocusScale", + ) Row( modifier = modifier, @@ -1043,9 +1068,14 @@ fun ModernCenterTransportControls( Surface( modifier = Modifier .size(52.dp) + .graphicsLayer { + scaleX = rewindScale + scaleY = rewindScale + } .clip(CircleShape) + .focusable(interactionSource = rewindInteraction) .clickable( - interactionSource = remember { MutableInteractionSource() }, + interactionSource = rewindInteraction, indication = ripple(bounded = true, radius = 26.dp), onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) @@ -1053,15 +1083,16 @@ fun ModernCenterTransportControls( }, ) .then( - if (!showBackground) { - Modifier.background(brush = transportShadow, shape = CircleShape) + if (isRewindFocused) { + Modifier.border(BorderStroke(2.5.dp, primary), CircleShape) + } else if (showBackground) { + Modifier.border(borderStroke, CircleShape) } else { - Modifier - }, + Modifier.background(brush = transportShadow, shape = CircleShape) + } ), shape = CircleShape, - color = if (showBackground) surfaceColor else Color.Transparent, - border = if (showBackground) borderStroke else null, + color = if (isRewindFocused) primary.copy(alpha = 0.25f) else if (showBackground) surfaceColor else Color.Transparent, ) { Box(contentAlignment = Alignment.Center) { Icon( @@ -1077,9 +1108,15 @@ fun ModernCenterTransportControls( Surface( modifier = Modifier .size(68.dp) + .graphicsLayer { + scaleX = playPauseScale + scaleY = playPauseScale + } + .then(if (playPauseFocusRequester != null) Modifier.focusRequester(playPauseFocusRequester) else Modifier) .clip(CircleShape) + .focusable(interactionSource = playPauseInteraction) .clickable( - interactionSource = remember { MutableInteractionSource() }, + interactionSource = playPauseInteraction, indication = ripple(bounded = true, radius = 34.dp), onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) @@ -1087,15 +1124,16 @@ fun ModernCenterTransportControls( }, ) .then( - if (!showBackground) { - Modifier.background(brush = transportShadow, shape = CircleShape) + if (isPlayPauseFocused) { + Modifier.border(BorderStroke(2.5.dp, primary), CircleShape) + } else if (showBackground) { + Modifier.border(borderStroke, CircleShape) } else { - Modifier - }, + Modifier.background(brush = transportShadow, shape = CircleShape) + } ), shape = CircleShape, - color = if (showBackground) surfaceColor else Color.Transparent, - border = if (showBackground) borderStroke else null, + color = if (isPlayPauseFocused) primary.copy(alpha = 0.25f) else if (showBackground) surfaceColor else Color.Transparent, ) { Box(contentAlignment = Alignment.Center) { Icon( @@ -1111,9 +1149,14 @@ fun ModernCenterTransportControls( Surface( modifier = Modifier .size(52.dp) + .graphicsLayer { + scaleX = forwardScale + scaleY = forwardScale + } .clip(CircleShape) + .focusable(interactionSource = forwardInteraction) .clickable( - interactionSource = remember { MutableInteractionSource() }, + interactionSource = forwardInteraction, indication = ripple(bounded = true, radius = 26.dp), onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) @@ -1121,15 +1164,16 @@ fun ModernCenterTransportControls( }, ) .then( - if (!showBackground) { - Modifier.background(brush = transportShadow, shape = CircleShape) + if (isForwardFocused) { + Modifier.border(BorderStroke(2.5.dp, primary), CircleShape) + } else if (showBackground) { + Modifier.border(borderStroke, CircleShape) } else { - Modifier - }, + Modifier.background(brush = transportShadow, shape = CircleShape) + } ), shape = CircleShape, - color = if (showBackground) surfaceColor else Color.Transparent, - border = if (showBackground) borderStroke else null, + color = if (isForwardFocused) primary.copy(alpha = 0.25f) else if (showBackground) surfaceColor else Color.Transparent, ) { Box(contentAlignment = Alignment.Center) { Icon( @@ -1143,6 +1187,64 @@ fun ModernCenterTransportControls( } } +/** + * Action icon button with focus ring and scale animation for remote D-Pad navigation. + */ +@Composable +fun ModernActionIconButton( + icon: ImageVector, + contentDescription: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + iconSize: androidx.compose.ui.unit.Dp = 20.dp, + buttonSize: androidx.compose.ui.unit.Dp = 30.dp, +) { + val haptic = LocalHapticFeedback.current + val interaction = remember { MutableInteractionSource() } + val isFocused by interaction.collectIsFocusedAsState() + val primary = MaterialTheme.colorScheme.primary + val scale by animateFloatAsState( + targetValue = if (isFocused) 1.18f else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "actionBtnScale", + ) + Box( + modifier = modifier + .size(buttonSize) + .graphicsLayer { + scaleX = scale + scaleY = scale + } + .clip(CircleShape) + .focusable(interactionSource = interaction) + .clickable( + interactionSource = interaction, + indication = ripple(bounded = true, radius = buttonSize / 2), + onClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onClick() + }, + ) + .then( + if (isFocused) { + Modifier + .background(primary.copy(alpha = 0.35f), CircleShape) + .border(BorderStroke(2.dp, primary), CircleShape) + } else { + Modifier + } + ), + contentAlignment = Alignment.Center, + ) { + Icon( + imageVector = icon, + contentDescription = contentDescription, + tint = Color.White, + modifier = Modifier.size(iconSize), + ) + } +} + /** * Bottom-right floating glass actions pill: * Features Subtitles, Audio tracks, Explain (core feature), and Menu by default, @@ -1191,85 +1293,41 @@ fun ModernBottomActionsPill( border = borderStroke, ) { Row( - modifier = Modifier.padding(horizontal = 14.dp, vertical = 6.dp), + modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp), verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(14.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), ) { displayButtons.forEach { button -> when (button) { PlayerButton.SUBTITLES -> { - Icon( - imageVector = Icons.Default.Subtitles, + ModernActionIconButton( + icon = Icons.Default.Subtitles, contentDescription = "Subtitles", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onOpenSubtitles() - }, - ), + onClick = onOpenSubtitles, ) } PlayerButton.AUDIO_TRACK -> { - Icon( - imageVector = Icons.Outlined.GraphicEq, + ModernActionIconButton( + icon = Icons.Outlined.GraphicEq, contentDescription = "Audio Tracks", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onOpenAudio() - }, - ), + onClick = onOpenAudio, ) } PlayerButton.EXPLAIN -> { - Icon( - imageVector = Icons.Outlined.Translate, + ModernActionIconButton( + icon = Icons.Outlined.Translate, contentDescription = "Explain", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onOpenExplain() - }, - ), + onClick = onOpenExplain, ) } PlayerButton.MORE_OPTIONS -> { - Icon( - imageVector = Icons.Outlined.MoreVert, + ModernActionIconButton( + icon = Icons.Outlined.MoreVert, contentDescription = "Menu and More Options", - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onOpenMore() - }, - ), + onClick = onOpenMore, ) } @@ -1303,21 +1361,10 @@ fun ModernBottomActionsPill( buttonSize = 30.dp, ) } else { - Icon( - imageVector = button.icon, + ModernActionIconButton( + icon = button.icon, contentDescription = button.name, - tint = Color.White, - modifier = Modifier - .size(20.dp) - .clip(CircleShape) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(bounded = true, radius = 18.dp), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onOpenMore() - }, - ), + onClick = onOpenMore, ) } } @@ -1515,12 +1562,48 @@ fun ModernSeekbarTrack( } val themePrimary = MaterialTheme.colorScheme.primary + val seekbarInteraction = remember { MutableInteractionSource() } + val isSeekbarFocused by seekbarInteraction.collectIsFocusedAsState() Box( modifier = modifier .fillMaxWidth() .height(if (isWavy) 30.dp else 24.dp) .onSizeChanged { trackWidthPx = it.width } + .clip(RoundedCornerShape(12.dp)) + .focusable(interactionSource = seekbarInteraction) + .then( + if (isSeekbarFocused) { + Modifier.border(BorderStroke(2.dp, themePrimary.copy(alpha = 0.85f)), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) + .onKeyEvent { keyEvent -> + if (keyEvent.type == KeyEventType.KeyDown) { + val currDuration = latestDuration + val currPosition = latestPosition + when (keyEvent.key) { + Key.DirectionLeft -> { + if (currDuration > 0f) { + val step = maxOf(5f, currDuration * 0.01f).coerceAtMost(10f) + val newPos = (currPosition - step).coerceAtLeast(0f) + latestOnSeekTo(newPos, false) + true + } else false + } + Key.DirectionRight -> { + if (currDuration > 0f) { + val step = maxOf(5f, currDuration * 0.01f).coerceAtMost(10f) + val newPos = (currPosition + step).coerceAtMost(currDuration) + latestOnSeekTo(newPos, false) + true + } else false + } + else -> false + } + } else false + } .pointerInput(Unit) { detectTapGestures( onTap = { offset -> @@ -1712,7 +1795,7 @@ fun ModernSeekbarTrack( ) // 5. Thumb indicator - if (isDragging && playedWidth > 0.5f) { + if ((isDragging || isSeekbarFocused) && playedWidth > 0.5f) { drawCircle( color = Color.White, radius = (strokeWidth / 2f) + 3.dp.toPx(), @@ -1785,8 +1868,8 @@ fun ModernSeekbarTrack( } } - // 5. Thumb indicator when dragging - if (isDragging && playedWidth > 0.5f) { + // 5. Thumb indicator when dragging or focused + if ((isDragging || isSeekbarFocused) && playedWidth > 0.5f) { drawCircle( color = Color.White, radius = (h / 2f) + 2.5.dp.toPx(), diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/PlayerControls.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/PlayerControls.kt index 42a78e99..3e97439b 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/PlayerControls.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/PlayerControls.kt @@ -1,6 +1,9 @@ package app.aryan447.mpvium.ui.player.controls import androidx.activity.compose.LocalActivity +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import app.aryan447.mpvium.ui.utils.LocalIsTv import app.aryan447.mpvium.preferences.AdvancedPreferences import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.FastOutSlowInEasing @@ -278,20 +281,34 @@ fun PlayerControls( } var isUnlockSliderDragging by remember { mutableStateOf(false) } + val isTv = LocalIsTv.current + val controlsInteractionTimestamp by viewModel.controlsInteractionTimestamp.collectAsState() + val playPauseFocusRequester = remember { FocusRequester() } + + LaunchedEffect(controlsShown, isTv) { + if (controlsShown && isTv) { + try { + playPauseFocusRequester.requestFocus() + } catch (_: Exception) {} + } + } LaunchedEffect( controlsShown, paused, isSeeking, resetControlsTimestamp, + controlsInteractionTimestamp, areControlsLocked, isUnlockSliderDragging, playerLayout, + isTv, ) { if (controlsShown && paused == false && !isSeeking && !isUnlockSliderDragging) { - // Use 2.5 second delay in Modern mode, 2 second delay when controls are locked, otherwise user preference + // Use 5s on TV for remote accessibility, 2s when locked, 2.5s in Modern, otherwise user pref val delayTime = when { areControlsLocked -> 2000L + isTv -> 5000L isModern -> 2500L else -> playerTimeToDisappear.toLong() } @@ -872,6 +889,7 @@ fun PlayerControls( currentZoom = currentZoom, aspect = aspect, decoder = decoder, + playPauseFocusRequester = playPauseFocusRequester, modifier = Modifier.fillMaxSize(), ) } @@ -925,6 +943,7 @@ fun PlayerControls( resetControlsTimestamp = System.currentTimeMillis() viewModel.pauseUnpause() }, + modifier = Modifier.focusRequester(playPauseFocusRequester), hideBackground = hideBackground, size = if (isModern) 84.dp else 72.dp, ) @@ -948,6 +967,7 @@ fun PlayerControls( resetControlsTimestamp = System.currentTimeMillis() viewModel.pauseUnpause() }, + modifier = Modifier.focusRequester(playPauseFocusRequester), hideBackground = hideBackground, size = if (isModern) 84.dp else 72.dp, ) diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/ControlsButton.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/ControlsButton.kt index b26c6b88..95f426b9 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/ControlsButton.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/ControlsButton.kt @@ -39,6 +39,7 @@ import app.aryan447.mpvium.ui.player.controls.LocalPlayerButtonsClickEvent import app.aryan447.mpvium.ui.player.controls.LocalPlayerColors import app.aryan447.mpvium.ui.player.controls.LocalPlayerLayout import app.aryan447.mpvium.ui.theme.spacing +import app.aryan447.mpvium.ui.utils.tvFocusHighlight import org.koin.compose.koinInject private val modernGlyphShadow = @@ -86,6 +87,12 @@ fun ControlsButton( modifier = modifier .sizeIn(minWidth = if (isModern) 28.dp else 40.dp, minHeight = if (isModern) 28.dp else 40.dp) + .tvFocusHighlight( + shape = CircleShape, + interactionSource = interactionSource, + scale = 1.15f, + borderWidth = 2.dp, + ) .clip(CircleShape) .combinedClickable( onClick = { diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/TransportButtons.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/TransportButtons.kt index a8b01b78..09351d65 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/TransportButtons.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/TransportButtons.kt @@ -42,6 +42,7 @@ import app.aryan447.mpvium.ui.player.controls.ModernChrome import app.aryan447.mpvium.ui.player.controls.LocalPlayerColors import app.aryan447.mpvium.ui.player.controls.LocalPlayerLayout import app.aryan447.mpvium.ui.theme.spacing +import app.aryan447.mpvium.ui.utils.tvFocusHighlight internal val transportShadow = Brush.radialGradient( @@ -67,6 +68,7 @@ fun PlayerTransportButton( val haptic = LocalHapticFeedback.current val colors = LocalPlayerColors.current val isModern = LocalPlayerLayout.current == PlayerLayout.MODERN + val interactionSource = remember { MutableInteractionSource() } val contentColor = when { isModern -> ModernChrome.glyph @@ -77,10 +79,16 @@ fun PlayerTransportButton( modifier = modifier .size(size) + .tvFocusHighlight( + shape = CircleShape, + interactionSource = interactionSource, + scale = 1.12f, + borderWidth = 2.dp, + ) .clip(CircleShape) .clickable( enabled = enabled, - interactionSource = remember { MutableInteractionSource() }, + interactionSource = interactionSource, indication = ripple(bounded = false, radius = size / 2), onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) @@ -144,6 +152,7 @@ fun PlayerPillButton( val haptic = LocalHapticFeedback.current val colors = LocalPlayerColors.current val isModern = LocalPlayerLayout.current == PlayerLayout.MODERN + val interactionSource = remember { MutableInteractionSource() } Surface( shape = RoundedCornerShape(50), color = @@ -169,9 +178,16 @@ fun PlayerPillButton( modifier = modifier .height(height) + .tvFocusHighlight( + shape = RoundedCornerShape(50), + interactionSource = interactionSource, + scale = 1.05f, + borderWidth = 2.dp, + ) .clip(RoundedCornerShape(50)) .combinedClickable( enabled = enabled, + interactionSource = interactionSource, onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onClick() @@ -223,6 +239,12 @@ fun PlayerPlayPauseButton( modifier = modifier .size(size) + .tvFocusHighlight( + shape = CircleShape, + interactionSource = interaction, + scale = 1.12f, + borderWidth = 2.5.dp, + ) .clip(CircleShape) .clickable( interaction, diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/AudioTracksSheet.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/AudioTracksSheet.kt index c7f307cf..86844ee2 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/AudioTracksSheet.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/AudioTracksSheet.kt @@ -1,5 +1,8 @@ package app.aryan447.mpvium.ui.player.controls.components.sheets +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -10,6 +13,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.MoreTime import androidx.compose.material3.FilterChip @@ -19,9 +23,17 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource @@ -35,6 +47,7 @@ import app.aryan447.mpvium.preferences.preference.collectAsState import app.aryan447.mpvium.ui.player.TrackNode import app.aryan447.mpvium.ui.theme.glassFilterChipColors import app.aryan447.mpvium.ui.theme.spacing +import app.aryan447.mpvium.ui.utils.LocalIsTv import `is`.xyz.mpv.MPVLib import kotlinx.collections.immutable.ImmutableList import org.koin.compose.koinInject @@ -51,17 +64,31 @@ fun AudioTracksSheet( val audioPreferences = koinInject() val audioChannels by audioPreferences.audioChannels.collectAsState() + val isTv = LocalIsTv.current + val initialFocusRequester = remember { FocusRequester() } + + LaunchedEffect(Unit) { + if (isTv) { + try { + initialFocusRequester.requestFocus() + } catch (_: Exception) {} + } + } + GenericTracksSheet( tracks, onDismissRequest = onDismissRequest, header = { AddTrackRow( - stringResource(R.string.player_sheets_add_ext_audio), - onAddAudioTrack, + title = stringResource(R.string.player_sheets_add_ext_audio), + onClick = onAddAudioTrack, + focusRequester = initialFocusRequester, actions = { - IconButton(onClick = onOpenDelayPanel) { - Icon(Icons.Default.MoreTime, null) - } + SheetActionButton( + icon = Icons.Default.MoreTime, + contentDescription = "Audio Delay", + onClick = onOpenDelayPanel, + ) }, ) }, @@ -120,10 +147,22 @@ fun AudioTrackRow( modifier: Modifier = Modifier, ) { val haptic = LocalHapticFeedback.current + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary Row( modifier = modifier .fillMaxWidth() + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .clip(RoundedCornerShape(12.dp)) + .background(if (isFocused) primary.copy(alpha = 0.15f) else Color.Transparent) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) .clickable(onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onClick() diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/ChaptersSheet.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/ChaptersSheet.kt index cd597c75..28f2cc68 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/ChaptersSheet.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/ChaptersSheet.kt @@ -1,22 +1,35 @@ package app.aryan447.mpvium.ui.player.controls.components.sheets +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp import app.aryan447.mpvium.R import app.aryan447.mpvium.ui.theme.spacing import dev.vivvvek.seeker.Segment @@ -67,15 +80,28 @@ fun ChapterTrack( modifier: Modifier = Modifier, ) { val haptic = LocalHapticFeedback.current + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary Row( modifier = modifier .fillMaxWidth() + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .clip(RoundedCornerShape(12.dp)) + .background(if (isFocused) primary.copy(alpha = 0.15f) else Color.Transparent) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) .clickable(onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onClick() }) .padding(vertical = MaterialTheme.spacing.smaller, horizontal = MaterialTheme.spacing.medium), + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, ) { Text( diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/GenericTracksSheet.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/GenericTracksSheet.kt index fc1b6a12..47373663 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/GenericTracksSheet.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/GenericTracksSheet.kt @@ -1,11 +1,15 @@ package app.aryan447.mpvium.ui.player.controls.components.sheets import android.net.Uri +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding @@ -14,14 +18,27 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource @@ -65,32 +82,56 @@ fun AddTrackRow( title: String, onClick: () -> Unit, modifier: Modifier = Modifier, + focusRequester: FocusRequester? = null, actions: @Composable RowScope.() -> Unit = {}, ) { val haptic = LocalHapticFeedback.current + val primary = MaterialTheme.colorScheme.primary + var isFocused by remember { mutableStateOf(false) } + Row( modifier = modifier .fillMaxWidth() - .clickable(onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onClick() - }) .height(56.dp) .padding(horizontal = MaterialTheme.spacing.medium), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), ) { - Icon( - Icons.Default.Add, - contentDescription = null, - modifier = Modifier.size(24.dp), - ) - Text( - text = title, - style = MaterialTheme.typography.bodyLarge, - modifier = Modifier.weight(1f), - ) + Row( + modifier = Modifier + .weight(1f) + .fillMaxHeight() + .onFocusChanged { isFocused = it.isFocused } + .clip(RoundedCornerShape(12.dp)) + .background(if (isFocused) primary.copy(alpha = 0.15f) else Color.Transparent) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) + .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier) + .clickable { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onClick() + } + .padding(horizontal = 8.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), + ) { + Icon( + Icons.Default.Add, + contentDescription = null, + modifier = Modifier.size(24.dp), + ) + Text( + text = title, + style = MaterialTheme.typography.bodyLarge, + ) + } + Row( horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall), verticalAlignment = Alignment.CenterVertically, @@ -100,6 +141,38 @@ fun AddTrackRow( } } +@Composable +fun SheetActionButton( + icon: ImageVector, + contentDescription: String?, + onClick: () -> Unit, + modifier: Modifier = Modifier, +) { + val haptic = LocalHapticFeedback.current + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary + + IconButton( + onClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onClick() + }, + modifier = modifier + .onFocusChanged { isFocused = it.isFocused } + .clip(CircleShape) + .background(if (isFocused) primary.copy(alpha = 0.25f) else Color.Transparent) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), CircleShape) + } else { + Modifier + } + ), + ) { + Icon(icon, contentDescription = contentDescription) + } +} + /** * Get a displayable title for a track node. * Uses title, language, or a default substitute. diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/PlaylistSheet.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/PlaylistSheet.kt index ddb8fd4d..55e7ebce 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/PlaylistSheet.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/PlaylistSheet.kt @@ -45,6 +45,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.asImageBitmap @@ -451,14 +452,21 @@ fun PlaylistTrackListItem( } } - val borderModifier = if (item.isPlaying) { - Modifier.border( + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary + + val borderModifier = when { + isFocused -> Modifier.border( + width = 2.5.dp, + color = primary, + shape = RoundedCornerShape(12.dp), + ) + item.isPlaying -> Modifier.border( width = 2.dp, brush = Brush.linearGradient(listOf(accentColor, accentSecondary)), shape = RoundedCornerShape(12.dp), ) - } else { - Modifier + else -> Modifier } Surface( @@ -468,13 +476,14 @@ fun PlaylistTrackListItem( horizontal = MaterialTheme.spacing.medium, vertical = MaterialTheme.spacing.extraSmall, ) + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } .clip(RoundedCornerShape(12.dp)) .then(borderModifier) .clickable(onClick = onClick), - color = if (item.isPlaying) { - MaterialTheme.colorScheme.tertiary.copy(alpha = 0.15f) - } else { - Color.Transparent + color = when { + isFocused -> primary.copy(alpha = 0.2f) + item.isPlaying -> MaterialTheme.colorScheme.tertiary.copy(alpha = 0.15f) + else -> Color.Transparent }, shape = RoundedCornerShape(12.dp), ) { diff --git a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/SubtitleTracksSheet.kt b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/SubtitleTracksSheet.kt index d384a566..c699d945 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/SubtitleTracksSheet.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/player/controls/components/sheets/SubtitleTracksSheet.kt @@ -1,13 +1,22 @@ package app.aryan447.mpvium.ui.player.controls.components.sheets +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource @@ -16,6 +25,7 @@ import androidx.compose.ui.unit.dp import app.aryan447.mpvium.R import app.aryan447.mpvium.ui.player.TrackNode import app.aryan447.mpvium.ui.theme.spacing +import app.aryan447.mpvium.ui.utils.LocalIsTv import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList @@ -59,23 +69,41 @@ fun SubtitlesSheet( list.toImmutableList() } + val isTv = LocalIsTv.current + val initialFocusRequester = remember { FocusRequester() } + + LaunchedEffect(Unit) { + if (isTv) { + try { + initialFocusRequester.requestFocus() + } catch (_: Exception) {} + } + } + GenericTracksSheet( tracks = items, onDismissRequest = onDismissRequest, header = { AddTrackRow( - stringResource(R.string.player_sheets_add_ext_sub), - onAddSubtitle, + title = stringResource(R.string.player_sheets_add_ext_sub), + onClick = onAddSubtitle, + focusRequester = initialFocusRequester, actions = { - IconButton(onClick = onOpenOnlineSearch) { - Icon(Icons.Default.Search, null) - } - IconButton(onClick = onOpenSubtitleSettings) { - Icon(Icons.Default.Palette, null) - } - IconButton(onClick = onOpenSubtitleDelay) { - Icon(Icons.Default.MoreTime, null) - } + SheetActionButton( + icon = Icons.Default.Search, + contentDescription = stringResource(R.string.search), + onClick = onOpenOnlineSearch, + ) + SheetActionButton( + icon = Icons.Default.Palette, + contentDescription = "Subtitle Settings", + onClick = onOpenSubtitleSettings, + ) + SheetActionButton( + icon = Icons.Default.MoreTime, + contentDescription = "Subtitle Delay", + onClick = onOpenSubtitleDelay, + ) }, ) }, @@ -118,10 +146,22 @@ fun SubtitlesSheet( footer = { if (onForgetSubtitleSettings != null) { val haptic = LocalHapticFeedback.current + var isForgetFocused by remember { mutableStateOf(false) } + val errorColor = MaterialTheme.colorScheme.error Row( modifier = Modifier .fillMaxWidth() + .onFocusChanged { isForgetFocused = it.isFocused } + .clip(RoundedCornerShape(12.dp)) + .background(if (isForgetFocused) errorColor.copy(alpha = 0.15f) else Color.Transparent) + .then( + if (isForgetFocused) { + Modifier.border(BorderStroke(2.dp, errorColor), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) .clickable(onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onForgetSubtitleSettings() @@ -135,12 +175,12 @@ fun SubtitlesSheet( Icons.Default.RestartAlt, contentDescription = null, modifier = Modifier.size(24.dp), - tint = MaterialTheme.colorScheme.error, + tint = errorColor, ) Text( text = stringResource(R.string.player_sheets_forget_subtitle_settings), style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.error, + color = errorColor, modifier = Modifier.weight(1f), ) } @@ -161,12 +201,27 @@ fun SubtitleTrackRow( modifier: Modifier = Modifier, ) { val haptic = LocalHapticFeedback.current + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary val tickToggle = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onToggle() } Row( - modifier = modifier.fillMaxWidth().clickable(onClick = tickToggle).padding(horizontal = MaterialTheme.spacing.medium, vertical = MaterialTheme.spacing.extraSmall), + modifier = modifier + .fillMaxWidth() + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .clip(RoundedCornerShape(12.dp)) + .background(if (isFocused) primary.copy(alpha = 0.15f) else Color.Transparent) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) + .clickable(onClick = tickToggle) + .padding(horizontal = MaterialTheme.spacing.medium, vertical = MaterialTheme.spacing.extraSmall), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), ) { diff --git a/app/src/main/java/app/aryan447/mpvium/ui/preferences/CardPreferences.kt b/app/src/main/java/app/aryan447/mpvium/ui/preferences/CardPreferences.kt index ae01ec4d..4cf3bbc4 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/preferences/CardPreferences.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/preferences/CardPreferences.kt @@ -1,8 +1,11 @@ package app.aryan447.mpvium.ui.preferences +import androidx.compose.animation.core.animateFloatAsState import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -14,6 +17,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.automirrored.outlined.ArrowBack @@ -35,9 +39,15 @@ import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.composed import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape @@ -58,6 +68,7 @@ import app.aryan447.mpvium.ui.theme.glassRimStroke import app.aryan447.mpvium.ui.theme.glassSheen import app.aryan447.mpvium.ui.theme.rememberGlassHazeState import app.aryan447.mpvium.ui.utils.LocalBackStack +import app.aryan447.mpvium.ui.utils.tvFocusHighlight val SettingsCardShape = RoundedCornerShape(28.dp) val SettingsTileCorner = 24.dp @@ -68,6 +79,8 @@ private val IconBoxShape = RoundedCornerShape(SettingsIconBoxCorner) /** * Premium card container for grouped preferences. + * Constrained on wide screens and TV displays so controls remain easy + * to navigate and comfortable to read. * Non-glass theme gets a hairline outline + soft tonal fill so groups * read as layered surfaces; glass theme keeps its specular treatment. */ @@ -78,26 +91,32 @@ fun PreferenceCard( ) { val isGlass = LocalGlass.current val dark = androidx.compose.foundation.isSystemInDarkTheme() - Card( - modifier = modifier - .fillMaxWidth() - .padding(horizontal = 16.dp, vertical = 8.dp) - .glassSheen(SettingsCardShape, isGlass), - shape = SettingsCardShape, - colors = if (isGlass) glassCardColors() else CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceContainer, - ), - border = if (isGlass) glassRimStroke(dark) else BorderStroke( - 1.dp, - MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f), - ), - elevation = CardDefaults.cardElevation(defaultElevation = 0.dp), + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.Center, ) { - Column( - modifier = Modifier.padding(vertical = 6.dp), - verticalArrangement = Arrangement.spacedBy(0.dp), + Card( + modifier = modifier + .fillMaxWidth() + .widthIn(max = 880.dp) + .padding(horizontal = 16.dp, vertical = 8.dp) + .glassSheen(SettingsCardShape, isGlass), + shape = SettingsCardShape, + colors = if (isGlass) glassCardColors() else CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer, + ), + border = if (isGlass) glassRimStroke(dark) else BorderStroke( + 1.dp, + MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f), + ), + elevation = CardDefaults.cardElevation(defaultElevation = 0.dp), ) { - content() + Column( + modifier = Modifier.padding(vertical = 6.dp), + verticalArrangement = Arrangement.spacedBy(0.dp), + ) { + content() + } } } } @@ -126,34 +145,41 @@ fun PreferenceSectionHeader( modifier: Modifier = Modifier, count: Int? = null, ) { - Row( - modifier = modifier - .padding(horizontal = 24.dp) - .padding(top = 20.dp, bottom = 8.dp), - verticalAlignment = Alignment.CenterVertically, + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.Center, ) { - Text( - text = title.uppercase(), - style = MaterialTheme.typography.labelLarge.copy(letterSpacing = 1.4.sp), - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f, fill = false), - ) - if (count != null && count > 0) { - Spacer(modifier = Modifier.width(8.dp)) - Surface( - shape = CircleShape, - color = MaterialTheme.colorScheme.primaryContainer, - ) { - Text( - text = count.toString(), - style = MaterialTheme.typography.labelSmall, - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onPrimaryContainer, - modifier = Modifier.padding(horizontal = 9.dp, vertical = 3.dp), - ) + Row( + modifier = modifier + .fillMaxWidth() + .widthIn(max = 880.dp) + .padding(horizontal = 24.dp) + .padding(top = 20.dp, bottom = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = title.uppercase(), + style = MaterialTheme.typography.labelLarge.copy(letterSpacing = 1.4.sp), + fontWeight = FontWeight.Bold, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f, fill = false), + ) + if (count != null && count > 0) { + Spacer(modifier = Modifier.width(8.dp)) + Surface( + shape = CircleShape, + color = MaterialTheme.colorScheme.primaryContainer, + ) { + Text( + text = count.toString(), + style = MaterialTheme.typography.labelSmall, + fontWeight = FontWeight.Bold, + color = MaterialTheme.colorScheme.onPrimaryContainer, + modifier = Modifier.padding(horizontal = 9.dp, vertical = 3.dp), + ) + } } } } @@ -165,12 +191,24 @@ fun PreferenceSectionHeader( @Composable private fun SettingsBackButton(onBack: (() -> Unit)?) { val backstack = LocalBackStack.current - IconButton(onClick = { onBack?.invoke() ?: backstack.removeLastOrNull() }) { + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary + IconButton( + onClick = { onBack?.invoke() ?: backstack.removeLastOrNull() }, + modifier = Modifier.onFocusChanged { isFocused = it.isFocused || it.hasFocus }, + ) { Box( modifier = Modifier .size(40.dp) .clip(CircleShape) .background(MaterialTheme.colorScheme.surfaceContainerHighest) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, primary), CircleShape) + } else { + Modifier + } + ) .padding(8.dp), contentAlignment = Alignment.Center, ) { @@ -352,6 +390,44 @@ fun PreferenceRowIcon( ) } +/** + * Focus highlight for preference rows inside [PreferenceCard]. + * Highlights the row with a rounded border and subtle primary tint when + * focused by D-pad or keyboard navigation on TV and desktop. + */ +@Composable +fun Modifier.preferenceItemFocusHighlight( + shape: Shape = RoundedCornerShape(16.dp), +): Modifier = composed { + var isFocused by remember { mutableStateOf(false) } + val focusBorderAlpha by animateFloatAsState( + targetValue = if (isFocused) 1f else 0f, + animationSpec = MaterialTheme.motionScheme.fastEffectsSpec(), + label = "prefItemBorder", + ) + val focusBgAlpha by animateFloatAsState( + targetValue = if (isFocused) 0.12f else 0f, + animationSpec = MaterialTheme.motionScheme.fastEffectsSpec(), + label = "prefItemBg", + ) + val primary = MaterialTheme.colorScheme.primary + + this + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .clip(shape) + .background(primary.copy(alpha = focusBgAlpha)) + .then( + if (focusBorderAlpha > 0f) { + Modifier.border( + BorderStroke(2.dp, primary.copy(alpha = focusBorderAlpha)), + shape = shape, + ) + } else { + Modifier + } + ) +} + /** * A switch preference row that plays a haptic tick on toggle. * Same API as the underlying library switch. @@ -374,7 +450,7 @@ fun HapticSwitchPreference( onValueChange(it) }, title = title, - modifier = modifier, + modifier = modifier.preferenceItemFocusHighlight(), enabled = enabled, summary = summary, icon = icon, @@ -396,14 +472,24 @@ fun SettingsPreferenceRow( onClick: () -> Unit, ) { val haptic = LocalHapticFeedback.current + val interactionSource = remember { MutableInteractionSource() } Row( modifier = modifier .fillMaxWidth() - .clickable(onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onClick() - }) + .tvFocusHighlight( + shape = SettingsTileShape, + interactionSource = interactionSource, + scale = 1.02f, + ) + .clickable( + interactionSource = interactionSource, + indication = null, + onClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onClick() + }, + ) .padding(horizontal = 16.dp, vertical = 12.dp), verticalAlignment = Alignment.CenterVertically, ) { @@ -480,17 +566,24 @@ fun SettingsSearchResultRow( modifier: Modifier = Modifier, ) { val scheme = MaterialTheme.colorScheme + var isFocused by remember { mutableStateOf(false) } val titleText = preference.titleRes?.let { stringResource(it) } ?: preference.title.orEmpty() val summaryText = preference.summaryRes?.let { stringResource(it) } ?: preference.summary Surface( modifier = modifier .fillMaxWidth() .padding(horizontal = 16.dp, vertical = 4.dp) + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } .clip(SettingsCardShape) .clickable(onClick = onClick), shape = SettingsCardShape, - color = scheme.surfaceContainer, - border = BorderStroke(1.dp, scheme.outlineVariant.copy(alpha = 0.4f)), + color = if (isFocused) scheme.surfaceContainerHighest else scheme.surfaceContainer, + border = if (isFocused) { + BorderStroke(2.dp, scheme.primary) + } else { + BorderStroke(1.dp, scheme.outlineVariant.copy(alpha = 0.4f)) + }, + shadowElevation = if (isFocused) 6.dp else 0.dp, ) { Row( modifier = Modifier diff --git a/app/src/main/java/app/aryan447/mpvium/ui/preferences/ExpressiveListPreference.kt b/app/src/main/java/app/aryan447/mpvium/ui/preferences/ExpressiveListPreference.kt index 15226de0..e2d60085 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/preferences/ExpressiveListPreference.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/preferences/ExpressiveListPreference.kt @@ -1,15 +1,19 @@ package app.aryan447.mpvium.ui.preferences import androidx.compose.animation.animateColorAsState +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.selection.selectable import androidx.compose.foundation.selection.selectableGroup +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.BottomSheetDefaults import androidx.compose.material3.ExperimentalMaterial3Api @@ -25,12 +29,14 @@ import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback @@ -65,7 +71,7 @@ fun ExpressiveListPreference( Preference( title = title, - modifier = modifier, + modifier = modifier.preferenceItemFocusHighlight(), enabled = enabled, icon = icon, summary = summary, @@ -87,7 +93,7 @@ fun ExpressiveListPreference( /** * The picker sheet. Rows are grouped into one rounded surface so the list * reads as a connected choice group; tapping a row updates the preference and - * dismisses the sheet. + * dismisses the sheet. Constrained on TV and tablets so choices don't stretch. */ @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -109,50 +115,56 @@ private fun ExpressiveChoiceSheet( dragHandle = { BottomSheetDefaults.DragHandle() }, containerColor = glassSheetContainerColor(MaterialTheme.colorScheme.surfaceContainerLow), ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(start = 24.dp, end = 24.dp, top = 8.dp, bottom = 24.dp) - .verticalScroll(rememberScrollState()), + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.Center, ) { - ProvideTextStyle( - value = MaterialTheme.typography.headlineSmall.copy(fontWeight = FontWeight.SemiBold), - ) { - Box( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 4.dp, vertical = 8.dp), - ) { - title() - } - } - Column( modifier = Modifier .fillMaxWidth() - .clip(SettingsCardShape) - .background(MaterialTheme.colorScheme.surfaceContainerHigh) - .selectableGroup(), + .widthIn(max = 640.dp) + .padding(start = 24.dp, end = 24.dp, top = 8.dp, bottom = 24.dp) + .verticalScroll(rememberScrollState()), ) { - values.forEachIndexed { index, option -> - ExpressiveChoiceRow( - selected = option == value, - text = valueToText(option), - onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onValueChange(option) - scope.launch { - sheetState.hide() - onDismiss() - } - }, - ) - if (index < values.lastIndex) { - HorizontalDivider( - modifier = Modifier.padding(start = 20.dp), - thickness = 0.75.dp, - color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f), + ProvideTextStyle( + value = MaterialTheme.typography.headlineSmall.copy(fontWeight = FontWeight.SemiBold), + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 4.dp, vertical = 8.dp), + ) { + title() + } + } + + Column( + modifier = Modifier + .fillMaxWidth() + .clip(SettingsCardShape) + .background(MaterialTheme.colorScheme.surfaceContainerHigh) + .selectableGroup(), + ) { + values.forEachIndexed { index, option -> + ExpressiveChoiceRow( + selected = option == value, + text = valueToText(option), + onClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onValueChange(option) + scope.launch { + sheetState.hide() + onDismiss() + } + }, ) + if (index < values.lastIndex) { + HorizontalDivider( + modifier = Modifier.padding(start = 20.dp), + thickness = 0.75.dp, + color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f), + ) + } } } } @@ -168,13 +180,22 @@ private fun ExpressiveChoiceRow( onClick: () -> Unit, ) { val scheme = MaterialTheme.colorScheme + var isFocused by remember { mutableStateOf(false) } val containerColor by animateColorAsState( - targetValue = if (selected) scheme.secondaryContainer else Color.Transparent, + targetValue = when { + isFocused -> scheme.primaryContainer + selected -> scheme.secondaryContainer + else -> Color.Transparent + }, animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(), label = "choiceRowContainer", ) val contentColor by animateColorAsState( - targetValue = if (selected) scheme.onSecondaryContainer else scheme.onSurface, + targetValue = when { + isFocused -> scheme.onPrimaryContainer + selected -> scheme.onSecondaryContainer + else -> scheme.onSurface + }, animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(), label = "choiceRowContent", ) @@ -182,7 +203,15 @@ private fun ExpressiveChoiceRow( Row( modifier = Modifier .fillMaxWidth() + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } .background(containerColor) + .then( + if (isFocused) { + Modifier.border(BorderStroke(2.dp, scheme.primary), RoundedCornerShape(12.dp)) + } else { + Modifier + } + ) .selectable( selected = selected, onClick = onClick, diff --git a/app/src/main/java/app/aryan447/mpvium/ui/preferences/PreferencesScreen.kt b/app/src/main/java/app/aryan447/mpvium/ui/preferences/PreferencesScreen.kt index 2d61c1ba..11cf3628 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/preferences/PreferencesScreen.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/preferences/PreferencesScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -26,6 +27,7 @@ import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -33,6 +35,7 @@ import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape @@ -148,17 +151,24 @@ object PreferencesScreen : Screen { }, ) { padding -> ProvidePreferenceLocals { - Column( + Box( modifier = Modifier .fillMaxSize() .padding(padding) .nestedScroll(scrollBehavior.nestedScrollConnection), + contentAlignment = Alignment.TopCenter, ) { - DashboardSearchField( - query = query, - onQueryChange = { query = it }, - modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), - ) + Column( + modifier = Modifier + .fillMaxHeight() + .widthIn(max = 1100.dp) + .fillMaxWidth(), + ) { + DashboardSearchField( + query = query, + onQueryChange = { query = it }, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), + ) AnimatedContent( targetState = isSearching, @@ -214,6 +224,7 @@ object PreferencesScreen : Screen { } } } +} @Composable private fun rememberDashboardSections(): List { @@ -451,18 +462,23 @@ private fun DashboardTile( val dark = androidx.compose.foundation.isSystemInDarkTheme() val interaction = remember { MutableInteractionSource() } val pressed by interaction.collectIsPressedAsState() + val isFocused by interaction.collectIsFocusedAsState() val scale by animateFloatAsState( - targetValue = if (pressed) 0.965f else 1f, + targetValue = when { + pressed -> 0.965f + isFocused -> 1.05f + else -> 1f + }, animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), label = "tilePress", ) val tileCorner by animateDpAsState( - targetValue = if (pressed) SettingsTilePressedCorner else SettingsTileCorner, + targetValue = if (pressed || isFocused) SettingsTilePressedCorner else SettingsTileCorner, animationSpec = MaterialTheme.motionScheme.defaultSpatialSpec(), label = "tileCorner", ) val iconCorner by animateDpAsState( - targetValue = if (pressed) 52.dp / 2 else SettingsIconBoxCorner, + targetValue = if (pressed || isFocused) 52.dp / 2 else SettingsIconBoxCorner, animationSpec = MaterialTheme.motionScheme.defaultSpatialSpec(), label = "tileIconCorner", ) @@ -482,14 +498,22 @@ private fun DashboardTile( }, ), shape = tileShape, - colors = if (isGlass) glassCardColors() else CardDefaults.cardColors( - containerColor = scheme.surfaceContainer, - ), - border = if (isGlass) glassRimStroke(dark) else BorderStroke( - 1.dp, - scheme.outlineVariant.copy(alpha = 0.45f), - ), - elevation = CardDefaults.cardElevation(defaultElevation = 0.dp), + colors = if (isGlass) { + glassCardColors() + } else { + CardDefaults.cardColors( + containerColor = if (isFocused) scheme.surfaceContainerHighest else scheme.surfaceContainer, + ) + }, + border = when { + isFocused -> BorderStroke(2.5.dp, scheme.primary) + isGlass -> glassRimStroke(dark) + else -> BorderStroke( + 1.dp, + scheme.outlineVariant.copy(alpha = 0.45f), + ) + }, + elevation = CardDefaults.cardElevation(defaultElevation = if (isFocused) 8.dp else 0.dp), ) { Column( modifier = Modifier.padding(18.dp), @@ -508,13 +532,13 @@ private fun DashboardTile( modifier = Modifier .size(28.dp) .clip(CircleShape) - .background(scheme.surfaceContainerHighest), + .background(if (isFocused) scheme.primary else scheme.surfaceContainerHighest), contentAlignment = Alignment.Center, ) { Icon( imageVector = Icons.AutoMirrored.Filled.ArrowForwardIos, contentDescription = null, - tint = scheme.onSurfaceVariant, + tint = if (isFocused) scheme.onPrimary else scheme.onSurfaceVariant, modifier = Modifier.size(18.dp), ) } diff --git a/app/src/main/java/app/aryan447/mpvium/ui/preferences/components/ThemePreviewCard.kt b/app/src/main/java/app/aryan447/mpvium/ui/preferences/components/ThemePreviewCard.kt index 00e61269..4e6d9bc8 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/preferences/components/ThemePreviewCard.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/preferences/components/ThemePreviewCard.kt @@ -1,8 +1,10 @@ package app.aryan447.mpvium.ui.preferences.components +import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.border -import androidx.compose.foundation.gestures.detectTapGestures +import androidx.compose.foundation.clickable +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -23,13 +25,17 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.shadow +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color -import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign @@ -95,6 +101,7 @@ fun CustomThemePreviewCard( ) } +@OptIn(ExperimentalFoundationApi::class) @Composable private fun ThemePreviewCardContent( colorScheme: ColorScheme, @@ -107,20 +114,29 @@ private fun ThemePreviewCardContent( ) { // Use the current MaterialTheme primary for selection to ensure visibility val selectionColor = MaterialTheme.colorScheme.primary + var isFocused by remember { mutableStateOf(false) } - val borderWidth = if (isSelected) 3.dp else 1.dp - val borderColor = if (isSelected) selectionColor else Color.Transparent - val elevation = if (isSelected) 8.dp else 2.dp + val borderWidth = when { + isFocused -> 3.dp + isSelected -> 3.dp + else -> 1.dp + } + val borderColor = when { + isFocused -> selectionColor + isSelected -> selectionColor + else -> Color.Transparent + } + val elevation = if (isSelected || isFocused) 8.dp else 2.dp Column( modifier = modifier .width(ThemeCardColumnWidth) - .pointerInput(onClick, onLongClick) { - detectTapGestures( - onTap = { onClick() }, - onLongPress = if (onLongClick != null) { { onLongClick() } } else null, - ) - }, + .clip(RoundedCornerShape(ThemeCardCorner)) + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .combinedClickable( + onClick = onClick, + onLongClick = onLongClick, + ), horizontalAlignment = Alignment.CenterHorizontally, ) { // Theme preview card @@ -247,25 +263,25 @@ fun ThemeStudioCard( modifier: Modifier = Modifier, ) { val cardShape = RoundedCornerShape(ThemeCardCorner) + var isFocused by remember { mutableStateOf(false) } + val primary = MaterialTheme.colorScheme.primary Column( modifier = modifier .width(ThemeCardColumnWidth) - .pointerInput(Unit) { - detectTapGestures { - onClick() - } - }, + .clip(cardShape) + .onFocusChanged { isFocused = it.isFocused || it.hasFocus } + .clickable(onClick = onClick), horizontalAlignment = Alignment.CenterHorizontally, ) { Box( modifier = Modifier .size(width = ThemeCardWidth, height = ThemeCardHeight) .shadow( - elevation = 2.dp, + elevation = if (isFocused) 8.dp else 2.dp, shape = cardShape, - ambientColor = Color.Black.copy(alpha = 0.2f), - spotColor = Color.Black.copy(alpha = 0.2f), + ambientColor = if (isFocused) primary.copy(alpha = 0.3f) else Color.Black.copy(alpha = 0.2f), + spotColor = if (isFocused) primary.copy(alpha = 0.3f) else Color.Black.copy(alpha = 0.2f), ) .clip(cardShape) .background( @@ -277,8 +293,8 @@ fun ThemeStudioCard( ) ) .border( - width = 1.dp, - color = Color.Transparent, + width = if (isFocused) 3.dp else 1.dp, + color = if (isFocused) primary else Color.Transparent, shape = cardShape, ), contentAlignment = Alignment.Center, diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/ContinueWatchingRow.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/ContinueWatchingRow.kt index f70a0010..01aed836 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/ContinueWatchingRow.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/ContinueWatchingRow.kt @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape @@ -37,6 +38,7 @@ import app.aryan447.mpvium.ui.theme.glassFrostColor import app.aryan447.mpvium.ui.theme.glassMenuContainerColor import app.aryan447.mpvium.ui.theme.glassRimBrush import app.aryan447.mpvium.ui.theme.glassSheen +import app.aryan447.mpvium.ui.utils.tvFocusHighlight import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -129,13 +131,21 @@ fun ContinueWatchingCard( val haptic = LocalHapticFeedback.current var showMenu by remember { mutableStateOf(false) } val hasMenu = onRemove != null || onMarkAs != null + val interactionSource = remember { MutableInteractionSource() } Box(modifier = modifier.width(cardWidth)) { Column( modifier = Modifier .fillMaxWidth() + .tvFocusHighlight( + shape = RoundedCornerShape(14.dp), + interactionSource = interactionSource, + scale = 1.05f, + ) .clip(RoundedCornerShape(14.dp)) .combinedClickable( + interactionSource = interactionSource, + indication = null, onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onClick() diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/MoviePosterCard.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/MoviePosterCard.kt index 2b5263da..10eb79de 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/MoviePosterCard.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/MoviePosterCard.kt @@ -37,13 +37,16 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.foundation.border +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.runtime.remember import app.aryan447.mpvium.domain.streaming.model.LocalMovie import app.aryan447.mpvium.ui.theme.AppTheme import app.aryan447.mpvium.ui.theme.LocalAppTheme import app.aryan447.mpvium.ui.theme.LocalGlass import app.aryan447.mpvium.ui.theme.cinemaFilmStrip import app.aryan447.mpvium.ui.theme.glassRimBrush +import app.aryan447.mpvium.ui.utils.tvFocusHighlight @OptIn(ExperimentalFoundationApi::class) @Composable @@ -56,12 +59,20 @@ fun MoviePosterCard( ) { val isCinema = LocalAppTheme.current == AppTheme.Cinema val haptic = LocalHapticFeedback.current + val interactionSource = remember { MutableInteractionSource() } Column( modifier = modifier .width(cardWidth) + .tvFocusHighlight( + shape = RoundedCornerShape(14.dp), + interactionSource = interactionSource, + scale = 1.06f, + ) .clip(RoundedCornerShape(14.dp)) .combinedClickable( + interactionSource = interactionSource, + indication = null, onClick = { haptic.performHapticFeedback(HapticFeedbackType.LongPress) onClick() diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/SeriesPosterCard.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/SeriesPosterCard.kt index 5a21e59d..0d5f9243 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/SeriesPosterCard.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/components/SeriesPosterCard.kt @@ -37,7 +37,9 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.foundation.border +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.runtime.remember import app.aryan447.mpvium.domain.streaming.model.LocalEpisode import app.aryan447.mpvium.domain.streaming.model.LocalSeries import app.aryan447.mpvium.ui.theme.AppTheme @@ -45,6 +47,7 @@ import app.aryan447.mpvium.ui.theme.LocalAppTheme import app.aryan447.mpvium.ui.theme.LocalGlass import app.aryan447.mpvium.ui.theme.cinemaFilmStrip import app.aryan447.mpvium.ui.theme.glassRimBrush +import app.aryan447.mpvium.ui.utils.tvFocusHighlight @Composable fun SeriesPosterCard( @@ -82,15 +85,25 @@ private fun SeriesPosterCard( ) { val isCinema = LocalAppTheme.current == AppTheme.Cinema val haptic = LocalHapticFeedback.current + val interactionSource = remember { MutableInteractionSource() } Column( modifier = modifier .width(cardWidth) + .tvFocusHighlight( + shape = RoundedCornerShape(14.dp), + interactionSource = interactionSource, + scale = 1.06f, + ) .clip(RoundedCornerShape(14.dp)) - .clickable(onClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - onClick() - }), + .clickable( + interactionSource = interactionSource, + indication = null, + onClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + onClick() + }, + ), ) { // Poster (2:3 Aspect Ratio) val isGlass = LocalGlass.current diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/home/StreamingHomeScreen.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/home/StreamingHomeScreen.kt index 75730450..d7bd88ff 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/home/StreamingHomeScreen.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/home/StreamingHomeScreen.kt @@ -7,9 +7,11 @@ import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically import androidx.compose.animation.togetherWith +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -246,32 +248,66 @@ object StreamingHomeScreen : Screen { }, actions = { val dark = isSystemInDarkTheme() + val primary = MaterialTheme.colorScheme.primary val iconGlass = Modifier .clip(CircleShape) .background(glassFrostColor(isDark = dark, kind = GlassKind.Chip)) .border(1.dp, glassRimColor(dark), CircleShape) .glassSheen(CircleShape, true) + + var refreshFocused by remember { mutableStateOf(false) } IconButton( onClick = { viewModel.refreshMetadata() }, - modifier = if (isGlass) iconGlass else Modifier, + modifier = (if (isGlass) iconGlass else Modifier) + .onFocusChanged { refreshFocused = it.isFocused || it.hasFocus } + .clip(CircleShape) + .then( + if (refreshFocused) { + Modifier + .background(primary.copy(alpha = 0.2f), CircleShape) + .border(BorderStroke(2.dp, primary), CircleShape) + } else Modifier + ), colors = androidx.compose.material3.IconButtonDefaults.iconButtonColors( contentColor = glassButtonContentColor(MaterialTheme.colorScheme.onSurface), ), ) { Icon(Icons.Filled.Refresh, contentDescription = "Refresh details") } + + var searchFocused by remember { mutableStateOf(false) } IconButton( onClick = { viewModel.setSearching(true) }, - modifier = if (isGlass) iconGlass else Modifier, + modifier = (if (isGlass) iconGlass else Modifier) + .onFocusChanged { searchFocused = it.isFocused || it.hasFocus } + .clip(CircleShape) + .then( + if (searchFocused) { + Modifier + .background(primary.copy(alpha = 0.2f), CircleShape) + .border(BorderStroke(2.dp, primary), CircleShape) + } else Modifier + ), colors = androidx.compose.material3.IconButtonDefaults.iconButtonColors( contentColor = glassButtonContentColor(MaterialTheme.colorScheme.onSurface), ), ) { Icon(Icons.Filled.Search, contentDescription = "Search") } + + var settingsFocused by remember { mutableStateOf(false) } IconButton( onClick = { backstack.add(PreferencesScreen) }, - modifier = if (isGlass) iconGlass else Modifier, + modifier = (if (isGlass) iconGlass else Modifier) + .onFocusChanged { settingsFocused = it.isFocused || it.hasFocus } + .clip(CircleShape) + .then( + if (settingsFocused) { + Modifier + .background(primary.copy(alpha = 0.2f), CircleShape) + .border(BorderStroke(2.dp, primary), CircleShape) + } else Modifier + ), colors = androidx.compose.material3.IconButtonDefaults.iconButtonColors( contentColor = glassButtonContentColor(MaterialTheme.colorScheme.onSurface), ), diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/movies/MoviesGridScreen.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/movies/MoviesGridScreen.kt index affba49f..e8513fdc 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/movies/MoviesGridScreen.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/movies/MoviesGridScreen.kt @@ -100,6 +100,7 @@ import app.aryan447.mpvium.ui.streaming.components.SortOption import app.aryan447.mpvium.ui.theme.rememberGlassHazeState import app.aryan447.mpvium.ui.utils.LocalBackStack import app.aryan447.mpvium.ui.utils.LocalDetailPaneBack +import app.aryan447.mpvium.ui.utils.LocalIsTv import app.aryan447.mpvium.utils.media.MediaLibraryEvents import app.aryan447.mpvium.utils.media.MediaUtils import app.aryan447.mpvium.utils.permission.PermissionUtils @@ -129,6 +130,7 @@ object MoviesGridScreen : Screen { val whitelistOnlyEnabled by foldersPreferences.whitelistOnlyEnabled.collectAsState() val whitelistedFolders by foldersPreferences.whitelistedFolders.collectAsState() val libraryFiltered = whitelistOnlyEnabled && whitelistedFolders.isNotEmpty() + val isTv = LocalIsTv.current val navigationBarHeight = LocalNavigationBarHeight.current val configuration = LocalConfiguration.current val isLandscape = configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE @@ -186,7 +188,7 @@ object MoviesGridScreen : Screen { // The scanner treats every non-episode file as a movie. Keep reels, // trailers, social exports and personal clips out of the Movies grid; // they are not deleted or moved, and Folders still lists every file. - val libraryMovies = detected.movies.filter { MovieLibraryClassifier.isMovieLibraryItem(it) } + val libraryMovies = detected.movies.filter { MovieLibraryClassifier.isMovieLibraryItem(it, isTv = isTv) } // Drop cached TMDB entries for deleted movies. // Remaining movies reuse their cache with no re-scrape. runCatching { diff --git a/app/src/main/java/app/aryan447/mpvium/ui/streaming/titles/TitlesScreen.kt b/app/src/main/java/app/aryan447/mpvium/ui/streaming/titles/TitlesScreen.kt index 6aef759a..810c9be3 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/streaming/titles/TitlesScreen.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/streaming/titles/TitlesScreen.kt @@ -106,6 +106,7 @@ import app.aryan447.mpvium.ui.theme.glassSearchBarColors import app.aryan447.mpvium.ui.theme.rememberGlassHazeState import app.aryan447.mpvium.ui.utils.LocalBackStack import app.aryan447.mpvium.ui.utils.LocalDetailPaneBack +import app.aryan447.mpvium.ui.utils.LocalIsTv import app.aryan447.mpvium.utils.media.MediaLibraryEvents import app.aryan447.mpvium.utils.permission.PermissionUtils import kotlinx.coroutines.Dispatchers @@ -149,6 +150,7 @@ data class TitlesScreen( val whitelistOnlyEnabled by foldersPreferences.whitelistOnlyEnabled.collectAsState() val whitelistedFolders by foldersPreferences.whitelistedFolders.collectAsState() val libraryFiltered = whitelistOnlyEnabled && whitelistedFolders.isNotEmpty() + val isTv = LocalIsTv.current val navigationBarHeight = LocalNavigationBarHeight.current val configuration = LocalConfiguration.current val isLandscape = configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE @@ -225,7 +227,7 @@ data class TitlesScreen( LaunchedEffect(refreshKey) { withContext(Dispatchers.IO) { val detected = libraryIndexRepository.getLibrary(force = isRefreshing.value) - val libraryMovies = detected.movies.filter { MovieLibraryClassifier.isMovieLibraryItem(it) } + val libraryMovies = detected.movies.filter { MovieLibraryClassifier.isMovieLibraryItem(it, isTv = isTv) } runCatching { metadataRepository.pruneStaleMetadata( diff --git a/app/src/main/java/app/aryan447/mpvium/ui/utils/CompositionLocales.kt b/app/src/main/java/app/aryan447/mpvium/ui/utils/CompositionLocales.kt index 95133614..5f73204a 100644 --- a/app/src/main/java/app/aryan447/mpvium/ui/utils/CompositionLocales.kt +++ b/app/src/main/java/app/aryan447/mpvium/ui/utils/CompositionLocales.kt @@ -15,3 +15,9 @@ val LocalBackStack: ProvidableCompositionLocal> = */ val LocalDetailPaneBack: ProvidableCompositionLocal<(() -> Unit)?> = compositionLocalOf { null } + +/** + * Indicates whether the app is currently running on an Android TV device. + */ +val LocalIsTv: ProvidableCompositionLocal = + compositionLocalOf { false } diff --git a/app/src/main/java/app/aryan447/mpvium/ui/utils/FocusUtils.kt b/app/src/main/java/app/aryan447/mpvium/ui/utils/FocusUtils.kt new file mode 100644 index 00000000..1d50f796 --- /dev/null +++ b/app/src/main/java/app/aryan447/mpvium/ui/utils/FocusUtils.kt @@ -0,0 +1,56 @@ +package app.aryan447.mpvium.ui.utils + +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.border +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp + +/** + * Modifier to provide TV / D-Pad friendly visual focus indication (scale + border ring) + * adhering to mpvium design tokens and motion specs. + */ +fun Modifier.tvFocusHighlight( + shape: Shape, + interactionSource: MutableInteractionSource, + scale: Float = 1.05f, + borderWidth: Dp = 2.dp, + borderColor: Color? = null, + enabled: Boolean = true, +): Modifier = composed { + if (!enabled) return@composed this + + val isFocused by interactionSource.collectIsFocusedAsState() + val animatedScale by animateFloatAsState( + targetValue = if (isFocused) scale else 1f, + animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(), + label = "tv_focus_scale", + ) + + val focusBorderColor = borderColor ?: MaterialTheme.colorScheme.primary + + this + .graphicsLayer { + scaleX = animatedScale + scaleY = animatedScale + } + .then( + if (isFocused) { + Modifier.border( + border = BorderStroke(borderWidth, focusBorderColor), + shape = shape, + ) + } else { + Modifier + }, + ) +} diff --git a/app/src/main/java/app/aryan447/mpvium/utils/DeviceUtils.kt b/app/src/main/java/app/aryan447/mpvium/utils/DeviceUtils.kt new file mode 100644 index 00000000..89a622e1 --- /dev/null +++ b/app/src/main/java/app/aryan447/mpvium/utils/DeviceUtils.kt @@ -0,0 +1,34 @@ +package app.aryan447.mpvium.utils + +import android.app.UiModeManager +import android.content.Context +import android.content.pm.PackageManager +import android.content.res.Configuration + +/** + * Utility helpers for detecting device types, such as Android TV / Google TV. + */ +object DeviceUtils { + private var isTvCached: Boolean? = null + + /** + * Returns true if the app is running on an Android TV, Google TV, or Fire TV device. + * Caches result to avoid repeated PackageManager queries. + */ + fun isTv(context: Context): Boolean { + isTvCached?.let { return it } + + val appContext = context.applicationContext ?: context + val uiModeManager = appContext.getSystemService(Context.UI_MODE_SERVICE) as? UiModeManager + val isTvMode = uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION + + val pm = appContext.packageManager + val hasLeanback = pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) + val hasFireTv = pm.hasSystemFeature("amazon.hardware.fire_tv") + val lacksTouchscreen = !pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN) + + val result = isTvMode || hasLeanback || hasFireTv || lacksTouchscreen + isTvCached = result + return result + } +} diff --git a/app/src/main/res/drawable/tv_banner.xml b/app/src/main/res/drawable/tv_banner.xml new file mode 100644 index 00000000..80bb08ea --- /dev/null +++ b/app/src/main/res/drawable/tv_banner.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/test/java/app/aryan447/mpvium/domain/streaming/MovieLibraryClassifierTest.kt b/app/src/test/java/app/aryan447/mpvium/domain/streaming/MovieLibraryClassifierTest.kt index a5ea6127..4073a7d6 100644 --- a/app/src/test/java/app/aryan447/mpvium/domain/streaming/MovieLibraryClassifierTest.kt +++ b/app/src/test/java/app/aryan447/mpvium/domain/streaming/MovieLibraryClassifierTest.kt @@ -344,4 +344,34 @@ class MovieLibraryClassifierTest { ), ) } + + @Test + fun landscapeDownloadUnderTwentyMinutes_onTv_staysMovie() { + assertEquals( + MOVIE, + MovieLibraryClassifier.classify( + fileName = "Big Buck Bunny.mp4", + folderPath = DOWNLOAD_FOLDER, + durationMs = 9 * MINUTE_MS + 56_000L, + width = 1920, + height = 1080, + isTv = true, + ), + ) + } + + @Test + fun veryShortDownloadUnderFiveMinutes_onTv_isShortVideo() { + assertEquals( + SHORT_VIDEO, + MovieLibraryClassifier.classify( + fileName = "Clip.mp4", + folderPath = DOWNLOAD_FOLDER, + durationMs = 3 * MINUTE_MS, + width = 1920, + height = 1080, + isTv = true, + ), + ) + } }