ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.73k stars 2.24k forks source link

Fix huge image crashes, allow adding large images, fixup large image size formatting #17467

Closed mikehardy closed 1 day ago

mikehardy commented 1 day ago

Purpose / Description

Attempting to test:

Reproduced and fixed:

Noticed that the number format on the "image too large, want to crop?" dialog was mathematically incorrect and formatted wrong.

Also noticed that if the image was too large you really just couldn't save it at all even if you were a grown adult and you knew what you were doing

Finally noticed that if you have an image file that is finally large enough (I needed a really really big image) then you'll crash both when adding via shortcut and from image picker. Same line of code though, so I handled that and it should work now.

Fixes

Fixes:

Approach

Carefully catch the exception thrown, but also clear out the dirty intermediate state in the image widget so we recover

How Has This Been Tested?

I manually verified that when I add a really large image it has the size correctly displayed now, and I can save it if I really want to.

ankidroid_add_large_image.webm

I also manually verified that when I add a stupendously large image that crashed (I reproduced the crash...) it now succeeds

no-crash-on-huge-file.webm

Learning (optional, can help others)

Yak shaves always Crash fixes - even easy ones - are a little subtle

Checklist

Please, go through these checks before submitting the PR.

mikehardy commented 1 day ago

Note that rendering images with WebView does not really fix the "users loading huge images" problem(s), it has different problems with huge images.

So I think this package of fixes is a good thing to have in 2.19.x if reviewers agree

criticalAY commented 1 day ago

Niceeee one! Just woke up but this is great