Skip to content

Commit

Permalink
fix: display SYMBOL type using var-length style
Browse files Browse the repository at this point in the history
As `SINGLE` type is used to display one-character-length content, `SYMBOL` type is var-length.
So it should use var-length style to display.
  • Loading branch information
goofyz committed Jan 16, 2024
1 parent e6d71aa commit b983342
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Expand Up @@ -87,15 +87,15 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
TabManager.get().select(i)
initCandidates()
}
SymbolKeyboardType.VAR_LENGTH -> {
initVarLengthKeys(TabManager.get().select(i))
SymbolKeyboardType.VAR_LENGTH, SymbolKeyboardType.SYMBOL -> {
initVarLengthKeys(i, TabManager.get().select(i))
}
SymbolKeyboardType.TABS -> {
TabManager.get().select(i)
initVarLengthKeys(TabManager.get().tabSwitchData)
initVarLengthKeys(i, TabManager.get().tabSwitchData)
Timber.v("All tags in TABS: TabManager.get().tabSwitchData = ${TabManager.get().tabSwitchData}")
}
SymbolKeyboardType.SYMBOL, SymbolKeyboardType.HISTORY -> {
SymbolKeyboardType.HISTORY -> {
TabManager.get().select(i)
initFixData(i)
}
Expand Down Expand Up @@ -303,10 +303,22 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
keyboardView.scrollToPosition(0)
}

private fun initVarLengthKeys(data: List<SimpleKeyBean>) {
private fun initVarLengthKeys(
i: Int,
data: List<SimpleKeyBean>,
) {
val tabTag = TabManager.getTag(i)

val candidateAdapter =
CandidateAdapter(theme).apply {
setListener { position ->
if (position < data.size) {
val bean = data[position]
if (tabTag.type === SymbolKeyboardType.SYMBOL) {
service.inputSymbol(bean.text)
return@setListener
}
}
service.currentInputConnection?.commitText(data[position].text, 1)
}
}
Expand All @@ -316,8 +328,15 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
adapter = candidateAdapter
keyboardView.isSelected = true
}

val candidates =
if (tabTag.type === SymbolKeyboardType.SYMBOL) {
data.map { b -> CandidateListItem("", b.label) }
} else {
data.map { b -> CandidateListItem("", b.text) }
}
candidateAdapter.updateCandidates(
data.map { b -> CandidateListItem("", b.text) },
candidates,
)
}

Expand Down

0 comments on commit b983342

Please sign in to comment.