mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 12:02:16 +02:00
AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
036b882677
Currently there are many instances in the AnkiDroid codebase where the collection is accessed a) on the UI thread, blocking the UI, and b) in unsafe ways (eg by checking to see if the collection is open, and then assuming it will remain open for the rest of a method call. "Fix full download crashing in new schema case" (159a108dcb) demonstrates a few of these cases. This PR is an attempt at addressing those issues. It introduces a `withCol` function that is intended to be used instead of CollectionHelper.getCol(). For example, code that previously looked like: val col = CollectionHelper.getInstance().getCol(this) val count = col.decks.count() Can now be used like this: val count = withCol { decks.count() } The block is run on a background thread, and other withCol calls made in parallel will be queued up and executed sequentially. Because of the exclusive access, routines can safely close and reopen the collection inside the block without fear of affecting other callers. It's not practical to update all the legacy code to use withCol immediately - too much work is required, and coroutines are not accessible from Java code. The intention here is that this new path is gradually bought into. Legacy code can continue calling CollectionHelper. getCol(), which internally delegates to CollectionManager. Two caveats to be aware of: - Legacy callers will wait for other pending operations to complete before they receive the collection handle, but because they retain it, subsequent access is not guaranteed to be exclusive. - Because getCol() and colIsOpen() are often used on the main thread, they will block the UI if a background operation is already running. Logging has been added to help diagnose this, eg messages like: E/CollectionManager: blocked main thread for 2626ms: com.ichi2.anki.DeckPicker.onCreateOptionsMenu(DeckPicker.kt:624) Other changes: - simplified CoroutineHelpers - added TR function for accessing translations without a col reference - onCreateOptionsMenu() needed refactoring to avoid blocking the UI. - The blocking colIsOpen() call in onPrepareOptionsMenu() had to be removed. I can not reproduce the issue it reports, and the code checks for col in onCreateOptionsMenu(). - The subscribers in ChangeManager need to be cleared out at the start of each test, or two tests are flaky when run with the new schema. |
||
---|---|---|
.github | ||
.idea | ||
AnkiDroid | ||
annotations | ||
api | ||
docs | ||
gradle/wrapper | ||
lint-rules | ||
tools | ||
.codecov.yml | ||
.gitattributes | ||
.gitignore | ||
.prettierignore | ||
.prettierrc | ||
build.gradle | ||
CONTRIBUTING.md | ||
COPYING | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
lint-release.xml | ||
lint.gradle | ||
pre-commit | ||
README.md | ||
settings.gradle |
AnkiDroid
A semi-official port of the open source Anki spaced repetition flashcard system to Android. Memorize anything with AnkiDroid!
Features
- night mode
- whiteboard
- progress widget
- detailed statistics
- syncing with AnkiWeb
- write answers (optional)
- text-to-speech integration
- more than 6000 premade decks
- spaced repetition (supermemo 2 algorithm)
- supported contents: text, images, sounds, MathJax
- add cards by intent from other applications like dictionaries
Install
Wiki
View Wiki
Help
Check the user manual and the wiki for usage instructions. See the help page for how to submit a bug report or contact a project member, etc.
Contribute
You can contribute to AnkiDroid by beta testing, translating, or submitting code. See the contribution wiki page for more info.
Join Us On
Credits
Code Contributors
Thanks to these awesome code contributors who keep this project going
Sponsors
Backers
Thank you to all our backers! 🙏
Translators
Thanks to our 1400 translators, for allowing us to be available, partially or totally, in 99 languages as of July 2022.
License
- GPL-3.0 License
- AGPL-3.0 Licence for some part of the back-end