Skip to content

feat: Add download support for Non-DRM#12

Merged
syed-tp merged 3 commits intomainfrom
ui/add_download_bottom_sheet
Jun 13, 2025
Merged

feat: Add download support for Non-DRM#12
syed-tp merged 3 commits intomainfrom
ui/add_download_bottom_sheet

Conversation

@syed-tp
Copy link
Copy Markdown
Contributor

@syed-tp syed-tp commented Jun 12, 2025

Summary by CodeRabbit

  • New Features

    • Added video download support, including offline playback and download management within the player.
    • Introduced UI components for selecting download quality and managing downloads via bottom sheets.
    • Added download status indicators and actions (pause, resume, cancel, delete) in the player interface.
    • Integrated notifications for download progress and completion.
  • Bug Fixes

    • Improved handling of download permissions for newer Android versions.
  • Style

    • Updated and added new icons for download states.
    • Enhanced bottom sheet and player settings layouts to support download features.
  • Documentation

    • Added new string resources for download-related UI and notifications.
  • Chores

    • Updated app permissions to support download and notification features.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 12, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces comprehensive offline video download support to the Android player. It adds new UI components for download actions and options, integrates a download manager and supporting services, updates the player to enable offline playback, and expands resources and permissions to support the new functionality. Multiple new classes, layouts, and resources are included.

Changes

File(s) Change Summary
AndroidManifest.xml Added permissions for network, notifications, storage, and foreground service; declared TPSDownloadService.
.../player/DownloadActionBottomSheet.kt, .../player/DownloadOptionsBottomSheet.kt Added new bottom sheet UI components for download actions and resolution selection.
.../player/PlayerSettingsBottomSheet.kt Added "Download" option and related listener methods to settings UI.
.../player/TPStreamsPlayer.kt Added offline playback support, local download check, video bitrate querying, and cache-aware data source.
.../player/TPStreamsPlayerView.kt Integrated download management UI and logic, download state handling, and permission checks.
.../player/download/DownloadController.kt Added singleton controller for download manager lifecycle, download actions, and notification channel setup.
.../player/download/DownloadPermissionHandler.kt Added object for notification permission handling on Android Tiramisu+.
.../player/download/DownloadTracker.kt Added singleton class to track download states, progress, and manage listeners.
.../player/download/TPSDownloadService.kt Added foreground service for managing downloads and notifications.
.../res/drawable/ic_download.xml Updated download icon vector drawable.
.../res/drawable/ic_download_done.xml, .../res/drawable/ic_download_progress.xml Added new vector drawables for download done and download progress states.
.../res/layout/item_download_resolution.xml Added layout for download resolution item in options list.
.../res/layout/layout_download_action_bottom_sheet.xml Added layout for download action bottom sheet UI.
.../res/layout/layout_download_options_bottom_sheet.xml Added layout for download options bottom sheet UI.
.../res/layout/layout_player_settings_bottom_sheet.xml Renamed IDs for clarity; added download option section.
.../res/values/strings.xml Added string resources for download-related UI, states, and notifications.
.../res/values/styles.xml Added colorAccent to BottomSheetDialogTheme.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PlayerView
    participant DownloadOptionsBottomSheet
    participant DownloadActionBottomSheet
    participant DownloadController
    participant DownloadTracker
    participant TPSDownloadService

    User->>PlayerView: Clicks Download in Settings
    PlayerView->>DownloadTracker: Check download state for media URI
    alt Not downloaded
        PlayerView->>DownloadOptionsBottomSheet: Show resolution options
        User->>DownloadOptionsBottomSheet: Selects resolution and clicks Download
        DownloadOptionsBottomSheet->>PlayerView: onDownloadResolutionSelected(resolution)
        PlayerView->>DownloadController: startDownload(mediaItem, resolution)
        DownloadController->>TPSDownloadService: sendDownload(request)
    else Downloading/Paused/Completed
        PlayerView->>DownloadActionBottomSheet: Show download action sheet
        User->>DownloadActionBottomSheet: Selects action (Pause/Resume/Delete/Cancel)
        DownloadActionBottomSheet->>PlayerView: onPause/onResume/onDelete/onCancel
        PlayerView->>DownloadTracker: pauseDownload/resumeDownload/removeDownload(uri)
        DownloadTracker->>DownloadController: pauseDownload/resumeDownload/removeDownload(id)
        DownloadController->>TPSDownloadService: pauseDownloads/resumeDownloads/removeDownload(id)
    end
Loading

Poem

In the meadow of code where the streams do play,
A rabbit hops in—downloads now underway!
With sheets that slide and icons that gleam,
Offline or online, you’ll watch every stream.
Pause, resume, or delete with a tap,
This bunny’s made sure you’ll never miss a nap!
🐇💾✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codetortoiseai
Copy link
Copy Markdown

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

