-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Feat[Multimedia]: render svg
using webview
#17035
base: main
Are you sure you want to change the base?
Conversation
Message to maintainers, this PR contains strings changes.
Read more about updating strings on the wiki, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks GREAT to me
Question: does this work for other formats? Because animated PNGs are static in the ImageView, but animated when the card is opened |
2d8f019
to
167baac
Compare
No this method would require workarounds for different images, we can directly use webview to preview images |
So, is it possible to use the WebView instead of an ImageView to preview all the images? That should handle all the images that can be rendered in a flashcard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does seem like a fantastic opportunity to have a single way to do things vs conditionals
what if all images went through the webview? can this PR be altered to do that?
also would be nice to move this along by removing the dependency blocker - I think that other PR is about ready to go so the first commit can drop here ?
I will update it to use webview then /will rebase once the blocker goes in / |
this one is free / unblocked now 🥳 |
167baac
to
cd4d47b
Compare
3380af6
to
654e231
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good. Love the "use webview for all the things" direction if we're going to be using a WebView at all
Was testing this and took a crash here - granted, unlikely perhaps in the wild but on an emulator, boom
- add note (basic forward/reversed)
- click paperclip
- select gallery
10-12 12:58:40.367 4867 4867 D MultimediaImageFragment: MultimediaImageFragment:: Opening gallery
10-12 12:58:40.391 661 963 D CompatibilityChangeReporter: Compat change id reported: 182734110; UID 10193; state: ENABLED
10-12 12:58:40.392 509 608 D audioserver: FGS Logger Transaction failed
10-12 12:58:40.392 509 608 D audioserver: -129
10-12 12:58:40.399 661 963 I ActivityTaskManager: START u0 {act=android.intent.action.PICK dat=content://media/...} with LAUNCH_MULTIPLE from uid 10193 result code=-91
10-12 12:58:40.399 4867 4867 D AndroidRuntime: Shutting down VM
--------- beginning of crash
10-12 12:58:40.404 4867 4867 E AndroidRuntime: FATAL EXCEPTION: main
10-12 12:58:40.404 4867 4867 E AndroidRuntime: Process: com.ichi2.anki.debug, PID: 4867
10-12 12:58:40.404 4867 4867 E AndroidRuntime: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/... }
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2239)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1878)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:5589)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.kt:704)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:244)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.activity.ComponentActivity$activityResultRegistry$1.onLaunch(ComponentActivity.kt:225)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.activity.result.ActivityResultRegistry$register$2.launch(ActivityResultRegistry.kt:137)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.fragment.app.Fragment$10.launch(Fragment.java:3637)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.kt:37)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at com.ichi2.anki.multimedia.MultimediaImageFragment.openGallery(MultimediaImageFragment.kt:328)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at com.ichi2.anki.multimedia.MultimediaImageFragment.handleSelectedImageOptions(MultimediaImageFragment.kt:288)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at com.ichi2.anki.multimedia.MultimediaImageFragment.handleImageUri(MultimediaImageFragment.kt:280)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at com.ichi2.anki.multimedia.MultimediaImageFragment.onViewCreated(MultimediaImageFragment.kt:272)
10-12 12:58:40.404 4867 4867 E AndroidRuntime: at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3152)
The "take photo, crop it, see it in the preview both times" case worked well though
I did not test the "unsupported image type" case or the actual SVG case (yet)
I did test it with svg, gif and normal pictures |
654e231
to
94cf173
Compare
private fun loadSvgFromUri(uri: Uri): String? { | ||
return try { | ||
val inputStream = context?.contentResolver?.openInputStream(uri) | ||
inputStream?.bufferedReader()?.use { it.readText() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather also see the inputStream
in a use {
. I don't believe it's necessary, but don't want readers of the code to have to think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't close the inputStream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary, but removes a question I'd have each time I review the code
Index: AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt (revision 4bb6974116b35eea097c03bc1643d76582d8161b)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt (date 1729058648238)
@@ -579,11 +579,13 @@
*/
private fun loadSvgFromUri(uri: Uri): String? {
return try {
- context?.contentResolver?.openInputStream(uri)?.bufferedReader()?.use { inputStream ->
- inputStream.readText()
+ context?.contentResolver?.openInputStream(uri)?.use { inputStream ->
+ inputStream.bufferedReader().use { inputStream ->
+ inputStream.readText()
+ }
}
} catch (e: Exception) {
- Timber.e(e, "Error reading SVG from URI")
+ Timber.w(e, "Error reading SVG from URI")
null
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I thought you meant it should be readable and the extra code, now use is applied to the inputStream, ensuring it is closed properly after the BufferedReader has finished reading the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-allison I already made changes, if you think this is not readable still then I will apply your patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for your review
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
94cf173
to
4bb6974
Compare
4bb6974
to
16727fa
Compare
16727fa
to
a9bdf3a
Compare
@david-allison pending review |
a9bdf3a
to
fd6dae6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think these are nitpicks, with the .use
potentially being a blocker
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
fd6dae6
to
1b4c10e
Compare
Purpose / Description
Render SVG instead of showing a warning text.
Blocked by
Fixes
Approach
Use a webview to render an SVG in it
How Has This Been Tested?
Tested on OnePlus Nord CE:
Checklist
Please, go through these checks before submitting the PR.