-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ensure files are fully downloaded before sharing (#482)
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.
- Loading branch information
1 parent
fcae441
commit b9512e4
Showing
2 changed files
with
67 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters