Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e23aeb

Browse filesBrowse files
committed
feat: load Popup from json config config/PopupPreset.json
1 parent df4e134 commit 6e23aeb
Copy full SHA for 6e23aeb

File tree

1 file changed

+30
-1
lines changed
Filter options

1 file changed

+30
-1
lines changed

‎app/src/main/java/org/fcitx/fcitx5/android/input/popup/PopupComponent.kt

Copy file name to clipboardExpand all lines: app/src/main/java/org/fcitx/fcitx5/android/input/popup/PopupComponent.kt
+30-1Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import splitties.views.dsl.core.add
2727
import splitties.views.dsl.core.frameLayout
2828
import splitties.views.dsl.core.lParams
2929
import java.util.LinkedList
30+
import kotlinx.serialization.json.Json
31+
import org.fcitx.fcitx5.android.utils.appContext
32+
import java.io.File
3033

3134
class PopupComponent :
3235
UniqueComponent<PopupComponent>(), Dependent, ManagedHandler by managedHandler() {
@@ -62,6 +65,32 @@ class PopupComponent :
6265
private val rootLocation = intArrayOf(0, 0)
6366
private val rootBounds: Rect = Rect()
6467

68+
companion object {
69+
private var lastModified = 0L
70+
private var cachedPopupPreset: Map<String, Array<String>>? = null
71+
val popupPresetJson: Map<String, Array<String>>?
72+
@Synchronized
73+
get() {
74+
var file = File(appContext.getExternalFilesDir(null), "config/PopupPreset.json")
75+
if (!file.exists()) {
76+
cachedPopupPreset = null
77+
return null
78+
}
79+
if (cachedPopupPreset == null || file.lastModified() != lastModified) {
80+
try {
81+
lastModified = file.lastModified()
82+
val json = file.readText()
83+
cachedPopupPreset = Json.decodeFromString<Map<String, List<String>>>(json)
84+
.mapValues { it.value.toTypedArray() }
85+
} catch (e: Exception) {
86+
e.printStackTrace()
87+
cachedPopupPreset = null
88+
}
89+
}
90+
return cachedPopupPreset
91+
}
92+
}
93+
6594
val root by lazy {
6695
context.frameLayout {
6796
// we want (0, 0) at top left
@@ -107,7 +136,7 @@ class PopupComponent :
107136
}
108137

109138
private fun showKeyboard(viewId: Int, keyboard: KeyDef.Popup.Keyboard, bounds: Rect) {
110-
val keys = PopupPreset[keyboard.label] ?: return
139+
val keys = Companion.popupPresetJson?.get(keyboard.label) ?: PopupPreset[keyboard.label] ?: return
111140
// clear popup preview text OR create empty popup preview
112141
showingEntryUi[viewId]?.setText("") ?: showPopup(viewId, "", bounds)
113142
reallyShowKeyboard(viewId, keys, bounds)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.