fix(stats): recreate statistics and card info on rotation
Purpose / Description
When viewing charts in the Statistics or Card Info screens, tapping on a bar opens a popup tooltip. If the device orientation changes while this popup is active, the popup remains on the screen and goes "out of bounds" instead of updating its position or being dismissed.
Fixes
- Fixes #18358
Approach
Approach
-
Switched the hosting activity for
StatisticsandCardInfoFragmentdestinations fromSingleFragmentActivitytoConfigAwareSingleFragmentActivity. UnlikeSingleFragmentActivity,ConfigAwareSingleFragmentActivityrecreates on configuration changes (such as device rotation), ensuring the hosting Activity and Fragment are rebuilt and the WebView page is cleanly re-rendered to fit the new screen dimensions. -
Overrode
onCreateWebViewClientinStatisticsto re-apply the currently selected deck viachangeDeckonce the WebView finishes loading (usingonPageFinishedCallbacks) to preserve the user's selected deck across rotation.
How Has This Been Tested?
Automated Tests
- Updated and ran the local Robolectric unit tests for the statistics screen:
./gradlew :AnkiDroid:testPlayDebugUnitTest --tests "com.ichi2.anki.pages.StatisticsTest"(Tests pass successfully)
Manual Verification
- Open the Statistics or Card Info screen.
- Rotate the device to landscape mode.
- Tap on a chart bar to display the tooltip popup.
- Rotate the device back to portrait mode.
- Verified that the layout re-fits correctly and the out-of-bounds popup is cleared/dismissed.
https://github.com/user-attachments/assets/81a8d3da-3625-4f59-a183-0f2928f593c7
Configuration: Tested using Robolectric and on an Android Emulator running SDK 33.
Checklist
- [x] 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
- [x] 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
Thanks, but your video doesn't seem to demonstrate the fix.
You need to tap on one of the bars in landscape mode to show the tooltip then rotate to portrait mode. Also, the bug is un-noticable when tapping on the bars on the left, so tap the right-mist bar.
I changed the video, and now I think its the correct video as per the issue. btw thanks for tagging the issue.
This now appears to reset scroll position on rotation
Tried saving and restoring scroll position via webViewLayout.scrollY / webView.scrollTo(), but it's unreliable since we don't know when the SvelteKit charts finish rendering after the reload. Any preferred approach here?
@david-allison can you please help me with this ?
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically
Sorry but I can't help you @Ayush-Patel-56, I know nothing about this kind of coding.