-
-
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: use default constructor / factory + Arguments init style #17488
fix: use default constructor / factory + Arguments init style #17488
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
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.
Fully agreed with empty constructors for Fragments and passing stuff with arguments. Following the Android way of things is normally the most sane alternative.
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
Okay, going to take that preliminary note of approval for the style, Kotlin-ify it, and try another Dialog Fragment or two |
6d52349
to
b517320
Compare
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
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.
Yes, dialogs with constructor parameters that don't use a fragment factory should be refactored.
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
b517320
to
da2c5e5
Compare
Turns out there was only one other DialogFragment with a problem like this (no default constructor) and it has a Factory but it must just not get installed correctly every time. I'm not going to add that commit here, I'll work it in a separate PR So this is ready to go I've adopted all the feedback to make this more Kotlin-y (and extract string constants) - thank you! Three people approved but there were enough little changes from the feedback I think at least one other person should take a final look before merge so I am repinging the reviewers but hopefully (since it is a simple change) it's easy and done |
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.
Minor improvement with constants I believe, code is good
Although I stated that the styles of getter
was inconsistent, I prefer them the way they are now.
The following looks ugly to me
private val isTruncated by lazy {
when (arguments?.getBoolean("isTruncated")) {
true -> true
false -> false
null -> {
Timber.w("BrowserOptionsDialog instantiated without configuration.")
false
}
}
@IdRes val selectedButtonId = | ||
dialogView.findViewById<RadioGroup>(R.id.select_browser_mode).checkedRadioButtonId | ||
val newCardsOrNotes = | ||
if (selectedButtonId == R.id.select_cards_mode) CardsOrNotes.CARDS else CardsOrNotes.NOTES |
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.
Note: this is now just a spacing change
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt
Outdated
Show resolved
Hide resolved
this allows Fragment lifecycle save/restore to work seemlessly and that fixes crashes on Activity restarts
da2c5e5
to
4dc36ce
Compare
Purpose / Description
this allows Fragment lifecycle save/restore to work seemlessly and that fixes crashes on Activity restarts
NOTE THAT IF THIS STYLE IS OKAY - A FEW OTHER DIALOGS NEED FIXES IN SAME STYLE[edit: turns out this was the only easy one like this - so just one commit]
Fixes
Approach
Used the approach mentioned here https://stackoverflow.com/a/51831137/9910298
How Has This Been Tested?
Everything seems to work
browser-options-crashfix.webm
Learning (optional, can help others)
Now we don't just have Activity lifecycle problems, we have Fragment lifecycle problems. Great
Checklist
Please, go through these checks before submitting the PR.