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

"Delete your account" next step is not very clear (and not translated) fixed #19436

Open infiniteflux opened this issue 1 month ago • 9 comments

Purpose / Description Add a confirmation dialog before redirecting users to the AnkiWeb account removal page. The current flow immediately opens a WebView, which is confusing for users as they don't understand what will happen next and the page is not translated.

This PR:

  • Shows user's email address with a copy button for convenience during re-authentication
  • Explains that re-authentication is required before account removal
  • Provides clear "OK" and "Cancel" options
  • Uses Material Design 3 dialog styling consistent with the app

Fixes

  • Fixes #19436

Approach How does this change address the problem?

  1. Added AccountRemovalExplanationDialog: A new DialogFragment that displays:
  • Title explaining re-authentication is required
  • User's email address (retrieved from Prefs.username)
  • Copy button to easily copy email to clipboard
  • OK/Cancel buttons for user confirmation

2.Modified LoggedInFragment:

  • Intercepts the "Remove Account" button click
  • Shows the explanation dialog first
  • Uses fragment result listener to proceed only if user clicks OK
  • Listener properly managed using viewLifecycleOwner for automatic cleanup

3.User Flow:

  • Before: Click "Remove Account" → Immediately opens WebView
  • After: Click "Remove Account" → See explanation dialog → Click OK → Opens WebView

This gives users context and prevents accidental account removal attempts.

How Has This Been Tested? Test Environment:

  • Device: Realme 15 5g
  • Android Version: Android 15 (API 35)
  • AnkiDroid Version: Latest debug build from this branch

Test Cases: 1.Happy Path - User proceeds with removal:

  • Navigate to Settings → Sync → Account
  • Click "Remove Account"
  • Verify dialog appears with correct title and message
  • Verify email is displayed
  • Click "Copy" button
  • Verify email is copied to clipboard (paste in another app to confirm)
  • Click "OK"
  • Verify WebView opens with AnkiWeb removal page

2.User cancels:

  • Click "Remove Account"
  • Click "Cancel"
  • Verify dialog dismisses
  • Verify no WebView is opened
  • User remains on Account settings screen

3.Configuration changes:

  • Click "Remove Account" to show dialog
  • Rotate device
  • Verify dialog persists and data is retained
  • Click "OK" after rotation
  • Verify WebView still opens correctly

4.Empty email handling:

  • Test with no logged-in user (if possible)
  • Verify email section is hidden if no username available

5.Back button:

  • Open dialog
  • Press back button
  • Verify dialog dismisses (same as Cancel)

Learning Key patterns used:

  • Fragment Result API: Modern way to pass data between fragments, replacing deprecated setTargetFragment
  • View Binding: Type-safe view access, replacing findViewById
  • viewLifecycleOwner: Proper lifecycle scope for fragment views, ensures automatic cleanup
  • Material Design 3 Dialogs: Using MaterialAlertDialogBuilder for consistent styling

Resources:

Checklist

  • [x] You have a descriptive commit message with a short title (first line, max 50 chars).
  • [x] You have commented your code, particularly in hard-to-understand areas
  • [x] You have performed a self-review of your own code
  • [x] UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • [ ] Screenshots to be added
  • [x] UI Changes: You have tested your change using the Google Accessibility Scanner
  • [x] Dialog is keyboard navigable, has proper content descriptions, meets contrast requirements

infiniteflux avatar Nov 19 '25 18:11 infiniteflux

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

welcome[bot] avatar Nov 19 '25 18:11 welcome[bot]

[!IMPORTANT] Maintainers: This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

github-actions[bot] avatar Nov 19 '25 18:11 github-actions[bot]