1 similar comment
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (19)
tpstreams-android-player/src/main/res/values/styles.xml (1)

10-10: Use a color resource or theme attribute instead of a hard-coded hex
Referencing #2196F3 directly makes future palette changes error-prone. Extract this into a color resource (e.g. @color/colorAccent) or reference the theme attribute (?attr/colorAccent) for consistency.

tpstreams-android-player/src/main/res/drawable/ic_download.xml (1)

1-13: Enable theme-driven icon tinting
The vector’s fillColor is hard-coded to black, which may prevent runtime tinting via Material components. Consider replacing it with a theme attribute (e.g. ?attr/colorOnSurface) or omitting fillColor and relying on the host view’s iconTint.

tpstreams-android-player/src/main/res/layout/item_download_resolution.xml (1)

1-39: Extract hard-coded text styles and colors into resources
Inline text sizes, colors, and margins are repeated values. Define reusable styles (textAppearance) and color resources (@color/...) to maintain consistency and simplify theming.

tpstreams-android-player/src/main/res/layout/layout_download_options_bottom_sheet.xml (1)

53-68: Extract button styling into a reusable style
Hard-coded backgroundTint, iconTint, paddings, and textColor risk duplication. Define a style in styles.xml or leverage theme attributes (?attr/colorPrimary, ?attr/colorOnPrimary) to enforce consistency across buttons.

tpstreams-android-player/src/main/res/layout/layout_download_action_bottom_sheet.xml (4)

11-17: Add contentDescription for decorative View
The drag handle is purely decorative and currently focusable by accessibility services. Add android:contentDescription="@null" to the <View> to mark it as non-interactive.


