Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

fix(stats): recreate statistics and card info on rotation

Open Ayush-Patel-56 opened this issue 5 months ago • 4 comments

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 Statistics and CardInfoFragment destinations from SingleFragmentActivity to ConfigAwareSingleFragmentActivity. Unlike SingleFragmentActivity, ConfigAwareSingleFragmentActivity recreates 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 onCreateWebViewClient in Statistics to re-apply the currently selected deck via changeDeck once the WebView finishes loading (using onPageFinishedCallbacks) 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

  1. Open the Statistics or Card Info screen.
  2. Rotate the device to landscape mode.
  3. Tap on a chart bar to display the tooltip popup.
  4. Rotate the device back to portrait mode.
  5. 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

Ayush-Patel-56 avatar Jun 09 '26 09:06 Ayush-Patel-56

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.

ZornHadNoChoice avatar Jun 09 '26 09:06 ZornHadNoChoice

I changed the video, and now I think its the correct video as per the issue. btw thanks for tagging the issue.

Ayush-Patel-56 avatar Jun 09 '26 12:06 Ayush-Patel-56

This now appears to reset scroll position on rotation

david-allison avatar Jun 10 '26 05:06 david-allison

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 ?

Ayush-Patel-56 avatar Jun 15 '26 08:06 Ayush-Patel-56

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

github-actions[bot] avatar Jun 29 '26 10:06 github-actions[bot]

Sorry but I can't help you @Ayush-Patel-56, I know nothing about this kind of coding.

ZornHadNoChoice avatar Jun 29 '26 11:06 ZornHadNoChoice