Skip to content

Conversation

@infiniteflux
Copy link

@infiniteflux infiniteflux commented Nov 19, 2025

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

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

  • 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
  • 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)
  • Screenshots to be added
  • UI Changes: You have tested your change using the Google Accessibility Scanner
  • Dialog is keyboard navigable, has proper content descriptions, meets contrast requirements

@welcome
Copy link

welcome bot commented Nov 19, 2025

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.

@github-actions
Copy link
Contributor

Important

Maintainers: This PR contains 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

@infiniteflux infiniteflux changed the title Added delete account info screen before opening webview Added delete account info screen before opening webview #19436 Nov 19, 2025
@infiniteflux infiniteflux changed the title Added delete account info screen before opening webview #19436 "Delete your account" next step is not very clear (and not translated) fixed #19436 Nov 19, 2025
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Nov 22, 2025
- Use View Binding for dialog
- Switch to FixedTextView in layout
- Use android.R.string for standard buttons
- Use Context.copyToClipboard() utility
- Apply sentence case to dialog title
- Simplify dialog message wording
- Use AlertDialogFacade.create extension
- Move fragment result listener to onCreate()
- Remove clearFragmentResultListener from callback
- Add listener cleanup in onDestroy()
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val preferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val email = preferences.getString("username", "") ?: ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefs.username

@infiniteflux
Copy link
Author

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 [BUG] 'RemoveAccountFragment' crashes on open: must implement OnWebViewRecreatedListener #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.

@david-allison
Copy link
Member

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

@infiniteflux
Copy link
Author

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
Copy link
Author

infiniteflux commented Nov 25, 2025

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!

- Use viewLifecycleOwner for fragment result listener
- Remove onDestroy cleanup (handled automatically)
- Keep minimal OnWebViewRecreatedListener for testing (per reviewer request)
- Use Prefs.username instead of PreferenceManager
- Hide email/copy button if username is empty
- Remove unnecessary comments
@david-allison
Copy link
Member

david-allison commented Nov 25, 2025

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

@david-allison
Copy link
Member

david-allison commented Nov 25, 2025

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

@infiniteflux infiniteflux force-pushed the feature-delete-account-info branch from 946ee94 to 19036f9 Compare November 25, 2025 12:15
@david-allison david-allison added squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. and removed Has Conflicts labels Nov 28, 2025
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, cheers. One more round I think

Index: AnkiDroid/src/main/res/layout/dialog_account_removal_explanation.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/res/layout/dialog_account_removal_explanation.xml b/AnkiDroid/src/main/res/layout/dialog_account_removal_explanation.xml
--- a/AnkiDroid/src/main/res/layout/dialog_account_removal_explanation.xml	(revision c27970afc599ec0f98ff2c39dafc55d5db6bb253)
+++ b/AnkiDroid/src/main/res/layout/dialog_account_removal_explanation.xml	(date 1764299227454)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
@@ -38,8 +39,9 @@
             android:layout_weight="1"
             android:textAppearance="?attr/textAppearanceBody1"
             android:textColor="?attr/colorOnSurface"
-            android:ellipsize="end"
-            android:maxLines="1" />
+            android:ellipsize="middle"
+            android:maxLines="1"
+            tools:text="[email protected]"/>
 
         <Button
             android:id="@+id/copy_email_button"

using android:ellipsize="middle leads to a better email experience:

Image

Comment on lines 55 to 58
setPositiveButton(R.string.dialog_ok) { _, _ ->
setFragmentResult(REQUEST_KEY, bundleOf(RESULT_PROCEED to true))
}
setNegativeButton(R.string.dialog_cancel) { _, _ -> }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: positiveButton and negativeButton are a little less verbose, as you can skip the lambda parameters

/**
* Redirect from post-login pages (such as 'verify account') to the required page
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert - the overall 'diff' of your changes shouldn't include whitespace changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@david-allison
Copy link
Member

@Arthur-Milchior Is this what you intended?

- Use ellipsize middle for better email display
- Add tools:text for layout preview
- Simplify button lambdas using positiveButton/negativeButton
- Remove accidental whitespace changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author New contributor squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants