File tree Expand file tree Collapse file tree 7 files changed +52
-10
lines changed
test/java/com/ichi2/anki/servicemodel Expand file tree Collapse file tree 7 files changed +52
-10
lines changed Original file line number Diff line number Diff line change @@ -485,7 +485,7 @@ object UsageAnalytics {
485485 R .string.learn_cutoff_preference, // Learn ahead limit
486486 R .string.time_limit_preference, // Timebox time limit
487487 R .string.keep_screen_on_preference, // Disable screen timeout
488- R .string.double_tap_time_interval_preference , // Double tap time interval (milliseconds)
488+ R .string.double_tap_timeout_pref_key , // Double tap time interval (milliseconds)
489489 // ******************************** Sync ***************************************************
490490 R .string.sync_fetch_media_key, // Fetch media on sync
491491 R .string.automatic_sync_choice_key, // Automatic synchronization
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ import com.ichi2.utils.HashUtil.hashSetInit
5757import timber.log.Timber
5858import java.util.Locale
5959import kotlin.collections.ArrayList
60+ import kotlin.math.round
6061
6162private typealias VersionIdentifier = Int
6263private typealias LegacyVersionIdentifier = Long
@@ -128,6 +129,7 @@ object PreferenceUpgradeService {
128129 yield (UpgradeBrowserColumns ())
129130 yield (RemoveLastExportedAtTime ())
130131 yield (RemoveLongTouchGesture ())
132+ yield (UpgradeDoubleTapTimeout ())
131133 }
132134
133135 /* * Returns a list of preference upgrade classes which have not been applied */
@@ -695,6 +697,26 @@ object PreferenceUpgradeService {
695697 }
696698 }
697699 }
700+
701+ internal class UpgradeDoubleTapTimeout : PreferenceUpgrade (22 ) {
702+ override fun upgrade (preferences : SharedPreferences ) {
703+ val oldPrefKey = " doubleTapTimeInterval"
704+ val value = preferences.getInt(oldPrefKey, - 1 )
705+ if (value == - 1 ) return
706+ val newValue =
707+ if (value > 1000 ) {
708+ 1000
709+ } else {
710+ val result = value / 10.0
711+ val roundedResult = round(result)
712+ (roundedResult * 10 ).toInt()
713+ }
714+ preferences.edit {
715+ remove(oldPrefKey)
716+ putInt(" doubleTapTimeout" , newValue)
717+ }
718+ }
719+ }
698720 }
699721}
700722
Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ object Prefs {
179179
180180 // **************************************** Reviewer **************************************** //
181181
182- val doubleTapInterval by intPref(R .string.double_tap_time_interval_preference , defaultValue = 200 )
182+ val doubleTapInterval by intPref(R .string.double_tap_timeout_pref_key , defaultValue = 200 )
183183 val ignoreDisplayCutout by booleanPref(R .string.ignore_display_cutout_key, false )
184184 val autoFocusTypeAnswer by booleanPref(R .string.type_in_answer_focus_key, true )
185185 val showAnswerFeedback by booleanPref(R .string.show_answer_feedback_key, defaultValue = true )
Original file line number Diff line number Diff line change 139139 <string name =" disable_extended_text_ui_summ" >Allows \'Cloze Deletion\' context menu when in landscape mode.</string >
140140 <string name =" vertical_centering" maxLength =" 41" >Center align</string >
141141 <string name =" vertical_centering_summ" >Center the content of cards vertically</string >
142- <string name =" pref_double_tap_time_interval" maxLength =" 41" >Double tap time interval (milliseconds) </string >
142+ <string name =" pref_double_tap_time_interval" maxLength =" 41" >Double tap time interval</string >
143143 <string name =" pref_double_tap_time_interval_summary" >A second tap of the answer buttons will be ignored if this time has not elapsed. This prevents accidental double taps</string >
144144 <string name =" pref_show_answer_long_press_time" maxLength =" 41" >Show answer long-press time</string >
145145 <string name =" pref_show_answer_long_press_time_summary" >Minimum pressing time before the show answer button registers a touch.</string >
Original file line number Diff line number Diff line change 1313 <string name =" learn_cutoff_preference" >learnCutoff</string >
1414 <string name =" time_limit_preference" >timeLimit</string >
1515 <string name =" keep_screen_on_preference" >keepScreenOn</string >
16- <string name =" double_tap_time_interval_preference " >doubleTapTimeInterval </string >
16+ <string name =" double_tap_timeout_pref_key " >doubleTapTimeout </string >
1717 <!-- Sync -->
1818 <string name =" pref_sync_screen_key" >syncScreen</string >
1919 <string name =" sync_account_key" >syncAccount</string >
Original file line number Diff line number Diff line change 5555 android : key =" @string/keep_screen_on_preference"
5656 android : summary =" @string/pref_keep_screen_on_summ"
5757 android : title =" @string/pref_keep_screen_on" />
58- <com .ichi2.preferences.NumberRangePreferenceCompat
59- android : defaultValue =" 200"
60- android : key =" @string/double_tap_time_interval_preference"
61- android : summary =" @string/pref_double_tap_time_interval_summary"
58+ <com .ichi2.preferences.SliderPreference
59+ android : key =" @string/double_tap_timeout_pref_key"
6260 android : title =" @string/pref_double_tap_time_interval"
63- app : min =" 0"
64- app : max =" 2000" />
61+ android : summary =" @string/pref_double_tap_time_interval_summary"
62+ android : valueFrom =" 0"
63+ android : valueTo =" 1000"
64+ android : defaultValue =" 200"
65+ android : stepSize =" 10"
66+ app1 : displayFormat =" @string/pref_milliseconds"
67+ />
6568 </PreferenceCategory >
6669</PreferenceScreen >
Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ class PreferenceUpgradeServiceTest : RobolectricTest() {
174174 assertThat(prefs.getString(" syncFetchMedia" , null ), equalTo(" never" ))
175175 }
176176
177+ @Test
178+ fun `Double tap timeout is converted correctly` () {
179+ fun testValue (
180+ oldValue : Int ,
181+ expectedValue : Int ,
182+ ) {
183+ prefs.edit { putInt(" doubleTapTimeInterval" , oldValue) }
184+ PreferenceUpgrade .UpgradeDoubleTapTimeout ().performUpgrade(prefs)
185+ assertThat(prefs.getInt(" doubleTapTimeout" , - 1 ), equalTo(expectedValue))
186+ }
187+ testValue(oldValue = 395 , expectedValue = 400 )
188+ testValue(oldValue = 25 , expectedValue = 20 )
189+ testValue(oldValue = 200 , expectedValue = 200 )
190+ testValue(oldValue = 0 , expectedValue = 0 )
191+ testValue(oldValue = 1350 , expectedValue = 1000 )
192+ }
193+
177194 // ############################
178195 // ##### UpgradeAppLocale #####
179196 // ############################
You can’t perform that action at this time.
0 commit comments