Video Library and History
Overview
The downloaded media/history screen is the Route.DOWNLOADS destination. app/…/Route.kt names it download_history, app/…/AppEntry.kt registers that route with VideoListPage, and callers route there from the home download page's history button and the navigation drawer entries in app/…/DownloadPage.kt and app/…/NavigationDrawer.kt. When adding another entry point, navigate to Route.DOWNLOADS rather than constructing a separate route string, and pass back navigation through VideoListPage's onNavigateBack callback.
app/…/VideoListViewModel.kt owns the screen state and database-backed flows. It reads persisted download history through DatabaseUtil.getDownloadHistoryFlow(), reverses the DAO order, and sorts by DownloadedVideoInfo.filterByType() so audio and video groups are stable before UI filtering. The same view model combines the history flow with VideoListViewState for search over title, author, extractor, and file path; derives the extractor chip set from the searched list; and computes a fileSizeMapFlow on Dispatchers.IO by calling FileUtil.getFileSize() for each stored path.
app/…/VideoListPage.kt renders the history. It collects the full list, searched list, filter set, and file-size map, then displays a LazyColumn of MediaListItem rows from app/…/VideoListItem.kt. Each persisted item is a DownloadedVideoInfo record with title, author, source URL, thumbnail URL, local path, extractor, and Room id. The page keeps transient Compose state for the selected ids, the current item whose context menu is open, import/export dialogs, delete dialogs, and the Material bottom sheet state.
List interaction is split between normal and selection modes. In normal mode, tapping a row calls FileUtil.openFile(videoPath) and shows a file-unavailable toast if no ACTION_VIEW intent can be built. Long-press enables multi-select and selects the row. The row's overflow button stores that DownloadedVideoInfo as currentVideoInfo and opens VideoDetailDrawer from app/…/VideoDetailDrawer.kt. In selection mode, MediaListItem switches from combinedClickable to selectable, shows a checkbox, hides the overflow button, and the page shows a bottom app bar with a tri-state select-all checkbox, selected audio/video counts, selected file-size total, and a multi-remove action.
Filtering happens in VideoListPage.kt helpers on DownloadedVideoInfo. The audio/video chips test videoPath against com.junkfood.seal.util.AUDIO_REGEX from app/…/FileUtil.kt; extractor chips compare the stored extractor string; search is applied before extractor-chip derivation. MediaListItem has its own private audio-extension regex in VideoListItem.kt only for thumbnail aspect ratio, not for the page's filter semantics. File availability is represented as a non-zero file size in fileSizeMapFlow; unavailable items show the error color and unavailable label in the row.
The detail drawer in VideoDetailDrawer.kt presents selectable title/author text, the source URL, and item actions. Clicking the URL button copies the URL, long-clicking it opens the URL through LocalUriHandler, and delete dismisses the sheet before opening the remove confirmation. If the local file still exists, the primary action shares the file using FileUtil.createIntentForSharingFile(videoPath); if not, it sends an in-app ACTION_SEND intent containing info.videoUrl so the app can re-download the source.
Delete behavior has two confirmation paths. Single-item delete uses app/…/RemoveItemDialog.kt; multi-delete uses an inline SealDialog in VideoListPage.kt. Both offer an optional "delete file" checkbox. Confirmation calls VideoListViewModel.deleteDownloadHistory(), which delegates to DatabaseUtil.deleteInfoList(infoList, deleteFile) on Dispatchers.IO; the database rows are deleted first, and FileUtil.deleteFile(videoPath) is attempted for each item only when the checkbox is enabled.
Import/export is handled by app/…/ExportImportDialog.kt and the launchers in VideoListPage.kt. Export chooses either BackupType.DownloadHistory or BackupType.URLList, then writes to a SAF-created text document or copies to the clipboard. Full-history export serializes selected items when multi-select has ids; otherwise it serializes the currently visible, filtered list. VideoListPage.backupToString() reverses full-history exports before calling BackupUtil.toJsonString(), while URL-list export uses BackupUtil.toURLListString(). Import only accepts full backup JSON, sourced from a text file via GetContent("text/plain") or from the clipboard, then VideoListViewModel decodes it with BackupUtil.decodeToBackup() and imports only BackupType.DownloadHistory through DatabaseUtil.importBackup(). Completion is surfaced through a snackbar with the imported count.
app/…/VideoInfo.kt is the broader yt-dlp metadata model used by download and format flows that feed history records. VideoInfo, PlaylistResult, Format, RequestedDownload, Chapter, SubtitleFormat, and related helpers mirror serialized yt-dlp keys with @SerialName where needed. The history list itself persists the smaller DownloadedVideoInfo; use VideoInfo when parsing/examining extractor metadata, and map only the durable display/opening fields into history rows. Format and RequestedDownload expose audio/video capability helpers, and VideoClip converts floating-point ranges to rounded integer seconds.
app/…/VideoCard.kt is the card-style media display used by download/preview flows rather than the history list. It shows the thumbnail, title, author, approximate file size, duration, optional cancel button, and determinate or indeterminate progress. It uses the same display utilities (toFileSizeText, toDurationText) as history-adjacent UI, so file-size or duration formatting changes affect both in-progress cards and completed history rows. app/…/DateTimeUtil.kt provides Long.toLocalizedString() for timestamp rendering elsewhere: API 26+ uses localized DateFormat, older devices fall back to yyyy-MM-dd HH:mm:ss.
Coupling
- If
DownloadedVideoInfoin app/…/DownloadedVideoInfo.kt changes, update history rendering, search, filtering, export/import, and detail actions together: VideoListPage.kt assumes title/author/source URL/thumbnail/path/extractor fields, andBackupUtil.toJsonString()serializes the same model for round-trip backups. - If audio extension detection changes, keep
FileUtil.AUDIO_REGEX,DownloadedVideoInfo.filterByType()in VideoListPage.kt, and the privateAUDIO_REGEXin VideoListItem.kt aligned. The page regex controls filter semantics and selected audio/video counts; the row regex controls audio thumbnail shape. - If backup JSON shape or destinations change in app/…/BackupUtil.kt, update both ExportImportDialog.kt and VideoListViewModel.kt: the dialogs expose only full-history and URL-list export, while import always decodes a full
Backupand passes onlyBackupType.DownloadHistorytoDatabaseUtil.importBackup(). - If route names or navigation helpers change, verify
Route.DOWNLOADSin Route.kt, theNavHostregistration in AppEntry.kt, the home-page history button, and the navigation drawer entry together.VideoListPageis callback-based and does not know the nav controller, so all path routing belongs to those callers. - If file opening/sharing/deletion support changes in FileUtil.kt, check VideoListPage.kt, VideoDetailDrawer.kt, and VideoListViewModel.kt: list taps use
openFile, drawer sharing usescreateIntentForSharingFile, availability is inferred fromgetFileSize, and optional physical deletion usesdeleteFileafter database deletion.
Risks
- app/…/VideoListPage.kt stores selected rows as integer ids in a Compose list remembered from the current
videoListandviewState. If the backing history flow changes while selection mode is active, stale ids can remain selected until selection mode exits, so bulk delete/export may act on the intersection of stale ids and the newly collected list rather than the exact rows originally selected. - app/…/DatabaseUtil.kt deletes history rows before attempting
FileUtil.deleteFile()and does not surface delete failures. If a SAF document or filesystem path cannot be removed, the UI will still lose the history record and no retry path remains on this screen. - app/…/DatabaseUtil.kt de-duplicates imported history with
itemList.contains(it)before copying imported rows toid = 0. If an exported row returns with a different Room id but the same media fields, it may be treated as distinct and imported again.