Skip to content

Commit 2276540

Browse files
committed
feat: add setting to hide quick bar when always show candidates window
1 parent 9850e71 commit 2276540

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

app/src/main/java/com/osfans/trime/data/prefs/AppPrefs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ class AppPrefs(
190190
companion object {
191191
const val MODE = "show_candidates_window"
192192
const val POSITION = "candidates_window_position"
193+
const val HIDE_QUICK_BAR = "hide_quick_bar"
193194
}
194195

195196
val mode = enum(R.string.show_candidates_window, MODE, PopupCandidatesMode.DISABLED)
196197
val position = enum(R.string.candidates_window_position, POSITION, PopupPosition.BOTTOM_LEFT)
198+
val hideQuickBar = switch(R.string.hide_quick_bar_when_always_show, HIDE_QUICK_BAR, false)
197199
}
198200

199201
/**

app/src/main/java/com/osfans/trime/data/prefs/PreferenceDelegateOwner.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ abstract class PreferenceDelegateOwner(
6161
},
6262
)
6363

64+
protected fun switch(
65+
@StringRes
66+
title: Int,
67+
key: String,
68+
defaultValue: Boolean,
69+
@StringRes
70+
summary: Int? = null,
71+
enableUiOn: (() -> Boolean)? = null,
72+
): PreferenceDelegate<Boolean> {
73+
val pref = PreferenceDelegate(sharedPreferences, key, defaultValue)
74+
val ui = PreferenceDelegateUi.Switch(title, key, defaultValue, summary, enableUiOn)
75+
pref.register()
76+
ui.registerUi()
77+
return pref
78+
}
79+
6480
// TODO: replace all [enum] with this
6581
protected inline fun <reified T> enum(
6682
@StringRes title: Int,

app/src/main/java/com/osfans/trime/data/prefs/PreferenceDelegateUi.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.Context
88
import androidx.annotation.StringRes
99
import androidx.preference.ListPreference
1010
import androidx.preference.Preference
11+
import androidx.preference.SwitchPreference
1112

1213
abstract class PreferenceDelegateUi<T : Preference>(
1314
val key: String,
@@ -17,6 +18,28 @@ abstract class PreferenceDelegateUi<T : Preference>(
1718

1819
fun isEnabled() = enableUiOn?.invoke() ?: true
1920

21+
class Switch(
22+
@StringRes
23+
val title: Int,
24+
key: String,
25+
val defaultValue: Boolean,
26+
@StringRes
27+
val summary: Int? = null,
28+
enableUiOn: (() -> Boolean)? = null,
29+
) : PreferenceDelegateUi<SwitchPreference>(key, enableUiOn) {
30+
override fun createUi(context: Context) =
31+
SwitchPreference(context).apply {
32+
key = this@Switch.key
33+
isIconSpaceReserved = false
34+
isSingleLineTitle = false
35+
setDefaultValue(defaultValue)
36+
if (this@Switch.summary != null) {
37+
setSummary(this@Switch.summary)
38+
}
39+
setTitle(this@Switch.title)
40+
}
41+
}
42+
2043
class StringList<T : Any>(
2144
@StringRes
2245
val title: Int,

app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff 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 hideQuickBar by prefs.candidates.hideQuickBar
5758

5859
val themedHeight =
5960
theme.generalStyle.candidateViewHeight + theme.generalStyle.commentHeight
@@ -182,9 +183,7 @@ class QuickBar(
182183
ViewAnimator(context).apply {
183184
rime.launchOnReady {
184185
visibility =
185-
if (it.getRuntimeOption("_hide_candidate") ||
186-
it.getRuntimeOption("_hide_bar")
187-
) {
186+
if (hideQuickBar && candidatesMode == PopupCandidatesMode.ALWAYS_SHOW) {
188187
View.GONE
189188
} else {
190189
View.VISIBLE
@@ -223,9 +222,6 @@ class QuickBar(
223222
"_hide_comment" -> {
224223
// candidateUi.candidates.shouldShowComment = !value.value
225224
}
226-
"_hide_candidate", "_hide_bar" -> {
227-
view.visibility = if (value.value) View.GONE else View.VISIBLE
228-
}
229225
}
230226
if (alwaysUi.currentState == AlwaysUi.State.Switches) {
231227
service.lifecycleScope.launch {

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
233233
<string name="candidates_window_position">候选词窗口位置</string>
234234
<string name="deploy_failure">部署失败</string>
235235
<string name="view_deploy_failure_log">部署失败。点此查看错误日志。</string>
236+
<string name="hide_quick_bar_when_always_show">始终显示候选词窗口时隐藏快捷栏</string>
236237
</resources>

app/src/main/res/values-zh-rTW/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
233233
<string name="candidates_window_position">候選詞視窗位置</string>
234234
<string name="deploy_failure">部署失敗</string>
235235
<string name="view_deploy_failure_log">部署失敗。點此檢視錯誤日誌。</string>
236+
<string name="hide_quick_bar_when_always_show">始終顯示候選詞視窗時隱藏快捷欄</string>
236237
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
233233
<string name="candidates_window_position">Candidates window position</string>
234234
<string name="deploy_failure">Deploy failure</string>
235235
<string name="view_deploy_failure_log">Deploy failure. Click here to view error log.</string>
236+
<string name="hide_quick_bar_when_always_show">Hide quick bar when always show candidates window</string>
236237
</resources>

0 commit comments

Comments
 (0)