Hi @david-allison, I've removed my OnWebViewRecreatedListener changes from RemoveAccountFragment.kt as requested. However, this means the account removal flow crashes when opening the WebView due to the pre-existing #19561 issue. The crash occurs because SafeWebViewLayout requires OnWebViewRecreatedListener but the original RemoveAccountFragment doesn't implement it. My dialog works perfectly - it shows, allows copying the email, and handles user confirmation. The crash only happens in the existing RemoveAccountFragment code that's outside the scope of this PR. Should I:

  1. Leave it as-is and document that account removal is currently broken (waiting for #19561 fix)
  2. Or add a minimal OnWebViewRecreatedListener implementation just to unblock testing? Let me know your preference. The dialog functionality itself is complete and working.

infiniteflux avatar Nov 24 '25 20:11 infiniteflux

Leave a patch on the PR for testing, and remove the method

david-allison avatar Nov 24 '25 21:11 david-allison

Leave a patch on the PR for testing, and remove the method

Done! I've added a minimal OnWebViewRecreatedListener implementation as a temporary patch to allow testing. It's clearly marked as temporary and references #19561 for the proper fix. The implementation simply reloads the removal URL when the WebView is recreated, which should be sufficient for testing the dialog flow.

infiniteflux avatar Nov 24 '25 21:11 infiniteflux

Heya, could you fill out all the PR Template:

https://github.com/ankidroid/Anki-Android/blob/main/.github/pull_request_template.md

I've updated the PR description to follow the template. Please let me know if there's anything else I should add or clarify in the description. I'm now working on addressing your code review feedback:

  • Using viewLifecycleOwner for the fragment result listener
  • OnWebViewRecreatedListener implementation for testing
  • Using Prefs.username instead of PreferenceManager
  • Hiding email/copy button when username is empty
  • Removing unnecessary comments

I'll push the updated code shortly. Thanks for the detailed feedback!

infiniteflux avatar Nov 25 '25 05:11 infiniteflux

  • https://github.com/ankidroid/Anki-Android/pull/19581

Well be merged. Rebase this PR on main and force push and the issue will be resolved

david-allison avatar Nov 25 '25 09:11 david-allison

Please rebase onto main + force push rather than adding in a commit which brings the file up to date:

  • This removes author & the git commit message
  • This appears as a diff when we're reviewing the code, even though it matches main
  • This adds additional commits into the history
  • This risks conflicts, as it's not the same commit

david-allison avatar Nov 25 '25 11:11 david-allison

@Arthur-Milchior Is this what you intended?

david-allison avatar Nov 28 '25 03:11 david-allison

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 Dec 14 '25 21:12 github-actions[bot]

First, nice to meet you @infiniteflux ! Great work! I'd suggest adding screenshot of your work in the PR. I had to download and run the code to check the behaviour, which is not a big deal but not ideal either.

Thank you David for pinging me on discord.

I've opinions indeed.

I'm not fan of "Remove account". It's not clear from what it'll be removed. I guess we should keep it as it's what ankiweb uses.

I like the way you implemented the alert. I'd suggest a different phrasing however.

If you remove your account, all data associated with your account will be permanently lost. This includes your flashcards, study progress, shared decks, and so on.

In order to remove your data from ankiweb, the English-only third party service used to sync data, you'll need to:

  • sign-in again with your password to your account: (enter the email address and the copy button)
  • then re-enter the password and the word "remove" (English for "remove") Click on "Remove account".

My reasoning is that it's nice for the non-English speaking users to be able to know what the warning says. And what is expected of them (type the word "remove"). And we can use our translators for that.

Maybe it'd be better to have distinct sentences for English and non-English, and check in code whether the locale is English to decide which sentence to use. Because some of those sentences are only useful for non english-speaking users. If it's not too hard, I'd appreciate that too.

Admittedly, if ankiweb UI changes, we'll need to update our strings. I expect it's rare enough that it's not a big maintenance burden.

Admittedly, an alternative solution could be to just open this in an external browser. I expect most brother to have a translate feature, which may simplify everything. Still, I prefer the solution I suggest above, because I don't expect users to necessarily know about the translate feature of their browser.

Can you please let me know how this behave when the account is on a personal server? I've never tried ankidroid with a non ankiweb server. It's not a big deal if this rare use case is not perfect, but it'd be nice to know what occurs.

Arthur-Milchior avatar Dec 16 '25 05:12 Arthur-Milchior

Hi @Arthur-Milchior, nice to meet you too—thanks so much for the thoughtful review!

Screenshot

remove_dialogue

This is what I've implemented based on your earlier suggestions. Does it look good, or any changes needed? Happy to tweak! Thanks again!

infiniteflux avatar Dec 16 '25 16:12 infiniteflux