Skip to content
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

Remove legacy collection loading code from AnkiFragment #17457

Merged

Conversation

lukstbit
Copy link
Member

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

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

This class was using the legacy CollectionLoader to return the already
available for use, CollectionManager.getColUnsafe().

The try-catch replicates CollectionLoader's behavior which invokes
the activity's onCollectionLoadError() method to go to DeckPicker
when faced with any exception during loading the collection.

Probably fixes  ankidroid#17380 where a NullPointerException is thrown for
one of AnkiFragment's subclasses, NoteEditor, because the culprit
property editorNote is assigned a valid note in the callback
onCollectionLoaded() which may or may not be executed at the right
time.
@lukstbit
Copy link
Member Author

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

@criticalAY
Copy link
Contributor

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

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, and I like this as a pick to 2.19 to hopefully address some of the Poison::unwrap issues there as the hypothesis is that it is getColUnsafe and racy code as a root cause

But I want a second set of eyes

@mikehardy mikehardy added Review High Priority Request for high priority review Needs Second Approval Has one approval, one more approval to merge labels Nov 18, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM.

Could someone test a 'clean open' of this screen from the 'Anki Card' context menu shortcut before merging.

@david-allison david-allison added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) Needs reviewer reply Waiting for a reply from another reviewer and removed Needs Review Needs Second Approval Has one approval, one more approval to merge labels Nov 18, 2024
@mikehardy
Copy link
Member

On it re: the testing request

@mikehardy
Copy link
Member

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.

@mikehardy mikehardy removed Review High Priority Request for high priority review Needs reviewer reply Waiting for a reply from another reviewer labels Nov 18, 2024
@mikehardy mikehardy added this pull request to the merge queue Nov 18, 2024
Merged via the queue into ankidroid:main with commit 24bde7b Nov 18, 2024
12 checks passed
@github-actions github-actions bot added this to the 2.20 Release milestone Nov 18, 2024
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Nov 18, 2024
@lukstbit lukstbit deleted the fix_handleCollectionStartupAnkiFragment branch November 19, 2024 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NoteEditor.getCurrentMultimediaEditableNote: NullPointerException
4 participants