Skip to content

Commit

Permalink
refactor: rename InlinePreeditMode to ComposingTextMode and set DISAB…
Browse files Browse the repository at this point in the history
…LED as default value
  • Loading branch information
WhiredPlanck committed Nov 21, 2024
1 parent b449368 commit 31aa00b
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 31 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/com/osfans/trime/data/prefs/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import androidx.preference.PreferenceManager
import com.osfans.trime.R
import com.osfans.trime.data.base.DataManager
import com.osfans.trime.ime.candidates.popup.PopupCandidatesMode
import com.osfans.trime.ime.core.ComposingTextMode
import com.osfans.trime.ime.enums.FullscreenMode
import com.osfans.trime.ime.enums.InlinePreeditMode
import com.osfans.trime.util.appContext
import java.lang.ref.WeakReference

Expand All @@ -37,6 +37,7 @@ class AppPrefs(
}

val internal = Internal(shared)
val general = General(shared).register()
val keyboard = Keyboard(shared)
val theme = Theme(shared)
val profile = Profile(shared)
Expand Down Expand Up @@ -91,14 +92,23 @@ class AppPrefs(
var pid by int(PID, 0)
}

class General(
shared: SharedPreferences,
) : PreferenceDelegateOwner(shared, R.string.general) {
companion object {
const val COMPOSING_TEXT_MODE = "composing_text_mode"
}

val composingTextMode = enum(R.string.composing_text_mode, COMPOSING_TEXT_MODE, ComposingTextMode.DISABLE)
}

