Legacy download UI flow
Overview
The legacy/original download page is rooted at app/…/DownloadPage.kt. DownloadPage composes the home screen, collects state from the shared singleton downloader (Downloader.downloaderState, Downloader.taskState, Downloader.errorState, Downloader.processCount, and Downloader.playlistResult), and collects local page state from HomePageViewModel.viewStateFlow and HomePageViewModel.videoInfoFlow. The visible page is rendered by DownloadPageImpl: a top app bar routes to settings, downloads history, and running tasks; the main body shows the app title, current download/playlist progress, the URL field, optional VideoCard progress, terminal output when debug output is enabled, and an expandable/copyable error report.
URL input state lives in HomePageViewModel.ViewState.url (HomePageViewModel.kt). The paste FAB in DownloadPage.kt reads the clipboard, passes it through matchUrlFromClipboard, and writes the result with HomePageViewModel.updateUrl. The URL text field writes every edit back through the same method. Shared intents are represented by ViewState.isUrlSharingTriggered; when DownloadPage sees it, it calls HomePageViewModel.onShareIntentConsumed() and then runs the legacy download callback.
There are two download-start paths in DownloadPage.kt:
- Normal page interaction (
DownloadPageImpl.downloadCallback) postsDownloadDialogViewModel.Action.ShowSheet()to the newerdownloadv2.configure.DownloadDialogflow. The bottom sheet is shown fromdialogViewModel.sheetValueFlow; its preferences are initialized fromDownloadUtil.DownloadPreferences.createFromPreferences(), and format-selection state may showdownloadv2.configure.FormatPage. - The legacy callback, still used for shared URLs, first handles notification permission prompts, then either opens
DownloadSettingDialogwhenCONFIGUREis enabled or proceeds through storage/network checks before callingHomePageViewModel.startDownloadVideo().
HomePageViewModel.startDownloadVideo() (HomePageViewModel.kt) is the legacy orchestrator for actual work. It clears downloader errors, optionally executes a custom command with DownloadUtil.executeCommandInBackground, checks downloader availability, validates that the URL is not blank, and then branches by preferences: PLAYLIST fetches playlist/video metadata via DownloadUtil.getPlaylistOrVideoInfo, FORMAT_SELECTION fetches video metadata via DownloadUtil.fetchVideoInfoFromUrl, and the default path calls Downloader.getInfoAndDownload(url). Playlist metadata is written to the shared downloader via Downloader.updatePlaylistResult; format metadata is written to videoInfoFlow.
Routing out of this package is controlled by callbacks supplied to DownloadPage. navigateToSettings, navigateToDownloads, and onNavigateToTaskList are top-bar actions. navigateToPlaylistPage is triggered by a DisposableEffect when ViewState.showPlaylistSelectionDialog is true and Downloader.playlistResult.entries is non-empty; disposal calls HomePageViewModel.hidePlaylistDialog(). navigateToFormatPage is triggered similarly when ViewState.showFormatSelectionPage is true and videoInfoFlow.formats is non-empty; disposal calls hideFormatPage(). onNavigateToCookieGeneratorPage is passed into DownloadSettingDialog and is invoked when a cookie profile is selected from its cookies quick settings.
Dialogs in this package are mostly small state gates around preferences and permissions:
- DownloadSettingsDialog.kt exposes
DownloadSettingDialog, the legacy “settings before download” surface. It chooses anAlertDialogon wider windows (useDialog) or a modal bottom sheet on compact screens, falling back to the Material 2 sheet on Android versions below 30. It mutates shared preferences such asEXTRACT_AUDIO,CUSTOM_COMMAND,PLAYLIST,FORMAT_SELECTION,VIDEO_FORMAT,VIDEO_QUALITY,COOKIES,SUBTITLE,THUMBNAIL,FORMAT_SORTING, and command template IDs, then callsonDownloadConfirmto resume permission/network checks. It also opens nested settings dialogs for video format, quality, cookies, audio conversion, format sorting, and command templates. - NotificationPermissionDialog.kt is shown on Android 13+ when notifications are enabled in preferences but
POST_NOTIFICATIONSis not granted. Dismissing it disables theNOTIFICATIONpreference; confirming launches the permission request. - MeteredNetworkDialog.kt is shown when
PreferenceUtil.isNetworkAvailableForDownload()rejects the current network. “Allow once” callsHomePageViewModel.startDownloadVideo(). “Allow always” also setsCELLULAR_DOWNLOADtrue. - PlaylistSelectionDialog.kt is a legacy range picker for a
PlaylistResult. It validates numericfrom/toinputs against the playlist entry count and returns anIntRangeon confirm. The current DownloadPage.kt routes playlist selection tonavigateToPlaylistPageinstead of rendering this dialog directly. - VideoSectionSlider.kt contains the video clip selection UI:
VideoSelectionSliderwraps a MaterialRangeSliderState, displays the selected start/end as duration text, and offers discard/edit actions;VideoClipDialogedits the same range with minute/second fields and validates that start < end within the supplied duration range.
Coupling
- If
HomePageViewModel.ViewStateflags change in app/…/HomePageViewModel.kt, update theDisposableEffectrouting in app/…/DownloadPage.kt. The page relies onshowPlaylistSelectionDialogandshowFormatSelectionPagebeing one-shot navigation signals that are cleared on disposal. - If playlist or format routing changes, verify both the shared downloader state and page-local state: DownloadPage.kt reads playlist entries from
Downloader.playlistResult, while format routing readsHomePageViewModel.videoInfoFlow.formats. - If download preference keys or meanings change, update both HomePageViewModel.kt and DownloadSettingsDialog.kt. The dialog mutates preferences such as
PLAYLIST,CUSTOM_COMMAND, andFORMAT_SELECTION, while the view model branches on those same preferences to choose the downloader path. - If notification, storage, or metered-network behavior changes in DownloadPage.kt, verify the legacy shared-intent path as well as the normal
DownloadDialogViewModel.Action.ShowSheet()path. They do not currently enter the same start-download code. - If video clipping range semantics change, update both
VideoSelectionSliderandVideoClipDialogin app/…/VideoSectionSlider.kt; one usesRangeSliderStatefloats and the other converts minute/second text to integer seconds.
Risks
- app/…/DownloadPage.kt has parallel start flows: normal FAB/keyboard interaction opens the newer download dialog, while shared intents use the legacy permission/configuration callback. If a permission, cellular, or configuration fix is applied to only one path, shared URLs and manually entered URLs can behave differently.
- app/…/DownloadSettingsDialog.kt writes global preferences immediately when chips are tapped, before the user presses “start download.” If the user cancels, changed preferences remain and can affect the next download.