File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed
main/java/com/ichi2/anki/preferences
test/java/com/ichi2/anki/preferences Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,24 @@ class ControlsSettingsFragment :
6161 setupNewStudyScreenSettings()
6262 }
6363
64+ /* *
65+ * Selects the appropriate tab based on a preference key from search results.
66+ * This allows search navigation to automatically switch to the correct tab.
67+ */
68+ fun selectTabForPreference (key : String ) {
69+ val targetTabIndex = actionToScreenMap[key]?.ordinal
70+ if (targetTabIndex == null ) {
71+ Timber .w(" Could not find the preference with %s key" , key)
72+ return
73+ }
74+
75+ view?.post {
76+ requirePreference<ControlsTabPreference >(
77+ R .string.pref_controls_tab_layout_key,
78+ ).selectTab(targetTabIndex)
79+ }
80+ }
81+
6482 private fun setControlPreferencesDefaultValues (screen : ControlPreferenceScreen ) {
6583 val commands = screen.getActions().associateBy { it.preferenceKey }
6684 val prefs = sharedPrefs()
@@ -157,6 +175,12 @@ class ControlsSettingsFragment :
157175 }
158176
159177 companion object {
178+ val actionToScreenMap: Map <String , ControlPreferenceScreen > =
179+ ControlPreferenceScreen .entries
180+ .flatMap { screen ->
181+ screen.getActions().map { action -> action.preferenceKey to screen }
182+ }.toMap()
183+
160184 val legacyStudyScreenSettings =
161185 listOf (
162186 R .string.save_voice_command_key,
Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ class ControlsTabPreference
4545 tabLayout?.addOnTabSelectedListener(listener)
4646 }
4747
48+ /* *
49+ * Selects a tab programmatically by position.
50+ * @param tabPosition The position of the tab to select.
51+ */
52+ fun selectTab (tabPosition : Int ) {
53+ tabLayout?.selectTab(tabLayout?.getTabAt(tabPosition))
54+ }
55+
4856 override fun onBindViewHolder (holder : PreferenceViewHolder ) {
4957 super .onBindViewHolder(holder)
5058 tabLayout = holder.itemView as ? TabLayout
Original file line number Diff line number Diff line change @@ -130,6 +130,12 @@ class HeaderFragment : SettingsFragment() {
130130 .addBreadcrumb(R .string.pref_cat_appearance)
131131 }
132132 index(R .xml.preferences_controls)
133+ index(R .xml.preferences_reviewer_controls)
134+ .addBreadcrumb(activity.getString(R .string.pref_cat_controls))
135+ .addBreadcrumb(activity.getString(R .string.pref_controls_reviews_tab))
136+ index(R .xml.preferences_previewer_controls)
137+ .addBreadcrumb(activity.getString(R .string.pref_cat_controls))
138+ .addBreadcrumb(activity.getString(R .string.pref_controls_previews_tab))
133139 index(R .xml.preferences_accessibility)
134140 index(R .xml.preferences_backup_limits)
135141 ignorePreference(activity.getString(R .string.pref_backups_help_key))
Original file line number Diff line number Diff line change @@ -68,10 +68,18 @@ class PrefsSearchBarTest : RobolectricTest() {
6868 val fragment = getFragmentFromXmlRes(resId)
6969
7070 assertNotNull(fragment)
71+
72+ // Special handling for ControlsSettingsFragment which handles multiple XML resources
73+ val expectedResourceId =
74+ when (fragment) {
75+ is ControlsSettingsFragment -> fragment.preferenceResource
76+ else -> resId
77+ }
78+
7179 assertThat(
72- " ${targetContext.resources.getResourceName(resId)} should match the preferenceResource of ${fragment::class .simpleName} " ,
80+ " ${targetContext.resources.getResourceName(resId)} should be handled by ${fragment::class .simpleName} " ,
7381 fragment.preferenceResource,
74- equalTo(resId ),
82+ equalTo(expectedResourceId ),
7583 )
7684 }
7785 }
You can’t perform that action at this time.
0 commit comments