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

Remove legacy collection loading code from AnkiFragment #17457

Closed lukstbit closed 4 days ago

lukstbit commented 5 days ago

Purpose / Description

AnkiFragment was using CollectionManager.getColUnsafe() and also set up a loading mechanism similar with the CollectionLoader used by AnkiActivity returning the same CollectionManager.getColUnsafe(). This PR removes the loading mechanism and lets NoteEditor to only use CollectionManager.getColUnsafe(). This way, the setup that was done in onCollectionLoaded() is inserted in the fragment lifecycle and should prevent bugs from the bad timing around onCollectionLoaded().

The progress bar in the layout was removed because it was only used for the collection loading mechanism. I was kind of able to reproduce the error in #17380 by using the same steps from #17407(modify the collection loading in ANkiFragment) and opening NoteEditor -> attach image. I said kind of because there's a bug in the multimedia image selection(see #17455) where the return to NoteEditor doesn't work quite right with Don't keep activities enabled. IMO both bugs in #17380 and #17407 are happening because there's bad timing between the code expecting the collection to be available and the collection not being yet available( meaning onCollectionLoaded() executed).

At reviewers discretion if this should go in 2.19.x.

Fixes

How Has This Been Tested?

Tried to add things, ran the tests.

Checklist

lukstbit commented 5 days ago

@criticalAY I made this PR although you were assigned because I don't think the bug is related to multimedia stuff.

criticalAY commented 5 days ago

Cool cool, that was not related to multimedia anyway thanks for taking some weight off ;)

mikehardy commented 4 days ago

On it re: the testing request

mikehardy commented 4 days ago

Worked fine, going to merge etc

test: 1- demonstrate force stop of AnkiDroid 2- open some / any app that allows me to select text 3- open context menu and select Anki Card 4- finish creating that card and save it 5- demonstrate card exists in AnkiDroid app afterwards

Seems good

anki-card-context-menu-clean-open.webm

Wow, should have made that lower resolution / quality, sorry. Quite a big file.