-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: Settings highlight does not follow 'back button' #17447
Conversation
@jainv4156 , can you complete all the details in the PR template? Thanks! |
just to be sure ,do you mean testing with accessibility scanner. |
It's about the description and the approach you used, present in the template |
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.
seems reasonable - tiny nitpicks just a typo
@@ -43,7 +42,7 @@ class HeaderFragment : PreferenceFragmentCompat() { | |||
highlightHeaderPreference(requirePreference<HeaderPreference>(selectedHeaderPreferenceKey)) | |||
|
|||
requirePreference<HeaderPreference>(R.string.pref_backup_limits_screen_key) | |||
.title = CollectionManager.TR.preferencesBackups() | |||
.title = TR.preferencesBackups() |
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.
this is a reasonable change but is a refactor (along with the removal of collection manager - and I was curious why it was in the same commit - we usually split refactor stuff into separate commits so that review stays focused on the functional changes. No big deal this time though - just something to keep in the mind when developing in the future - think of the person that will review your code and make sure you keep their attention focused on the important bits by not including unimportant bits at the same time
@@ -105,6 +104,10 @@ class HeaderFragment : PreferenceFragmentCompat() { | |||
requirePreference<Preference>(R.string.pref_dev_options_screen_key).isVisible = isVisible | |||
} | |||
|
|||
fun handelHighlightHeaderPreferenceOnBack(key: String) { |
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.
typo
fun handelHighlightHeaderPreferenceOnBack(key: String) { | |
fun handleHighlightHeaderPreferenceOnBack(key: String) { |
val fragmentManager = supportFragmentManager | ||
if (key != null) { | ||
val headerFragment = (fragmentManager.findFragmentById(R.id.lateral_nav_container) as? HeaderFragment) | ||
headerFragment?.handelHighlightHeaderPreferenceOnBack(key) |
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.
typo
headerFragment?.handelHighlightHeaderPreferenceOnBack(key) | |
headerFragment?.handleHighlightHeaderPreferenceOnBack(key) |
@@ -100,6 +100,15 @@ abstract class SettingsFragment : | |||
dialogFragment.show(parentFragmentManager, "androidx.preference.PreferenceFragment.DIALOG") | |||
} | |||
|
|||
override fun onResume() { | |||
super.onResume() | |||
preferenceScreen?.key?.let { |
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.
(requireActivity() as Preferences)
This is going to conflict with
Please be sure that this method would work once the fragment is extracted from the activity
@@ -100,6 +100,15 @@ abstract class SettingsFragment : | |||
dialogFragment.show(parentFragmentManager, "androidx.preference.PreferenceFragment.DIALOG") | |||
} | |||
|
|||
override fun onResume() { | |||
super.onResume() | |||
preferenceScreen?.key?.let { |
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.
This isn't necessary. handleHighlightPreferenceOnBack
handles a nullable string
(requireActivity() as Preferences).handleHighlightPreferenceOnBack(preferenceScreen.key)
without the let {
will work
fun handleHighlightPreferenceOnBack(key: String?) { | ||
val fragmentManager = supportFragmentManager | ||
if (key != null) { | ||
val headerFragment = (fragmentManager.findFragmentById(R.id.lateral_nav_container) as? HeaderFragment) | ||
headerFragment?.handelHighlightHeaderPreferenceOnBack(key) | ||
} | ||
} |
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.
Extract finding the header fragment into a property so the intent of the method is clear:
fun handleHighlightPreferenceOnBack(key: String?) {
if (key == null) return
lateralNavigationFragment?.handleHighlightHeaderPreferenceOnBack(key)
}
Thanks, @david-allison , for mentioning this PR #17487 to me. I checked my implementation by bringing these PR changes locally. As this PR introduces a lot of changes to my implementation, would it be okay if I continue working on my PR after this one is merged? |
That PR also fixes the issue, and closes this PR. So it won't be necessary to continue working on this PR after that. Sorry for the time spent here. |
sure |
Purpose / Description
Approach
When the back button is pressed, the current fragment is popped from the back stack, and the previous fragment is displayed.
The
onResume
method of the newly visible fragment is triggered.In the
onResume
method, the current fragment passes its unique key to the associatedPreferences
activity.The
Preferences
activity locates theHeaderFragment
using the fragment manager and passes the received key to it.The
HeaderFragment
uses the key to identify the appropriate header and highlights it.Description of Changes
HeaderFragment.kt
handleHighlightHeaderPreferenceOnBack
Preferences.kt
handleHighlightPreferenceOnBack
HeaderFragment
instance.handleHighlightHeaderPreferenceOnBack
method on theHeaderFragment
.SettingsFragment.kt
onResume
Method:handleHighlightPreferenceOnBack
method fromPreferences
to handle the highlighting logic.Fixes
Checklist
Please, go through these checks before submitting the PR.
Screen_recording_20241115_173821.webm