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

feat: load Popup from json config config/PopupPreset.json #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
Loading
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import splitties.views.dsl.core.add
import splitties.views.dsl.core.frameLayout
import splitties.views.dsl.core.lParams
import java.util.LinkedList
import kotlinx.serialization.json.Json
import org.fcitx.fcitx5.android.utils.appContext
import java.io.File

class PopupComponent :
UniqueComponent<PopupComponent>(), Dependent, ManagedHandler by managedHandler() {
Expand Down Expand Up @@ -62,6 +65,32 @@ class PopupComponent :
private val rootLocation = intArrayOf(0, 0)
private val rootBounds: Rect = Rect()

companion object {
private var lastModified = 0L
private var cachedPopupPreset: Map<String, Array<String>>? = null
val popupPresetJson: Map<String, Array<String>>?
@Synchronized
get() {
var file = File(appContext.getExternalFilesDir(null), "config/PopupPreset.json")
if (!file.exists()) {
cachedPopupPreset = null
return null
}
if (cachedPopupPreset == null || file.lastModified() != lastModified) {
try {
lastModified = file.lastModified()
val json = file.readText()
cachedPopupPreset = Json.decodeFromString<Map<String, List<String>>>(json)
.mapValues { it.value.toTypedArray() }
} catch (e: Exception) {
e.printStackTrace()
cachedPopupPreset = null
}
}
return cachedPopupPreset
}
}

val root by lazy {
context.frameLayout {
// we want (0, 0) at top left
Expand Down Expand Up @@ -107,7 +136,7 @@ class PopupComponent :
}

private fun showKeyboard(viewId: Int, keyboard: KeyDef.Popup.Keyboard, bounds: Rect) {
val keys = PopupPreset[keyboard.label] ?: return
val keys = Companion.popupPresetJson?.get(keyboard.label) ?: PopupPreset[keyboard.label] ?: return
// clear popup preview text OR create empty popup preview
showingEntryUi[viewId]?.setText("") ?: showPopup(viewId, "", bounds)
reallyShowKeyboard(viewId, keys, bounds)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.