Skip to content

Commit baf31be

Browse files
BrayanDSOlukstbit
authored andcommitted
feat: Show keyboard shortcuts preference
it shows up the system dialog with the available shortcuts if the user has a physical keyboard attached. It helps the discoverability of keyboard shortcuts along the app. After the user knows that the app has keyboard shortcuts, they can use the system shortcut (which can be seen in the dialog itself) in any other screen to see the available shortcuts there
1 parent e5f9af1 commit baf31be

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/preferences/ControlsSettingsFragment.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package com.ichi2.anki.preferences
1717

18+
import android.content.res.Configuration
1819
import androidx.annotation.StringRes
20+
import androidx.preference.Preference
1921
import com.ichi2.anki.CollectionManager.TR
2022
import com.ichi2.anki.R
2123
import com.ichi2.anki.cardviewer.ViewerCommand
@@ -41,6 +43,16 @@ class ControlsSettingsFragment : SettingsFragment() {
4143
.forEach { pref -> pref.value = commands[pref.key]?.defaultValue?.toPreferenceString() }
4244

4345
setDynamicTitle()
46+
47+
// TODO replace the preference with something dismissible. This is meant only to improve
48+
// the discoverability of the system shortcut for the shortcuts dialog.
49+
requirePreference<Preference>(R.string.pref_keyboard_shortcuts_key).apply {
50+
isVisible = resources.configuration.keyboard == Configuration.KEYBOARD_QWERTY
51+
setOnPreferenceClickListener {
52+
requireActivity().requestShowKeyboardShortcuts()
53+
true
54+
}
55+
}
4456
}
4557

4658
private fun setDynamicTitle() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM16,17L8,17v-2h8v2zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z"/>
4+
5+
</vector>

AnkiDroid/src/main/res/values/10-preferences.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<string name="gestures_summ">Assign gestures to actions such as answering and editing cards.</string>
7575
<string name="gestures_corner_touch" maxLength="41">9-point touch</string>
7676
<string name="gestures_corner_touch_summary">Allow touch gestures in screen corners</string>
77+
<string name="show_keyboard_shortcuts" maxLength="41">Show keyboard shortcuts</string>
7778
<string name="gestures_full_screen_nav_drawer" maxLength="41">Full screen navigation drawer</string>
7879
<string name="gestures_fullscreen_nav_drawer_summary">Open navigation drawer when swiped right from anywhere on the screen</string>
7980
<string name="gestures_none" maxLength="41" comment="No gestures">None</string>

AnkiDroid/src/main/res/values/preferences.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<string name="gestures_preference">gestures</string>
8585
<string name="gestures_corner_touch_preference">gestureCornerTouch</string>
8686
<string name="nav_drawer_gesture_key">gestureFullScreenNavigationDrawer</string>
87+
<string name="pref_keyboard_shortcuts_key">showKeyboardShortcuts</string>
8788
<string name="pref_swipe_sensitivity_key">swipeSensitivity</string>
8889
<string name="show_answer_command_key">binding_SHOW_ANSWER</string>
8990
<string name="answer_again_command_key">binding_FLIP_OR_ANSWER_EASE1</string>

AnkiDroid/src/main/res/xml/preferences_controls.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
xmlns:app="http://schemas.android.com/apk/res-auto"
2121
xmlns:tools="http://schemas.android.com/tools"
2222
android:title="@string/pref_cat_controls"
23-
android:key="@string/pref_controls_screen_key">
23+
android:key="@string/pref_controls_screen_key"
24+
tools:context=".preferences.ControlsSettingsFragment">
2425

2526
<SwitchPreferenceCompat
2627
android:defaultValue="false"
@@ -48,7 +49,13 @@
4849
android:defaultValue="100"
4950
android:valueFrom="20"
5051
android:valueTo="180"
51-
app:displayValue="true"/>
52+
app:displayValue="true" />
53+
54+
<Preference
55+
android:key="@string/pref_keyboard_shortcuts_key"
56+
android:title="@string/show_keyboard_shortcuts"
57+
android:icon="@drawable/ic_keyboard"
58+
/>
5259

5360
<PreferenceCategory android:title="@string/answer_buttons">
5461
<com.ichi2.preferences.ControlPreference

AnkiDroid/src/test/java/com/ichi2/anki/analytics/PreferencesAnalyticsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PreferencesAnalyticsTest : RobolectricTest() {
6666
// Preferences that only click: don't have a value
6767
R.string.tts_key, // tts
6868
R.string.pref_reset_languages_key, // resetLanguages
69+
R.string.pref_keyboard_shortcuts_key, // showKeyboardShortcuts
6970
// Opens App Bar buttons fragment
7071
R.string.custom_buttons_link_preference, // custom_buttons_link
7172
// Opens Custom sync server fragment

0 commit comments

Comments
 (0)