-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix state restore bug in FindAndReplaceDialogFragment #19981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To get the current selected notes the fragment is querying the browser's ViewModel for the selected notes. This works most of the times but fails(we lose the selection and will target everything instead of only the selected notes) when going to the background and coming back(and fragment gets recreated). At this point the fragment tries to access again the selected notes but these are not available as they are being manually restored from a file. This bug can be seen by using the "Don't keep activities" dev option. The fix consists in using an IdsFile so the fragment always has a reference to the selected notes from the moment of its creation.
bdffe19 to
a7cd900
Compare
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to handle IdsFile being missing
This is a common issue
| companion object { | ||
| const val TAG = "FindAndReplaceDialogFragment" | ||
| const val REQUEST_FIND_AND_REPLACE = "request_find_and_replace" | ||
| const val ARG_IDS = " arg_ids" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const val ARG_IDS = " arg_ids" | |
| const val ARG_IDS = "arg_ids" |
| val idsFile = | ||
| requireNotNull( | ||
| BundleCompat.getParcelable( | ||
| requireArguments(), | ||
| ARG_IDS, | ||
| IdsFile::class.java, | ||
| ), | ||
| ) | ||
| val noteIds = idsFile.getIds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add handling for the file being deleted
| context: Context, | ||
| noteIds: List<NoteId>, | ||
| ): FindAndReplaceDialogFragment { | ||
| val file = IdsFile(context.cacheDir, noteIds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a common issue that IdsFile is not deleted after the activity/fragment/dialog is disposed.
Is it feasible to handle this in the PR for this fragment?
| context: Context, | ||
| noteIds: List<NoteId>, | ||
| ): FindAndReplaceDialogFragment { | ||
| val file = IdsFile(context.cacheDir, noteIds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a name to the IdsFile, this will make it easier to clean up our 'bad' IdsFile implementation at a future date
🤔 which bug ? |
Purpose / Description
Fixes a state restore bug for find and replace fragment where previously selected notes would get ignored when coming back from the background. This is not great because if the user doesn't notice he's going to run the find and replace operation over his entire collection. See bug:
Screen_recording_20251230_192801.webm
I used our IdsFile implementation to not query the browser's ViewModel. I'm not enthusiastic about this but it works, the browser could probably be changed to fix this but I didn't look into it.
With the code in this PR:
Screen_recording_20251230_191350.webm
Fixes
How Has This Been Tested?
Checked the bug scenario, ran tests.
Checklist