Skip to content
Open
Show file tree
Hide file tree
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 @@ -160,6 +160,7 @@ class SuggestionHandler(
ime.updateEmojiSuggestion(true, emojis)
ime.updateButtonVisibility(true)
} else {
ime.autoSuggestEmojis = null
ime.updateButtonVisibility(false)
}
}
Expand Down
10 changes: 0 additions & 10 deletions app/src/keyboards/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler

/**
* The EnglishKeyboardIME class provides the input method for the English language keyboard.
Expand All @@ -32,13 +31,4 @@ class EnglishKeyboardIME : GeneralKeyboardIME("English") {
override var inputTypeClass: Int = InputType.TYPE_CLASS_TEXT
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

/**
* Handles key input from the keyboard and delegates it to [KeyHandler].
*/
override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
10 changes: 0 additions & 10 deletions app/src/keyboards/java/be/scri/services/FrenchKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler

/**
* The FrenchKeyboardIME class provides the input method for the French language keyboard.
Expand Down Expand Up @@ -38,13 +37,4 @@ class FrenchKeyboardIME : GeneralKeyboardIME("French") {
// so we must remove the overrides here. They are now inherited directly.
// override lateinit var binding: KeyboardViewCommandOptionsBinding // REMOVED
// override var keyboardView: KeyboardView? = null // REMOVED

private val keyHandler by lazy { KeyHandler(this) }

/**
* Handles key press events on the keyboard.
*/
override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
57 changes: 8 additions & 49 deletions app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import be.scri.helpers.AutocompletionHandler
import be.scri.helpers.BackspaceHandler
import be.scri.helpers.DatabaseManagers
import be.scri.helpers.EmojiUtils.insertEmoji
import be.scri.helpers.KeyHandler
import be.scri.helpers.KeyboardBase
import be.scri.helpers.KeyboardLanguageMappingConstants
import be.scri.helpers.LanguageMappingConstants.getLanguageAlias
Expand Down Expand Up @@ -143,6 +144,7 @@ abstract class GeneralKeyboardIME(
internal lateinit var suggestionHandler: SuggestionHandler
internal lateinit var autocompletionHandler: AutocompletionHandler
private lateinit var autocompletionManager: AutocompletionDataManager
internal lateinit var keyHandler: KeyHandler
private var dataContract: DataContract? = null

var emojiKeywords: HashMap<String, MutableList<String>>? = null
Expand Down Expand Up @@ -226,6 +228,7 @@ abstract class GeneralKeyboardIME(
suggestionHandler = SuggestionHandler(this)
autocompletionManager = dbManagers.autocompletionManager
autocompletionHandler = AutocompletionHandler(this)
keyHandler = KeyHandler(this)
clipboardMonitor =
ClipboardMonitor(this) { text ->
latestClipText = text
Expand Down Expand Up @@ -566,55 +569,7 @@ abstract class GeneralKeyboardIME(
* Handles key input from the keyboard. Delegates to specific handlers based on the key code.
*/
override fun onKey(code: Int) {
when (code) {
KeyboardBase.KEYCODE_EMOJI -> {
openEmojiKeyboard()
return
}
KeyboardBase.KEYCODE_FLOAT_TOGGLE -> {
toggleFloatingMode()
return
}
KeyboardBase.KEYCODE_CLIPBOARD -> {
openClipboardPanel()
return
}
}
val inputConnection = currentInputConnection
if (inputConnection != null) {
when (code) {
KeyboardBase.KEYCODE_DELETE -> handleDelete()
KeyboardBase.KEYCODE_SHIFT -> {
if (keyboardMode == keyboardLetters) {
val shiftState = keyboardView?.mKeyboard?.mShiftState ?: SHIFT_OFF
when {
shiftState == SHIFT_ON_PERMANENT -> keyboardView?.setShifted(SHIFT_OFF)
System.currentTimeMillis() - lastShiftPressTS < shiftPermToggleSpeed -> keyboardView?.setShifted(SHIFT_ON_PERMANENT)
shiftState == SHIFT_ON_ONE_CHAR -> keyboardView?.setShifted(SHIFT_OFF)
shiftState == SHIFT_OFF -> keyboardView?.setShifted(SHIFT_ON_ONE_CHAR)
}
lastShiftPressTS = System.currentTimeMillis()
} else {
handleModeChange(keyboardMode, keyboardView, this)
}
}

KeyboardBase.KEYCODE_ENTER -> handleKeycodeEnter()
KeyboardBase.KEYCODE_MODE_CHANGE -> handleModeChange(keyboardMode, keyboardView, this)
KeyboardBase.KEYCODE_CLIPBOARD -> openClipboardPanel()
else -> {
if (KeyboardBase.SCRIBE_VIEW_KEYS.contains(code)) {
val keyLabel = keyboardView?.getKeyLabel(code)
if (!keyLabel.isNullOrEmpty()) {
commitText("$keyLabel ")
}
} else {
val commandBarState = currentState != ScribeState.IDLE && currentState != ScribeState.SELECT_COMMAND
handleElseCondition(code, keyboardMode, commandBarState)
}
}
}
}
keyHandler.handleKey(code, language)
}

// MARK: Helper Methods
Expand Down Expand Up @@ -1935,6 +1890,10 @@ abstract class GeneralKeyboardIME(
}
if (completions.isNullOrEmpty()) {
uiManager.disableAutoSuggest(language)
if (!autoSuggestEmojis.isNullOrEmpty() && emojiAutoSuggestionEnabled) {
updateEmojiSuggestion(true, autoSuggestEmojis)
updateButtonVisibility(true)
}
return
}

Expand Down
7 changes: 0 additions & 7 deletions app/src/keyboards/java/be/scri/services/GermanKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler
import be.scri.helpers.PreferencesHelper.getIsAccentCharacterDisabled

/**
Expand Down Expand Up @@ -52,10 +51,4 @@ class GermanKeyboardIME : GeneralKeyboardIME("German") {
// so we must remove the overrides here. They are now inherited directly.
// override lateinit var binding: KeyboardViewCommandOptionsBinding // REMOVED
// override var keyboardView: KeyboardView? = null // REMOVED

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
7 changes: 0 additions & 7 deletions app/src/keyboards/java/be/scri/services/ItalianKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler

/**
* The ItalianKeyboardIME class provides the input method for the Italian language keyboard.
Expand All @@ -32,10 +31,4 @@ class ItalianKeyboardIME : GeneralKeyboardIME("Italian") {
override var inputTypeClass: Int = InputType.TYPE_CLASS_TEXT
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler

/**
* The PortugueseKeyboardIME class provides the input method for the Portuguese language keyboard.
Expand Down Expand Up @@ -33,10 +32,4 @@ class PortugueseKeyboardIME : GeneralKeyboardIME("Portuguese") {
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false
override var hasTextBeforeCursor: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
7 changes: 0 additions & 7 deletions app/src/keyboards/java/be/scri/services/RussianKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler

/**
* The RussianKeyboardIME class provides the input method for the Russian language keyboard.
Expand All @@ -32,10 +31,4 @@ class RussianKeyboardIME : GeneralKeyboardIME("Russian") {
override var inputTypeClass: Int = InputType.TYPE_CLASS_TEXT
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
7 changes: 0 additions & 7 deletions app/src/keyboards/java/be/scri/services/SpanishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler
import be.scri.helpers.PreferencesHelper.getIsAccentCharacterDisabled

/**
Expand Down Expand Up @@ -43,10 +42,4 @@ class SpanishKeyboardIME : GeneralKeyboardIME("Spanish") {
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false
override var hasTextBeforeCursor: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
7 changes: 0 additions & 7 deletions app/src/keyboards/java/be/scri/services/SwedishKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package be.scri.services
import android.text.InputType
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.helpers.KeyHandler
import be.scri.helpers.PreferencesHelper.getIsAccentCharacterDisabled

/**
Expand Down Expand Up @@ -42,10 +41,4 @@ class SwedishKeyboardIME : GeneralKeyboardIME("Swedish") {
override var inputTypeClass: Int = InputType.TYPE_CLASS_TEXT
override var enterKeyType: Int = IME_ACTION_NONE
override var switchToLetters: Boolean = false

private val keyHandler by lazy { KeyHandler(this) }

override fun onKey(code: Int) {
keyHandler.handleKey(code, language)
}
}
17 changes: 13 additions & 4 deletions app/src/main/java/be/scri/helpers/data/EmojiDataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ class EmojiDataManager(
val db = fileManager.getLanguageDatabase(language) ?: return emojiMap

db.use {
if (!it.tableExists("emoji_keywords")) return emojiMap
// The server contract names the table "emojikeywords", but older local
// databases may use the snake_case form, so accept both.
val tableName =
when {
it.tableExists("emoji_keywords") -> "emoji_keywords"
it.tableExists("emojikeywords") -> "emojikeywords"
else -> return emojiMap
Comment thread
Roniscend marked this conversation as resolved.
}

it.rawQuery("SELECT MAX(LENGTH(word)) FROM emoji_keywords", null).use { cursor ->
it.rawQuery("SELECT MAX(LENGTH(word)) FROM $tableName", null).use { cursor ->
if (cursor.moveToFirst()) {
maxKeywordLength = cursor.getInt(0)
}
}
it.rawQuery("SELECT * FROM emoji_keywords", null).use { cursor ->

it.rawQuery("SELECT * FROM $tableName", null).use { cursor ->
processEmojiCursor(cursor, emojiMap)
}
}
Expand All @@ -61,7 +69,8 @@ class EmojiDataManager(
.mapNotNull { name -> cursor.getColumnIndex(name).takeIf { it != -1 } }

do {
val word = cursor.getString(wordIndex)
// Keys are lowercased so lookups via the user's (lowercased) input match.
val word = cursor.getString(wordIndex)?.lowercase() ?: continue
val emojis =
emojiIndices
.mapNotNull { index -> cursor.getString(index)?.takeIf { it.isNotBlank() } }
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/be/scri/helpers/data/SQLiteExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.database.sqlite.SQLiteDatabase

fun SQLiteDatabase.tableExists(tableName: String): Boolean =
rawQuery(
"SELECT name FROM sqlite_master WHERE type='table' AND name='$tableName'",
null,
"SELECT name FROM sqlite_master WHERE type='table' AND LOWER(name) = LOWER(?)",
arrayOf(tableName),
).use { it.moveToFirst() }

fun SQLiteDatabase.columnExists(
Expand Down
Loading