@@ -27,6 +27,9 @@ import splitties.views.dsl.core.add
27
27
import splitties.views.dsl.core.frameLayout
28
28
import splitties.views.dsl.core.lParams
29
29
import java.util.LinkedList
30
+ import kotlinx.serialization.json.Json
31
+ import org.fcitx.fcitx5.android.utils.appContext
32
+ import java.io.File
30
33
31
34
class PopupComponent :
32
35
UniqueComponent <PopupComponent >(), Dependent , ManagedHandler by managedHandler() {
@@ -62,6 +65,32 @@ class PopupComponent :
62
65
private val rootLocation = intArrayOf(0 , 0 )
63
66
private val rootBounds: Rect = Rect ()
64
67
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
+
65
94
val root by lazy {
66
95
context.frameLayout {
67
96
// we want (0, 0) at top left
@@ -107,7 +136,7 @@ class PopupComponent :
107
136
}
108
137
109
138
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
111
140
// clear popup preview text OR create empty popup preview
112
141
showingEntryUi[viewId]?.setText(" " ) ? : showPopup(viewId, " " , bounds)
113
142
reallyShowKeyboard(viewId, keys, bounds)
0 commit comments