fix SVG file processing and upload validation#6665
fix SVG file processing and upload validation#6665Roniscend wants to merge 1 commit intocommons-app:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Android Commons upload UI to correctly preview SVG files by adding SVG rendering support (AndroidSVG) and adjusting upload/edit behaviors so SVGs no longer appear as black thumbnails during the upload flow. This addresses the SVG preview portion of issue #6650.
Changes:
- Added AndroidSVG dependency and introduced
SvgUtilsto detect and render SVGs to bitmaps/drawables. - Updated upload thumbnail and media detail screens to render SVGs via
SvgUtilsand hide the “Edit image” action for SVGs. - Skipped the “image too dark” check for SVG inputs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| gradle/libs.versions.toml | Adds version + library entry for AndroidSVG. |
| app/build.gradle.kts | Includes AndroidSVG dependency in the app module. |
| app/src/main/java/fr/free/nrw/commons/utils/SvgUtils.kt | New utility for SVG detection and rendering to Bitmap/Drawable. |
| app/src/main/java/fr/free/nrw/commons/utils/ImageUtils.kt | Bypasses darkness check for SVG inputs. |
| app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt | Renders SVG previews on the media detail screen; hides edit UI for SVG. |
| app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.kt | Renders SVG thumbnails in the upload thumbnails list. |
| app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt | Blocks editing for SVGs (exits early with a toast). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/fr/free/nrw/commons/upload/ThumbnailsAdapter.kt
Outdated
Show resolved
Hide resolved
710c888 to
351dce9
Compare
|
|
||
| if (isMediaSvg || isFileSvg) { | ||
| viewLifecycleOwner.lifecycleScope.launch { | ||
| val drawable = withContext(Dispatchers.IO) { |
There was a problem hiding this comment.
Why do we need IO thread to render image?
There was a problem hiding this comment.
@owm would you mind addressing the unresolved comments? Thanks!
app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt
Outdated
Show resolved
Hide resolved
| val uploadableFile = uploadableFiles[position] | ||
| val uri = uploadableFile.getMediaUri() | ||
| background.setImageURI(Uri.fromFile(File(uri.toString()))) | ||
| val filePath = uploadableFile.getFilePath()?.toString() ?: "" |
There was a problem hiding this comment.
Can we have a if(filepath.isNullOrBlank.not())
| org.gradle.jvmargs=-Xmx1536M | ||
| org.gradle.caching=true | ||
| android.enableR8.fullMode=false | ||
|
|
There was a problem hiding this comment.
Could you please remove anything unrelated to this change so it doesn’t show up in the git diff? It will help keep the review clean and focused.
351dce9 to
700c0fe
Compare
| } | ||
|
|
||
| if (imageUri.substringBefore("?").endsWith(".svg", ignoreCase = true)) { | ||
| Toast.makeText(this, "SVG files cannot be edited", Toast.LENGTH_SHORT).show() |
There was a problem hiding this comment.
Will review this today, thanks for contributing @Roniscend. Can I know is there any reason we can't edit svg images?
There was a problem hiding this comment.
Can I know is there any reason we can't edit svg images?
@neeldoshii Not sure but based on one of the issues I’m working on, the reason might be that SVG files don’t contain EXIF headers, which could be causing the problem :)
Comment link : #6642 (comment)
There was a problem hiding this comment.
Yes, our current editing flow relies on EXIF metadata, which svg do not have.
There was a problem hiding this comment.
The app exists because smartphones have become the main way people take pictures. By contrast, creating SVG on smartphone is an extremely niche use case. In my experience monitoring the app's uploads, most non-photography files uploaded from the app are copyright violations. So I think it makes sense to focus our limited resources on photography formats. 🙂
There was a problem hiding this comment.
in that case how about we convert svg to png first? Not sure if its possible or not and how much workaround is there will check it once.
There was a problem hiding this comment.
We don't have the bandwidth to maintain any SVG or PNG editing features.
We can grey out the edit button and when tapped, it could say something like "To edit non-JPG files, use third-party tools".
There was a problem hiding this comment.
We can grey out the edit button
@nicolas-raoul this was recently fixed in #6653 as part of #6642 ,and now the edit image button will be disabled for the non JPG files :)
There was a problem hiding this comment.
This one sounds better actually. It's more transparent for our users, otherwise they'll keep wondering when that Edit button appears. I'll create a follow-up issue.
There was a problem hiding this comment.
"To edit non-JPG files, use third-party tools".
Great. Also just an idea for suggestion not sure it good or not. How about we provide third party tool link and user can click and go to the website (externally, in app is very hard to maintain as we don't know when to close) and once the user has converted the image to jpg, user can finally upload jpg image.
nicolas-raoul
left a comment
There was a problem hiding this comment.
Would you mind letting us know what is the apk file size before and after this PR?
|
Would you mind rebasing from main? |
Signed-off-by: Owm Dubey <owmdubey163@gmail.com> # Conflicts: # app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt # Conflicts: # app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt # app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.kt
|
✅ Generated APK variants! |
This branch increases the application size by approximately 0.4 MB |
on which build flavour? was proguard enabled on that? I think 0.4 MB won't be a big tradeoff if we remove fresco as removing fresco will reduce the app size in long run, also is the PR ready to review? |
| newViewHeight = (drawableHeight * newImageScale).toInt() | ||
| } | ||
| else -> { | ||
| throw |
Description (required)
I updated the upload flow to properly handle .svg files by integrating SVG decoding logic, which was previously causing thumbnails to appear as black screens. By ensuring the app correctly recognizes and renders SVG vector data into a visible Drawable, users can now preview their files before uploading.
Fixes #6650
What changes did you make and why?
I integrated SVG decoding logic into the upload flow to properly handle .svg files, which previously caused thumbnails to appear as black screens. Users can now accurately verify their SVG files on their devices before completing an upload.
Tests performed (required)
Tested 6.3.0-debug on a Pixel 9 running Android 16 (API 36)
Screenshots (for UI changes only)
Solution.mp4