Add media file limit size warning and media quality selection (#5131)

* Add `VideoCompressorPreset` enum

This represents the different compression presets used for processing videos before uploading them

* Add `VideoCompressorHelper` util class to calculate the scaled output size of the video given an input size and its optimal bitrate

Also add `MediaOptimizationConfig` which will be used to decide how to apply compression in `MediaPreProcessor`

* Add `RustMatrixClient.getMaxFileUploadSize()` function and `MaxUploadSizeProvider` so we can import only this functionality into other components

* Try preloading the max file upload size the first time we get network connectivity - it's a best effort

This should help ensure we'll have this value available later, even if we still need to load it asynchronously.

* Split the `compressMedia` preference into `compressImages` and `compressMediaPreset`

* Modify the media processing parts to use the new classes and utils

* Add `MediaOptimizationSelectorPresenter`, which will retrieve the compression values and the max file upload size, also estimating the compressed video file sizes if needed.

* Add a feature flag to allow selecting the media upload quality per upload

* Integrate the previous changes with the attachments preview screen

Add strings from localazy too.

* Adapt the rest of the app calls to upload media to using the media optimization configs

* Allow modifying the default compression values in advanced settings, based on the feature flag value

* Pass the `fileSize` in `MediaUploadInfo` too, to be able to check it against the `maxUploadSize`

* Update screenshots

---------

Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
Jorge Martin Espinosa 2025-08-11 17:22:46 +02:00 committed by GitHub
parent ffe183c952
commit a170d80cb3
174 changed files with 2152 additions and 340 deletions

View file

@ -17,6 +17,7 @@ data class MediaInfo(
val filename: String,
val caption: String?,
val mimeType: String,
val fileSize: Long?,
val formattedFileSize: String,
val fileExtension: String,
val senderId: UserId?,
@ -36,6 +37,7 @@ fun anImageMediaInfo(
dateSentFull: String? = null,
): MediaInfo = MediaInfo(
filename = "an image file.jpg",
fileSize = 4 * 1024 * 1024,
caption = caption,
mimeType = MimeTypes.Jpeg,
formattedFileSize = "4MB",
@ -57,6 +59,7 @@ fun aVideoMediaInfo(
duration: String? = null,
): MediaInfo = MediaInfo(
filename = "a video file.mp4",
fileSize = 14 * 1024 * 1024,
caption = caption,
mimeType = MimeTypes.Mp4,
formattedFileSize = "14MB",
@ -78,6 +81,7 @@ fun aPdfMediaInfo(
dateSentFull: String? = null,
): MediaInfo = MediaInfo(
filename = filename,
fileSize = 23 * 1024 * 1024,
caption = caption,
mimeType = MimeTypes.Pdf,
formattedFileSize = "23MB",
@ -98,6 +102,7 @@ fun anApkMediaInfo(
dateSentFull: String? = null,
): MediaInfo = MediaInfo(
filename = "an apk file.apk",
fileSize = 50 * 1024 * 1024,
caption = null,
mimeType = MimeTypes.Apk,
formattedFileSize = "50MB",
@ -121,6 +126,7 @@ fun anAudioMediaInfo(
duration: String? = null,
): MediaInfo = MediaInfo(
filename = filename,
fileSize = 7 * 1024 * 1024,
caption = caption,
mimeType = MimeTypes.Mp3,
formattedFileSize = "7MB",
@ -144,6 +150,7 @@ fun aVoiceMediaInfo(
duration: String? = null,
): MediaInfo = MediaInfo(
filename = filename,
fileSize = 3 * 1024 * 1024,
caption = caption,
mimeType = MimeTypes.Ogg,
formattedFileSize = "3MB",
@ -165,6 +172,7 @@ fun aTxtMediaInfo(
dateSentFull: String? = null,
): MediaInfo = MediaInfo(
filename = filename,
fileSize = 2 * 1024,
caption = caption,
mimeType = MimeTypes.PlainText,
formattedFileSize = "2kB",