File tree Expand file tree Collapse file tree 7 files changed +26
-8
lines changed
Expand file tree Collapse file tree 7 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ class AppPrefs(
126126 const val POPUP_KEY_PRESS_ENABLED = " keyboard__show_key_popup"
127127 const val SHOW_SCHEMA_SWITCHES = " show_schema_switches_in_idle"
128128 const val SHOW_ARROW_IN_SWITCHES = " show_arrow_in_switches"
129+ const val SWITCHES_DEBOUNCE_INTERVAL = " schema_switches_debounce_interval"
129130 const val HIDE_QUICK_BAR = " hide_quick_bar"
130131 const val LANDSCAPE_MODE = " keyboard__landscape_mode"
131132 const val SPLIT_SPACE_PERCENT = " keyboard__split_space"
@@ -162,6 +163,7 @@ class AppPrefs(
162163 val popupKeyPressEnabled = bool(POPUP_KEY_PRESS_ENABLED , false )
163164 val showSchemaSwitches = bool(SHOW_SCHEMA_SWITCHES , true )
164165 val showArrowInSwitches = bool(SHOW_ARROW_IN_SWITCHES , true )
166+ val switchesDebounceInterval = int(SWITCHES_DEBOUNCE_INTERVAL , 300 )
165167 val hideQuickBar = bool(HIDE_QUICK_BAR , false )
166168
167169 enum class LandscapeModeOption {
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class QuickBar(
5454 private val prefs = AppPrefs .defaultInstance()
5555
5656 private val showSwitches by prefs.keyboard.showSchemaSwitches
57+ private val debounceInterval by prefs.keyboard.switchesDebounceInterval
5758 private val hideQuickBar by prefs.keyboard.hideQuickBar
5859
5960 val themedHeight =
@@ -73,7 +74,7 @@ class QuickBar(
7374 AlwaysUi (context, theme).apply {
7475 switchesUi.apply {
7576 setSwitches(SchemaManager .visibleSwitches)
76- setOnSwitchClick { switch ->
77+ setOnSwitchClick( { switch ->
7778 val prevEnabled = switch.enabled
7879 switch.enabled =
7980 if (switch.options.isEmpty()) {
@@ -91,7 +92,7 @@ class QuickBar(
9192 }
9293 }
9394 }
94- }
95+ }, debounceTime = debounceInterval.toLong())
9596 }
9697 }
9798 }
Original file line number Diff line number Diff line change @@ -38,12 +38,12 @@ class SwitchesUi(
3838 switchesAdapter.submitList(list)
3939 }
4040
41- fun setOnSwitchClick (listener : ( Schema . Switch ) -> Unit ) {
42- switchesAdapter.setOnDebouncedItemClick { adapter, _, position ->
43- val typed = (adapter as SwitchesAdapter )
44- if (typed.items.isEmpty()) return @setOnDebouncedItemClick
45- val switch = typed.items[ position]
46- listener(switch )
41+ fun setOnSwitchClick (
42+ listener : ( Schema . Switch ) -> Unit ,
43+ debounceTime : Long = 300L,
44+ ) {
45+ switchesAdapter.setOnDebouncedItemClick(debounceTime) { adapter, _, position ->
46+ (adapter as ? SwitchesAdapter )?.items?.getOrNull(position)?. let (listener )
4747 }
4848 }
4949}
Original file line number Diff line number Diff line change @@ -234,4 +234,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
234234 <string name =" deploy_failure" >部署失败</string >
235235 <string name =" view_deploy_failure_log" >部署失败。点此查看错误日志。</string >
236236 <string name =" hide_quick_bar" >隐藏快捷栏</string >
237+ <string name =" schema_switches_debounce_interval" >方案开关连击间隔</string >
237238</resources >
Original file line number Diff line number Diff line change @@ -234,4 +234,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
234234 <string name =" deploy_failure" >部署失敗</string >
235235 <string name =" view_deploy_failure_log" >部署失敗。點此檢視錯誤日誌。</string >
236236 <string name =" hide_quick_bar" >隱藏快捷欄</string >
237+ <string name =" schema_switches_debounce_interval" >方案開關連擊間隔</string >
237238</resources >
Original file line number Diff line number Diff line change @@ -234,4 +234,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
234234 <string name =" deploy_failure" >Deploy failure</string >
235235 <string name =" view_deploy_failure_log" >Deploy failure. Click here to view error log.</string >
236236 <string name =" hide_quick_bar" >Hide quick bar</string >
237+ <string name =" schema_switches_debounce_interval" >Schema switches debounce interval</string >
237238</resources >
Original file line number Diff line number Diff line change @@ -74,6 +74,18 @@ SPDX-License-Identifier: GPL-3.0-or-later
7474 android : title =" @string/show_arrow_in_switches"
7575 app : dependency =" show_schema_switches_in_idle"
7676 app : iconSpaceReserved =" false" />
77+ <com .osfans.trime.ui.components.DialogSeekBarPreference
78+ android : defaultValue =" 300"
79+ android : key =" schema_switches_debounce_interval"
80+ android : title =" @string/schema_switches_debounce_interval"
81+ app : allowDividerAbove =" false"
82+ app : dependency =" show_schema_switches_in_idle"
83+ app : iconSpaceReserved =" false"
84+ app : max =" 1000"
85+ app : min =" 0"
86+ app : seekBarIncrement =" 10"
87+ app : unit =" @string/unit__time_ms"
88+ app : useSimpleSummaryProvider =" true" />
7789 <SwitchPreferenceCompat
7890 android : defaultValue =" false"
7991 android : key =" hide_quick_bar"
You can’t perform that action at this time.
0 commit comments