Skip to content

Commit

Permalink
refactor: make the code of LiquidKeyboard more clean
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Apr 26, 2024
1 parent 7de93f5 commit de3a186
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ class LiquidKeyboard(
SimpleAdapter(theme, columnCount).apply {
setHasStableIds(true)
setListener { position ->
if (position < beans.size) {
if (position in beans.indices) {
val bean = beans[position]
if (currentBoardType === SymbolKeyboardType.SYMBOL) {
service.inputSymbol(bean.text)
return@setListener
} else {
service.commitText(bean.text)
if (currentBoardType !== SymbolKeyboardType.HISTORY) {
symbolHistory.insert(bean.text)
symbolHistory.save()
when (currentBoardType) {
SymbolKeyboardType.SYMBOL -> service.inputSymbol(bean.text)
else -> {
service.commitText(bean.text)
if (currentBoardType != SymbolKeyboardType.HISTORY) {
symbolHistory.insert(bean.text)
symbolHistory.save()
}
}
return@setListener
}
}
}
Expand Down Expand Up @@ -91,18 +90,17 @@ class LiquidKeyboard(
CandidateAdapter(theme).apply {
setListener { position ->
val data = TabManager.selectTabByIndex(TabManager.currentTabIndex)
if (position < data.size) {
if (position in data.indices) {
val bean = data[position]
if (currentBoardType === SymbolKeyboardType.SYMBOL) {
service.inputSymbol(bean.text)
return@setListener
} else if (currentBoardType === SymbolKeyboardType.TABS) {
val realPosition = TabManager.tabTags.indexOfFirst { it.text == bean.text }
select(realPosition)
return@setListener
when (currentBoardType) {
SymbolKeyboardType.SYMBOL -> service.inputSymbol(bean.text)
SymbolKeyboardType.TABS -> {
val realPosition = TabManager.tabTags.indexOfFirst { it.text == bean.text }
select(realPosition)
}
else -> service.currentInputConnection?.commitText(bean.text, 1)
}
}
service.currentInputConnection?.commitText(data[position].text, 1)
}
}
}
Expand Down

0 comments on commit de3a186

Please sign in to comment.