Skip to content

Commit 95f040c

Browse files
committed
refactor: extract space bar and emoji/language long press handlers
1 parent 441ed9c commit 95f040c

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

app/src/main/kotlin/org/fossify/keyboard/services/SimpleKeyboardIME.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
619619
}
620620
}
621621

622-
if (keyboardMode != KEYBOARD_LETTERS) return@let
622+
if (keyboardMode != KEYBOARD_LETTERS) return keyboard
623623
val emojiKeyIndex = keys.indexOfFirst { it.code == MyKeyboard.KEYCODE_EMOJI_OR_LANGUAGE }
624624
if (emojiKeyIndex != -1 && spaceKeyIndex != -1) {
625625
val emojiKey = keys[emojiKeyIndex]

app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,26 +1186,9 @@ class MyKeyboardView @JvmOverloads constructor(
11861186
*/
11871187
private fun onLongPress(popupKey: MyKeyboard.Key, me: MotionEvent): Boolean {
11881188
if (popupKey.code == KEYCODE_SPACE) {
1189-
return if (!mCursorControlActive) {
1190-
setCurrentKeyPressed(false)
1191-
mRepeatKeyIndex = NOT_A_KEY
1192-
mHandler?.removeMessages(MSG_REPEAT)
1193-
vibrateIfNeeded()
1194-
SwitchLanguageDialog(this) {
1195-
mOnKeyboardActionListener?.reloadKeyboard()
1196-
}
1197-
true
1198-
} else false
1189+
return onSpaceBarLongPressed()
11991190
} else if (popupKey.code == KEYCODE_EMOJI_OR_LANGUAGE) {
1200-
setCurrentKeyPressed(false)
1201-
if (context.config.showEmojiKey) {
1202-
openEmojiPalette()
1203-
} else {
1204-
SwitchLanguageDialog(this) {
1205-
mOnKeyboardActionListener?.reloadKeyboard()
1206-
}
1207-
}
1208-
return true
1191+
return onEmojiOrLanguageLongPressed()
12091192
} else {
12101193
val popupKeyboardId = popupKey.popupResId
12111194
if (popupKeyboardId != 0) {
@@ -1617,6 +1600,32 @@ class MyKeyboardView @JvmOverloads constructor(
16171600
setupStoredClips()
16181601
}
16191602

1603+
private fun onSpaceBarLongPressed(): Boolean {
1604+
return if (!mCursorControlActive) {
1605+
setCurrentKeyPressed(false)
1606+
mRepeatKeyIndex = NOT_A_KEY
1607+
mHandler?.removeMessages(MSG_REPEAT)
1608+
vibrateIfNeeded()
1609+
SwitchLanguageDialog(this) {
1610+
mOnKeyboardActionListener?.reloadKeyboard()
1611+
}
1612+
true
1613+
} else false
1614+
}
1615+
1616+
private fun onEmojiOrLanguageLongPressed(): Boolean {
1617+
setCurrentKeyPressed(false)
1618+
if (context.config.showEmojiKey) {
1619+
openEmojiPalette()
1620+
} else {
1621+
SwitchLanguageDialog(this) {
1622+
mOnKeyboardActionListener?.reloadKeyboard()
1623+
}
1624+
}
1625+
1626+
return true
1627+
}
1628+
16201629
private fun setupStoredClips() {
16211630
ensureBackgroundThread {
16221631
val clips = ArrayList<ListItem>()

0 commit comments

Comments
 (0)