Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure files are fully downloaded before sharing #482

Merged
merged 1 commit into from
Mar 1, 2024

Commits on Mar 1, 2024

  1. fix: Ensure files are fully downloaded before sharing

    The previous code would share media by either:
    
    a. If it was an image, downloading the image using Glide in to a bitmap,
    then recompressing as a PNG, saving, and sharing the resulting file.
    
    b. Otherwise, create a temporary file, enqueue a DownloadManager request
    to download the media in to the file, and immediately start sharing,
    hoping that the download had completed in time.
    
    Both approaches have problems:
    
    In the "image" case the image was being downloaded (or retrieved from
    the Glide cache), decompressed to a bitmap, then recompressed as a PNG.
    This uses more memory, and doesn't share the original contents of the
    file. E.g., if the original file was a JPEG that's lost (and the PNG
    might well be larger than the source image).
    
    In the second case the DownloadManager download is not guaranteed to
    have completed (or even started) before the user chooses the share
    destination. The destination could receive a partial or even empty
    file.
    
    Fix both of those cases by always fully downloading the file before
    sending the share intent. This guarantees the file is available to
    share, and in its original format. Since this uses the same OkHttpClient
    as the rest of the app the content is highly likely to be in the
    OkHttp cache, so there will no extra network traffic because of this.
    nikclayton committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    acc6125 View commit details
    Browse the repository at this point in the history