forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deck picker options flickering + error on full sync
ankidroid#11849 (comment) Android's onCreateOptionsMenu does not play well with coroutines, as it expects the menu to have been fully configured by the time the routine returns. This results in flicker, as the menu gets blanked out, and then configured a moment later when the coroutine runs. To work around this, the current state is stored in the deck picker, so that we can redraw the menu immediately, and then make any potential changes in the background. Other changes: - refactored onCreateOptionsMenu to make it simpler - instead of the sdCardAvailable checks (which I assume is a proxy for "col is available"), the entire menu is wrapped in a group, and the visibility of the group is toggled depending on whether the col is available or not. This also fixes the error on a full sync. - there are three sets of unit tests (one for search icon, one for sync icon, one for entire menu) that have been a pain since I originally introduced this PR, and and I've sunk a number of hours into trying to get them to work properly at this point. The issue appears to be that when mixing coroutine calls and invalidateOptionsMenu(), onCreateOptionsMenu() is not getting called before trying to await the job, leading to a hang or stale data. I tried advancing robolectric, but it did not help. Maybe someone more experienced in this area can figure it out, but for now I've changed these routines to be more of a unit test and less of an integration test: rather than checking the menu itself, they directly invoke the function that updates the menu state, and check the state instead. This takes onCreateOptionsMenu() out of the loop, and avoids the problems (and probably allows these tests to be re-enabled on Windows as well). The sync tests I've removed, as the entire menu is hidden/shown now when the col is closed, so they are redundant.
- Loading branch information
Showing
5 changed files
with
211 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.