Introducing a new way to review your PRs.

Read the announcement

junkfood02 / seal

🦭 Video/Audio Downloader for Android, based on yt-dlp

View on GitHub

13 documents · Updated Nov 16, 2026

docs / command-templates-and-task-log-ui

Command Templates and Task/Log UI

Overview

This area covers the Compose screens that let users manage custom command templates and launch/inspect command executions. The persistent template shape is CommandTemplate in app/…/CommandTemplate.kt: a Room entity and serializable data class with an auto-generated id, a user-facing name, and the raw command template string.

Template management has two entry styles:

  • app/…/TemplateListPage.kt is the full settings page for custom commands. It reads PreferenceUtil.templateListStateFlow for the template list, reads/writes the selected template through TEMPLATE_ID, and toggles the global CUSTOM_COMMAND preference. Each TemplateItem can open the edit route, mark a template as selected, or enter multi-select mode. The page also exports/imports templates through clipboard JSON via BackupUtil.exportTemplatesToJson() and DatabaseUtil.importTemplatesFromJson(), and deletes selected templates via DatabaseUtil.deleteTemplates().
  • app/…/TemplateEditPage.kt is the full-screen editor. It resolves templateId against PreferenceUtil.templateListStateFlow; templateId <= 0 creates a blank CommandTemplate(0, "", ""), while an existing id loads that template. The top-bar done action writes through DatabaseUtil.insertTemplate() when the entity id is 0, otherwise DatabaseUtil.updateTemplate(). The command body field is monospace, supports paste/clear, and can be extended by tapping shortcut chips loaded from DatabaseUtil.getShortcuts().

app/…/CommandTemplateDialog.kt provides the modal editor used from the task creation sheet. CommandTemplateDialog() mirrors the full editor but stays inside an AlertDialog: a blank/default CommandTemplate(0, "", "") creates a new row, an existing template updates in place, and confirmationCallback receives the inserted or updated template id so callers can immediately select it. The same file owns OptionChipsDialog(), which edits reusable command option shortcuts by collecting DatabaseUtil.getShortcuts(), inserting non-duplicate OptionShortcut rows, and deleting individual shortcuts from chips.

Task creation and execution state live in app/…/TaskListPage.kt. TaskListPage(onNavigateBack, onNavigateToDetail) renders Downloader.mutableTaskList.values, sorted by mapped TaskStatus, as CustomCommandTaskItems. The floating action button opens a bottom sheet that pre-fills the URL from clipboard using matchUrlFromString(), shows the currently selected template from PreferenceUtil.getTemplate(), and offers three template actions: pick an existing template (TemplatePickerDialog()), create a template (CommandTemplateDialog() with a callback that updates TEMPLATE_ID), or edit the current template (CommandTemplateDialog(commandTemplate = template)). Starting a task calls Downloader.executeCommandWithUrl(url) and dismisses the sheet.

Task log display is handled by app/…/TaskLogPage.kt. TaskLogPage(onNavigateBack, taskHashCode) finds the matching Downloader.mutableTaskList entry by hashCode() and renders task.output in a selectable monospace text area that auto-scrolls to the bottom. Its bottom action row delegates task operations to the task object: copy log, copy error report for error states, cancel for running states, restart for canceled/error states, and an expand toggle that enables horizontal scrolling for long log lines.

Path routing guidance: route the settings template list to TemplateListPage, and pass onNavigateToEditPage(id) to a route backed by TemplateEditPage(templateId = id); use -1 for “new template” because the editor treats non-positive ids as a blank entity. Route the running-task list to TaskListPage, and pass onNavigateToDetail(task.hashCode()) to a route backed by TaskLogPage(taskHashCode = value). The task log route is intentionally keyed by the in-memory task hash rather than a persisted database id, so it only works while the task remains in Downloader.mutableTaskList.

Coupling

  • If CommandTemplate in app/…/CommandTemplate.kt changes shape, update both persistence/import paths and every editor that constructs CommandTemplate(0, "", ""): TemplateEditPage.kt, CommandTemplateDialog.kt, and TaskListPage.kt all assume id == 0 means “new row” and that only name is required before save.
  • If template selection semantics change, verify TemplateListPage.kt, TemplatePickerDialog() in TaskListPage.kt, and the task creation bottom sheet together. They share the TEMPLATE_ID preference, but the full list uses PreferenceUtil.encodeInt() while picker/dialog callbacks use TEMPLATE_ID.updateInt().
  • If command execution task identity changes, update the navigation contract between TaskListPage.kt and TaskLogPage.kt. The list currently navigates with hashCode() and the log page searches Downloader.mutableTaskList.values.find { it.hashCode() == taskHashCode }; replacing tasks or changing equality/hash behavior can make the detail route fail silently.
  • If shortcut storage or display changes, check both TemplateEditPage.kt and CommandTemplateDialog.kt. The full editor appends shortcut options into the template text, while OptionChipsDialog() in the dialog file owns inserting/deleting the underlying shortcut rows.

Risks

  • app/…/TaskLogPage.kt returns immediately when no task matches taskHashCode. If a task is removed from Downloader.mutableTaskList before the log route opens, the user sees no fallback UI or navigation recovery.
  • app/…/TaskListPage.kt remembers the bottom-sheet template only when template dialogs open/close. If PreferenceUtil.getTemplate() changes from another path while the sheet remains open, the visible template chip may not refresh until one of those dialog state keys changes.