17-17: Replace hard-coded colors with resource references
Switch hex literals (e.g. #CCCCCC, #212121, #757575, button tints) to named color resources or theme attributes to support theming and maintain consistency.

Also applies to: 27-27, 39-39, 61-61, 83-83, 94-94


12-17: Use dimension resources for margins and paddings
Extract inline dp values (margins/paddings) into @dimen/ resources to centralize spacing definitions and improve consistency.

Also applies to: 28-30, 40-42


53-61: Consolidate MaterialButton styling
Extract repeated attributes (textColor, backgroundTint, layout params) into a shared style in styles.xml to reduce duplication and simplify future style changes.

Also applies to: 75-83, 86-94

tpstreams-android-player/src/main/res/drawable/ic_download_done.xml (1)

8-8: Use color resource instead of hex literal
Replace android:fillColor="#FF000000" with a color resource (e.g., @color/black) or theme attribute to allow easy theming.

tpstreams-android-player/src/main/res/drawable/ic_download_progress.xml (1)

1-1: Replace hex tint with color resource
Use a named color resource (e.g., @color/icon_tint) or theme attribute for android:tint instead of #000000 to support dark/light theming.

tpstreams-android-player/src/main/res/layout/layout_player_settings_bottom_sheet.xml (3)

172-180: Remove unnecessary ID on static label
The TextView displaying the static "Download" label does not need an ID (@+id/download_text) since it isn’t referenced in code. Remove it to match other option layouts.


165-169: Make download icon decorative
Similar to other option icons, this ImageView does not require an ID and should be marked decorative. Remove @+id/download_icon and add android:contentDescription="@null".


183-189: Mark chevron icon as decorative & use theme tint
Add android:contentDescription="@null" to the chevron ImageView and replace android:tint="#757575" with a theme attribute (e.g., ?attr/colorOnSurfaceVariant) for consistency.

tpstreams-android-player/src/main/res/values/strings.xml (2)

23-24: Disambiguate resource name 'download'
The generic download key may collide with other uses. Consider renaming to download_label or action_download for clarity.


29-31: Use more specific name for 'delete' string
delete is too generic and could conflict with other delete actions. Rename to delete_download_action or similar for better context.

tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadPermissionHandler.kt (1)

25-37: Clarify permission-request contract

requestNotificationPermission() returns a Boolean that signals whether the permission is already granted, yet the caller in TPStreamsPlayerView ignores the return value and proceeds to start the download immediately.
Consider:

  1. Rename the method to something like ensureNotificationPermission() and drop the Boolean return, or
  2. Keep the Boolean but make callers branch on it before starting any foreground-service work.

Using registerForActivityResult(RequestPermission()) would also modernise the flow and give you a callback with the user’s decision.

tpstreams-android-player/src/main/java/com/tpstreams/player/TPStreamsPlayerView.kt (1)

738-764: Cache download status while the sheet is open

getCurrentDownloadStatus() / getDownloadIcon() hit DownloadTracker on every invocation.
The values change slowly; cache them when the settings sheet is shown and refresh via a listener from DownloadTracker instead.

tpstreams-android-player/src/main/java/com/tpstreams/player/download/TPSDownloadService.kt (1)

94-103: Make notificationHelper thread-safe

notificationHelper is a mutable companion object field written from onCreate(); if the service is started concurrently multiple times you risk a race.
Initialise it with Kotlin lazy (or @Volatile + double-checked lock) to guarantee a single instance.

tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadActionBottomSheet.kt (1)

46-94: Avoid piling up click listeners in updateUI()

Every time setDownloadState() is called, updateUI() re-attaches a new OnClickListener to pause_resume_button.
Use a single listener whose behaviour switches on the current state, or clear the existing listener before setting a new one.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f978d1 and a35b3d8.

📒 Files selected for processing (19)
  • tpstreams-android-player/src/main/AndroidManifest.xml (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadActionBottomSheet.kt (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadOptionsBottomSheet.kt (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/PlayerSettingsBottomSheet.kt (3 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/TPStreamsPlayer.kt (7 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/TPStreamsPlayerView.kt (6 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadController.kt (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadPermissionHandler.kt (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadTracker.kt (1 hunks)
  • tpstreams-android-player/src/main/java/com/tpstreams/player/download/TPSDownloadService.kt (1 hunks)
  • tpstreams-android-player/src/main/res/drawable/ic_download.xml (1 hunks)
  • tpstreams-android-player/src/main/res/drawable/ic_download_done.xml (1 hunks)
  • tpstreams-android-player/src/main/res/drawable/ic_download_progress.xml (1 hunks)
  • tpstreams-android-player/src/main/res/layout/item_download_resolution.xml (1 hunks)
  • tpstreams-android-player/src/main/res/layout/layout_download_action_bottom_sheet.xml (1 hunks)
  • tpstreams-android-player/src/main/res/layout/layout_download_options_bottom_sheet.xml (1 hunks)
  • tpstreams-android-player/src/main/res/layout/layout_player_settings_bottom_sheet.xml (7 hunks)
  • tpstreams-android-player/src/main/res/values/strings.xml (1 hunks)
  • tpstreams-android-player/src/main/res/values/styles.xml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadActionBottomSheet.kt (2)
tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadOptionsBottomSheet.kt (1)
  • show (170-174)
tpstreams-android-player/src/main/java/com/tpstreams/player/PlayerSettingsBottomSheet.kt (1)
  • show (113-117)
tpstreams-android-player/src/main/java/com/tpstreams/player/TPStreamsPlayerView.kt (5)
tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadOptionsBottomSheet.kt (2)
  • setDownloadSelectionListener (47-49)
  • setAvailableResolutions (51-62)
tpstreams-android-player/src/main/java/com/tpstreams/player/AdvancedResolutionBottomSheet.kt (1)
  • setAvailableResolutions (33-38)
tpstreams-android-player/src/main/java/com/tpstreams/player/DownloadActionBottomSheet.kt (1)
  • setDownloadActionListener (33-35)
tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadController.kt (1)
  • startDownload (158-181)
tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadTracker.kt (1)
  • startDownload (98-101)
🔇 Additional comments (6)
tpstreams-android-player/src/main/AndroidManifest.xml (2)

3-10: Validate storage permissions and scoped storage approach
Using WRITE_EXTERNAL_STORAGE (maxSdkVersion=28) and READ_EXTERNAL_STORAGE (maxSdkVersion=32) is deprecated on newer Android releases. Ensure you’ve adopted scoped storage (MediaStore or SAF) for API 29+ and that runtime request logic aligns with your storage strategy.


12-17: Verify boot completed handling and service registration
You’ve declared TPSDownloadService and added RECEIVE_BOOT_COMPLETED permission, but no receiver is defined here. Confirm that you handle BOOT_COMPLETED events elsewhere (e.g. a BroadcastReceiver) or remove the unused permission.

tpstreams-android-player/src/main/res/layout/layout_download_options_bottom_sheet.xml (2)

1-8: LGTM – Root layout configuration
The bottom-sheet container, padding, and background match the design spec.


31-38: RecyclerView setup is appropriate
layout_weight="1" and overScrollMode="never" provide the expected scrolling behavior.

tpstreams-android-player/src/main/java/com/tpstreams/player/PlayerSettingsBottomSheet.kt (1)

69-110: Looks good – download option integrates cleanly

The added view look-ups and listeners are concise and null-safe.

tpstreams-android-player/src/main/java/com/tpstreams/player/download/DownloadTracker.kt (1)

130-133: getExternalFilesDir() may be null

Same NPE risk as in DownloadController; validate before using the path.

@syed-tp syed-tp merged commit fd7e821 into main Jun 13, 2025
1 check passed
@syed-tp syed-tp deleted the ui/add_download_bottom_sheet branch June 13, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants