-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Make preferences in ControlSettings tabs searchable #19422
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentFactory | |||||||||||||||||||||||
| import androidx.fragment.app.FragmentManager | ||||||||||||||||||||||||
| import androidx.fragment.app.FragmentTransaction | ||||||||||||||||||||||||
| import androidx.fragment.app.commit | ||||||||||||||||||||||||
| import androidx.lifecycle.lifecycleScope | ||||||||||||||||||||||||
| import androidx.preference.Preference | ||||||||||||||||||||||||
| import androidx.preference.PreferenceFragmentCompat | ||||||||||||||||||||||||
| import com.bytehamster.lib.preferencesearch.SearchConfiguration | ||||||||||||||||||||||||
|
|
@@ -46,10 +47,13 @@ import com.ichi2.anki.common.annotations.LegacyNotifications | |||||||||||||||||||||||
| import com.ichi2.anki.preferences.HeaderFragment.Companion.getHeaderKeyForFragment | ||||||||||||||||||||||||
| import com.ichi2.anki.reviewreminders.ReviewReminderScope | ||||||||||||||||||||||||
| import com.ichi2.anki.reviewreminders.ScheduleReminders | ||||||||||||||||||||||||
| import com.ichi2.anki.utils.AnimationUtils.areSystemAnimationsEnabled | ||||||||||||||||||||||||
| import com.ichi2.anki.utils.ext.sharedPrefs | ||||||||||||||||||||||||
| import com.ichi2.anki.utils.isWindowCompact | ||||||||||||||||||||||||
| import com.ichi2.themes.Themes | ||||||||||||||||||||||||
| import com.ichi2.utils.FragmentFactoryUtils | ||||||||||||||||||||||||
| import kotlinx.coroutines.delay | ||||||||||||||||||||||||
| import kotlinx.coroutines.launch | ||||||||||||||||||||||||
| import timber.log.Timber | ||||||||||||||||||||||||
| import kotlin.reflect.KClass | ||||||||||||||||||||||||
| import kotlin.reflect.jvm.jvmName | ||||||||||||||||||||||||
|
|
@@ -137,8 +141,22 @@ class PreferencesFragment : | |||||||||||||||||||||||
| addToBackStack(fragment.javaClass.name) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Timber.i("Highlighting key '%s' on %s", result.key, fragment) | ||||||||||||||||||||||||
| result.highlight(fragment as PreferenceFragmentCompat) | ||||||||||||||||||||||||
| if (fragment is ControlsSettingsFragment) { | ||||||||||||||||||||||||
| fragment.lifecycleScope.launch { | ||||||||||||||||||||||||
| if (areSystemAnimationsEnabled(requireContext())) { | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this only check system animations, ignoring the in-app 'safe display mode' Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt Lines 282 to 292 in 1be4ad3
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tested with system animations disabled, the tab selection and preference highlighting don't work in the 'Animations disabled - do everything immediately' case. I think we need delays regardless of the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this sat, could you provide reproduction steps or a video |
||||||||||||||||||||||||
| delay(100) | ||||||||||||||||||||||||
| fragment.selectTabForPreference(result.key) | ||||||||||||||||||||||||
| delay(150) | ||||||||||||||||||||||||
| result.highlight(fragment as PreferenceFragmentCompat) | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| // Animations disabled - do everything immediately | ||||||||||||||||||||||||
| fragment.selectTabForPreference(result.key) | ||||||||||||||||||||||||
| result.highlight(fragment as PreferenceFragmentCompat) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| result.highlight(fragment as PreferenceFragmentCompat) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private fun setupBackCallbacks() { | ||||||||||||||||||||||||
|
|
@@ -282,6 +300,8 @@ fun getFragmentFromXmlRes( | |||||||||||||||||||||||
| R.xml.preferences_notifications -> NotificationsSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_appearance -> AppearanceSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_controls -> ControlsSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_reviewer_controls -> ControlsSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_previewer_controls -> ControlsSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_advanced -> AdvancedSettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_accessibility -> AccessibilitySettingsFragment() | ||||||||||||||||||||||||
| R.xml.preferences_dev_options -> DevOptionsFragment() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2025 Sanjay Sargam <[email protected]> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.ichi2.anki.utils | ||
|
|
||
| import android.content.Context | ||
| import android.provider.Settings | ||
|
|
||
| /** | ||
| * Utility class for animation-related helper functions | ||
| */ | ||
| object AnimationUtils { | ||
| /** | ||
| * Checks if system animations are enabled by verifying all animation scale settings. | ||
| * | ||
| * This function returns false if any of the mentioned system animations are disabled (0f), | ||
| * which addresses safe display mode and accessibility concerns. | ||
| * | ||
| * ANIMATION_DURATION_SCALE - controls app switching animation speed. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the docs, apparently checking only this one is necessary. https://developer.android.com/reference/android/provider/Settings.Global#TRANSITION_ANIMATION_SCALE
On my phone (Android 16, Samsung), those scales can be changed only in the phone developer options. The public user facing setting only allows reducing animations in general. You don't need to take any action based on this comment, but it's something that I think it's worth noting so the method may be simplified or better documented later. |
||
| * TRANSITION_ANIMATION_SCALE - controls app window opening and closing animation speed | ||
| * WINDOW_ANIMATION_SCALE - controls pop-up window opening and closing animation speed | ||
| * | ||
| * @param context The context used to access system settings | ||
| * @return true if all animation scales are non-zero, false otherwise | ||
| */ | ||
| fun areSystemAnimationsEnabled(context: Context): Boolean = | ||
| try { | ||
| val animDuration = | ||
| Settings.Global.getFloat( | ||
| context.contentResolver, | ||
| Settings.Global.ANIMATOR_DURATION_SCALE, | ||
| 1f, | ||
| ) | ||
| val animTransition = | ||
| Settings.Global.getFloat( | ||
| context.contentResolver, | ||
| Settings.Global.TRANSITION_ANIMATION_SCALE, | ||
| 1f, | ||
| ) | ||
| val animWindow = | ||
| Settings.Global.getFloat( | ||
| context.contentResolver, | ||
| Settings.Global.WINDOW_ANIMATION_SCALE, | ||
| 1f, | ||
| ) | ||
| animDuration != 0f && animTransition != 0f && animWindow != 0f | ||
| } catch (e: Exception) { | ||
| true // Default to animations enabled if unable to read settings | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.