/**
* Wrapper class of keyboard settings.
*/
class Keyboard(
shared: SharedPreferences,
) : PreferenceDelegateOwner(shared) {
companion object {
const val INLINE_PREEDIT_MODE = "keyboard__inline_preedit"
const val SOFT_CURSOR_ENABLED = "keyboard__soft_cursor"
const val POPUP_KEY_PRESS_ENABLED = "keyboard__show_key_popup"
const val SWITCHES_ENABLED = "keyboard__show_switches"
Expand Down Expand Up @@ -134,7 +144,6 @@ class AppPrefs(
const val REPEAT_INTERVAL = "keyboard__key_repeat_interval"
}

var inlinePreedit by enum(INLINE_PREEDIT_MODE, InlinePreeditMode.PREVIEW)
var fullscreenMode by enum(FULLSCREEN_MODE, FullscreenMode.AUTO_SHOW)
val softCursorEnabled by bool(SOFT_CURSOR_ENABLED, true)
val popupKeyPressEnabled by bool(POPUP_KEY_PRESS_ENABLED, false)
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/osfans/trime/ime/core/ComposingTextMode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2015 - 2024 Rime community
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package com.osfans.trime.ime.core

import androidx.annotation.StringRes
import com.osfans.trime.R
import com.osfans.trime.data.prefs.PreferenceDelegateEnum

enum class ComposingTextMode(
@StringRes override val stringRes: Int,
) : PreferenceDelegateEnum {
DISABLE(R.string.disable),
PREEDIT(R.string.preedit),
COMMIT_TEXT_PREVIEW(R.string.commit_text_preview),
RAW_INPUT(R.string.raw_input),
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import com.osfans.trime.data.theme.Theme
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.broadcast.IntentReceiver
import com.osfans.trime.ime.enums.FullscreenMode
import com.osfans.trime.ime.enums.InlinePreeditMode
import com.osfans.trime.ime.keyboard.InitializationUi
import com.osfans.trime.ime.keyboard.InputFeedbackManager
import com.osfans.trime.util.ShortcutUtils
Expand Down Expand Up @@ -883,14 +882,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
return false
}

private val composingTextMode by prefs.general.composingTextMode

private fun updateComposingText(ctx: RimeProto.Context) {
val ic = currentInputConnection ?: return
val text =
when (prefs.keyboard.inlinePreedit) {
InlinePreeditMode.PREVIEW -> ctx.composition.commitTextPreview ?: ""
InlinePreeditMode.COMPOSITION -> ctx.composition.preedit ?: ""
InlinePreeditMode.INPUT -> ctx.input
InlinePreeditMode.NONE -> ""
when (composingTextMode) {
ComposingTextMode.DISABLE -> ""
ComposingTextMode.PREEDIT -> ctx.composition.preedit ?: ""
ComposingTextMode.COMMIT_TEXT_PREVIEW -> ctx.composition.commitTextPreview ?: ""
ComposingTextMode.RAW_INPUT -> ctx.input
}
if (ic.getSelectedText(0).isNullOrEmpty() || text.isNotEmpty()) {
ic.setComposingText(text, 1)
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/osfans/trime/ime/enums/InlinePreeditMode.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class PrefFragment : PaddingPreferenceFragment() {
findNavController().navigate(R.id.action_prefFragment_to_profileFragment)
true
}
get<Preference>("pref_general")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_generalSettingsFragment)
true
}
get<Preference>("pref_keyboard")?.setOnPreferenceClickListener {
findNavController().navigate(R.id.action_prefFragment_to_keyboardFragment)
true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2015 - 2024 Rime community
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package com.osfans.trime.ui.main.settings

import com.osfans.trime.data.prefs.AppPrefs
import com.osfans.trime.data.prefs.PreferenceDelegateFragment

class GeneralSettingsFragment : PreferenceDelegateFragment(AppPrefs.defaultInstance().general)
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/ic_baseline_tune_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
~ SPDX-FileCopyrightText: 2015 - 2024 Rime community
~ SPDX-License-Identifier: GPL-3.0-or-later
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:alpha="0.8"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
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" />

</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/navigation/pref_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<action
android:id="@+id/action_prefFragment_to_candidatesSettingsFragment"
app:destination="@id/candidatesSettingsFragment" />
<action
android:id="@+id/action_prefFragment_to_generalSettingsFragment"
app:destination="@id/generalSettingsFragment" />
</fragment>
<fragment
android:id="@+id/profileFragment"
Expand Down Expand Up @@ -108,4 +111,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
android:id="@+id/candidatesSettingsFragment"
android:name="com.osfans.trime.ui.main.settings.CandidatesSettingsFragment"
android:label="@string/candidates_window" />
<fragment
android:id="@+id/generalSettingsFragment"
android:name="com.osfans.trime.ui.main.settings.GeneralSettingsFragment"
android:label="@string/general" />
</navigation>
5 changes: 5 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="preedit_only">仅预编辑码</string>
<string name="candidates_window">候选词窗口</string>
<string name="candidates_mode">候选词显示模式</string>
<string name="general">常规</string>
<string name="preedit">预编辑码</string>
<string name="commit_text_preview">首选词预览</string>
<string name="raw_input">原始输入码</string>
<string name="composing_text_mode">在程序中显示撰写文本</string>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="simple_key_unpin">取消置頂</string>
<string name="simple_key_pin">置頂</string>
<string name="delete_all">刪除全部</string>
<string name="disable">禁用</string>
<string name="disable">停用</string>
<string name="found_some_problems">但是我們似乎發現了些問題,請檢查:</string>
<string name="pref_clipboard_summary">收藏夾和草稿箱也在這裡管理</string>
<string name="a_regular_expression_per_line">一行一條正則表示式</string>
Expand Down Expand Up @@ -271,4 +271,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="preedit_only">僅預編輯碼</string>
<string name="candidates_window">候选词窗口</string>
<string name="candidates_mode">候選詞顯示模式</string>
<string name="general">常規</string>
<string name="preedit">預編輯碼</string>
<string name="commit_text_preview">首選詞預覽</string>
<string name="raw_input">原始輸入碼</string>
<string name="composing_text_mode">在程式中顯示撰寫文字</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="preedit_only">Preedit only</string>
<string name="candidates_window">Candidates Window</string>
<string name="candidates_mode">Candidates mode</string>
<string name="general">General</string>
<string name="preedit">Preedit</string>
<string name="commit_text_preview">Commit text preview</string>
<string name="raw_input">Raw input</string>
<string name="composing_text_mode">Show composing text in editor</string>
</resources>
8 changes: 0 additions & 8 deletions app/src/main/res/xml/keyboard_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<PreferenceCategory
app:iconSpaceReserved="false"
app:title="@string/pref_keyboard__function">
<ListPreference
android:defaultValue="preview"
android:entries="@array/keyboard__inline_entries"
android:entryValues="@array/keyboard__inline_values"
android:key="keyboard__inline_preedit"
android:title="@string/keyboard__inline_preedit_title"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="auto_show"
android:entries="@array/keyboard__fullscreen_mode_entries"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:icon="@drawable/ic_baseline_snippet_folder_24"
android:summary="@string/pref_profile_summary"/>

<Preference android:key="pref_general"
android:title="@string/general"
app:icon="@drawable/ic_baseline_tune_24" />

<Preference android:key="pref_keyboard"
android:title="@string/pref_keyboard"
app:icon="@drawable/ic_baseline_keyboard_24" />
Expand Down

0 comments on commit 31aa00b

Please sign in to comment.