-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fix: attach custom study dialog fragment factory in SinglePageActivity to avoid crash #17508
fix: attach custom study dialog fragment factory in SinglePageActivity to avoid crash #17508
Conversation
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.
I don't like this; we should move to a much simpler model. For now, adding the listener to the problematic page would be cleaner
I don't support turning a 'method not implemented' into a runtime no-op which doesn't appear in ACRA
Simpler model
Inlining the interface, we have
// CustomStudyListener
fun onExtendStudyLimits()
fun showDialogFragment(newFragment: DialogFragment)
fun dismissAllDialogFragments()
fun startActivity(intent: Intent)
// CreateCustomStudySessionListener
fun hideProgressBar()
fun onCreateCustomStudySession()
fun showProgressBar()
- [hide/show]ProgressBar can be replaced with
launchCatchingTask
startActivity
,dismissAllDialogFragments
andshowDialogFragment
byrequireAnkiActivity()
This leaves us with:
onExtendStudyLimits()
onCreateCustomStudySession()
Inside the Fragment, both of these are called as a terminal action, and should be using the Fragment Result API
~~We're in this position because we over-abstract the 'rebuildCram' function, which is ~5 lines of code, and is NOT terminal when called from StudyOptionsFragment
~~
That's a reasonable stance, and the work here is just a couple minutes, doing it the completely-opposite-way as you suggest is also just the work of a couple minutes, and I was able to reproduce the crash so it's an easy one Will alter style and re-push All the other commentary is - I think - best suited to a new issue peeled off this one, based on that comment. It's a real refactor, I'm looking for minimal-surgical-intervention to keep it easy to understand + easily testable + cherry-pickable |
Definitely out of scope for this PR. Apologies I didn't make that clear. |
this avoids a lifecycle crash where SingleFragmentActivity may crash on activity-recreation if it is hosting the CongratsPage which hosts the CustomStudyDialog, since CustomStudyDialog fragment does not have a default constructor - it strictly requires its custom factory to be installed
4e57832
to
b2d34de
Compare
The amount of work involved made it clear 😆 - no worries, didn't spend an extra second on it Appears to pass all my manual testing, same as other style |
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.
LGTM as a quick fix.
The complete solution is to remove the need for a factory. The fragment shouldn't require the collection to be passed in(whatever access it needs should be done through CollectionManager directly) and the listener could be replaced with the FragmentResults apis.
Also we should refrain from adding functionality that is not general to SingleFragmentActivity, my understanding is that the activity was intended as a simple container for our backend pages fragments.
@lukstbit totally agreed on the smelly-ness of this temp fix, David's already got a couple PRs up that trim down the custom tag dialog factory/listener/callback/everything needs so all this will hopefully be evicted with a good refactor shortly |
There were two Activities that attached the custom factory for custom study dialog in onCreate, but there were three that needed it (SinglePageActivity hosting CongratsPage fragment hosting study options was missing)
If you didn't attach in onCreate then you would crash if the fragment/activity lifecycle had done a cycle on you due to background kill or don't keep activities on
Purpose / Description
Describe the problem or feature and motivation
Fixes
https://ankidroid.org/acra/app/1/bug/237277/report/ecbf20ba-e077-4952-ae40-14d56647ad99
Combined with this logcat showing the offender:
Approach
Implement CustomStudyListener in SinglePageActivity as a temporary solution to fix this crash, before a better refactoring that fixes the area
How Has This Been Tested?
1- turn on developer options -> don't keep activities so we trigger lifecycle changes when app backgrounds
2- create new deck with one card, review the card, see the congrats page
3- tap the link for custom study to open the dialog
4- background the app, foreground the app
5- see crash without patch, no crash with patch
I also tested other pathways that I knew use other fragment factories like the BrowserOptions one (card browser -> actions bar menu -> options -> change stuff / do lifecycle transitions) and this did not break those, so our fragment factory delegation is working correctly
Learning (optional, can help others)
Our fragment factory here is pretty complicated but...I guess it works.
Fragment lifecycle requires that we attach that fragment factory in Activity.onCreate if there is no default constructor though, otherwise the default fragment factory will crash while trying to call the default constructor
(similar to #17488 but here it is not feasible to make a default constructor - tried that, ugly change)
Checklist
Please, go through these checks before submitting the PR.