Skip to content

Commit 31aa00b

Browse files
committed
refactor: rename InlinePreeditMode to ComposingTextMode and set DISABLED as default value
1 parent b449368 commit 31aa00b

File tree

13 files changed

+99
-31
lines changed

13 files changed

+99
-31
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import androidx.preference.PreferenceManager
1010
import com.osfans.trime.R
1111
import com.osfans.trime.data.base.DataManager
1212
import com.osfans.trime.ime.candidates.popup.PopupCandidatesMode
13+
import com.osfans.trime.ime.core.ComposingTextMode
1314
import com.osfans.trime.ime.enums.FullscreenMode
14-
import com.osfans.trime.ime.enums.InlinePreeditMode
1515
import com.osfans.trime.util.appContext
1616
import java.lang.ref.WeakReference
1717

@@ -37,6 +37,7 @@ class AppPrefs(
3737
}
3838

3939
val internal = Internal(shared)
40+
val general = General(shared).register()
4041
val keyboard = Keyboard(shared)
4142
val theme = Theme(shared)
4243
val profile = Profile(shared)
@@ -91,14 +92,23 @@ class AppPrefs(
9192
var pid by int(PID, 0)
9293
}
9394

95+
class General(
96+
shared: SharedPreferences,
97+
) : PreferenceDelegateOwner(shared, R.string.general) {
98+
companion object {
99+
const val COMPOSING_TEXT_MODE = "composing_text_mode"
100+
}
101+
102+
val composingTextMode = enum(R.string.composing_text_mode, COMPOSING_TEXT_MODE, ComposingTextMode.DISABLE)
103+
}
104+
94105
/**
95106
* Wrapper class of keyboard settings.
96107
*/
97108
class Keyboard(
98109
shared: SharedPreferences,
99110
) : PreferenceDelegateOwner(shared) {
100111
companion object {
101-
const val INLINE_PREEDIT_MODE = "keyboard__inline_preedit"
102112
const val SOFT_CURSOR_ENABLED = "keyboard__soft_cursor"
103113
const val POPUP_KEY_PRESS_ENABLED = "keyboard__show_key_popup"
104114
const val SWITCHES_ENABLED = "keyboard__show_switches"
@@ -134,7 +144,6 @@ class AppPrefs(
134144
const val REPEAT_INTERVAL = "keyboard__key_repeat_interval"
135145
}
136146

137-
var inlinePreedit by enum(INLINE_PREEDIT_MODE, InlinePreeditMode.PREVIEW)
138147
var fullscreenMode by enum(FULLSCREEN_MODE, FullscreenMode.AUTO_SHOW)
139148
val softCursorEnabled by bool(SOFT_CURSOR_ENABLED, true)
140149
val popupKeyPressEnabled by bool(POPUP_KEY_PRESS_ENABLED, false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015 - 2024 Rime community
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package com.osfans.trime.ime.core
7+
8+
import androidx.annotation.StringRes
9+
import com.osfans.trime.R
10+
import com.osfans.trime.data.prefs.PreferenceDelegateEnum
11+
12+
enum class ComposingTextMode(
13+
@StringRes override val stringRes: Int,
14+
) : PreferenceDelegateEnum {
15+
DISABLE(R.string.disable),
16+
PREEDIT(R.string.preedit),
17+
COMMIT_TEXT_PREVIEW(R.string.commit_text_preview),
18+
RAW_INPUT(R.string.raw_input),
19+
}

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import com.osfans.trime.data.theme.Theme
5252
import com.osfans.trime.data.theme.ThemeManager
5353
import com.osfans.trime.ime.broadcast.IntentReceiver
5454
import com.osfans.trime.ime.enums.FullscreenMode
55-
import com.osfans.trime.ime.enums.InlinePreeditMode
5655
import com.osfans.trime.ime.keyboard.InitializationUi
5756
import com.osfans.trime.ime.keyboard.InputFeedbackManager
5857
import com.osfans.trime.util.ShortcutUtils
@@ -883,14 +882,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
883882
return false
884883
}
885884

885+
private val composingTextMode by prefs.general.composingTextMode
886+
886887
private fun updateComposingText(ctx: RimeProto.Context) {
887888
val ic = currentInputConnection ?: return
888889
val text =
889-
when (prefs.keyboard.inlinePreedit) {
890-
InlinePreeditMode.PREVIEW -> ctx.composition.commitTextPreview ?: ""
891-
InlinePreeditMode.COMPOSITION -> ctx.composition.preedit ?: ""
892-
InlinePreeditMode.INPUT -> ctx.input
893-
InlinePreeditMode.NONE -> ""
890+
when (composingTextMode) {
891+
ComposingTextMode.DISABLE -> ""
892+
ComposingTextMode.PREEDIT -> ctx.composition.preedit ?: ""
893+
ComposingTextMode.COMMIT_TEXT_PREVIEW -> ctx.composition.commitTextPreview ?: ""
894+
ComposingTextMode.RAW_INPUT -> ctx.input
894895
}
895896
if (ic.getSelectedText(0).isNullOrEmpty() || text.isNotEmpty()) {
896897
ic.setComposingText(text, 1)

app/src/main/java/com/osfans/trime/ime/enums/InlinePreeditMode.kt

-13
This file was deleted.

app/src/main/java/com/osfans/trime/ui/fragments/PrefFragment.kt

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class PrefFragment : PaddingPreferenceFragment() {
5757
findNavController().navigate(R.id.action_prefFragment_to_profileFragment)
5858
true
5959
}
60+
get<Preference>("pref_general")?.setOnPreferenceClickListener {
61+
findNavController().navigate(R.id.action_prefFragment_to_generalSettingsFragment)
62+
true
63+
}
6064
get<Preference>("pref_keyboard")?.setOnPreferenceClickListener {
6165
findNavController().navigate(R.id.action_prefFragment_to_keyboardFragment)
6266
true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015 - 2024 Rime community
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package com.osfans.trime.ui.main.settings
7+
8+
import com.osfans.trime.data.prefs.AppPrefs
9+
import com.osfans.trime.data.prefs.PreferenceDelegateFragment
10+
11+
class GeneralSettingsFragment : PreferenceDelegateFragment(AppPrefs.defaultInstance().general)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
~ SPDX-FileCopyrightText: 2015 - 2024 Rime community
3+
~ SPDX-License-Identifier: GPL-3.0-or-later
4+
-->
5+
6+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
7+
android:width="24dp"
8+
android:height="24dp"
9+
android:alpha="0.8"
10+
android:autoMirrored="true"
11+
android:tint="?attr/colorControlNormal"
12+
android:viewportWidth="24"
13+
android:viewportHeight="24">
14+
15+
<path
16+
android:fillColor="@android:color/white"
17+
android:pathData="M3,17v2h6v-2L3,17zM3,5v2h10L13,5L3,5zM13,21v-2h8v-2h-8v-2h-2v6h2zM7,9v2L3,11v2h4v2h2L9,9L7,9zM21,13v-2L11,11v2h10zM15,9h2L17,7h4L21,5h-4L17,3h-2v6z" />
18+
19+
</vector>

app/src/main/res/navigation/pref_nav.xml

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
6363
<action
6464
android:id="@+id/action_prefFragment_to_candidatesSettingsFragment"
6565
app:destination="@id/candidatesSettingsFragment" />
66+
<action
67+
android:id="@+id/action_prefFragment_to_generalSettingsFragment"
68+
app:destination="@id/generalSettingsFragment" />
6669
</fragment>
6770
<fragment
6871
android:id="@+id/profileFragment"
@@ -108,4 +111,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
108111
android:id="@+id/candidatesSettingsFragment"
109112
android:name="com.osfans.trime.ui.main.settings.CandidatesSettingsFragment"
110113
android:label="@string/candidates_window" />
114+
<fragment
115+
android:id="@+id/generalSettingsFragment"
116+
android:name="com.osfans.trime.ui.main.settings.GeneralSettingsFragment"
117+
android:label="@string/general" />
111118
</navigation>

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

+5
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
270270
<string name="preedit_only">仅预编辑码</string>
271271
<string name="candidates_window">候选词窗口</string>
272272
<string name="candidates_mode">候选词显示模式</string>
273+
<string name="general">常规</string>
274+
<string name="preedit">预编辑码</string>
275+
<string name="commit_text_preview">首选词预览</string>
276+
<string name="raw_input">原始输入码</string>
277+
<string name="composing_text_mode">在程序中显示撰写文本</string>
273278
</resources>

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
227227
<string name="simple_key_unpin">取消置頂</string>
228228
<string name="simple_key_pin">置頂</string>
229229
<string name="delete_all">刪除全部</string>
230-
<string name="disable">禁用</string>
230+
<string name="disable">停用</string>
231231
<string name="found_some_problems">但是我們似乎發現了些問題,請檢查:</string>
232232
<string name="pref_clipboard_summary">收藏夾和草稿箱也在這裡管理</string>
233233
<string name="a_regular_expression_per_line">一行一條正則表示式</string>
@@ -271,4 +271,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
271271
<string name="preedit_only">僅預編輯碼</string>
272272
<string name="candidates_window">候选词窗口</string>
273273
<string name="candidates_mode">候選詞顯示模式</string>
274+
<string name="general">常規</string>
275+
<string name="preedit">預編輯碼</string>
276+
<string name="commit_text_preview">首選詞預覽</string>
277+
<string name="raw_input">原始輸入碼</string>
278+
<string name="composing_text_mode">在程式中顯示撰寫文字</string>
274279
</resources>

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

+5
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
271271
<string name="preedit_only">Preedit only</string>
272272
<string name="candidates_window">Candidates Window</string>
273273
<string name="candidates_mode">Candidates mode</string>
274+
<string name="general">General</string>
275+
<string name="preedit">Preedit</string>
276+
<string name="commit_text_preview">Commit text preview</string>
277+
<string name="raw_input">Raw input</string>
278+
<string name="composing_text_mode">Show composing text in editor</string>
274279
</resources>

app/src/main/res/xml/keyboard_preference.xml

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
1414
<PreferenceCategory
1515
app:iconSpaceReserved="false"
1616
app:title="@string/pref_keyboard__function">
17-
<ListPreference
18-
android:defaultValue="preview"
19-
android:entries="@array/keyboard__inline_entries"
20-
android:entryValues="@array/keyboard__inline_values"
21-
android:key="keyboard__inline_preedit"
22-
android:title="@string/keyboard__inline_preedit_title"
23-
app:iconSpaceReserved="false"
24-
app:useSimpleSummaryProvider="true" />
2517
<ListPreference
2618
android:defaultValue="auto_show"
2719
android:entries="@array/keyboard__fullscreen_mode_entries"

app/src/main/res/xml/prefs.xml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
2020
app:icon="@drawable/ic_baseline_snippet_folder_24"
2121
android:summary="@string/pref_profile_summary"/>
2222

23+
<Preference android:key="pref_general"
24+
android:title="@string/general"
25+
app:icon="@drawable/ic_baseline_tune_24" />
26+
2327
<Preference android:key="pref_keyboard"
2428
android:title="@string/pref_keyboard"
2529
app:icon="@drawable/ic_baseline_keyboard_24" />

0 commit comments

Comments
 (0)