Skip to content

Commit

Permalink
Fix rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Linfye committed Oct 24, 2024
1 parent 7e48e2e commit 468ad0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
16 changes: 3 additions & 13 deletions app/src/main/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package be.scri.services

import android.text.InputType
import android.util.Log
import android.view.View
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.DatabaseHelper
import be.scri.helpers.MyKeyboard
import be.scri.helpers.MyKeyboard.Companion.KEYCODE_ENTER
import be.scri.views.MyKeyboardView
Expand All @@ -29,11 +28,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME("English") {
override var hasTextBeforeCursor = false
override lateinit var binding: KeyboardViewCommandOptionsBinding

private lateinit var dbHelper: DatabaseHelper
private lateinit var emojiKeywords: HashMap<String, MutableList<String>>
private var lastWord: String? = null
private var autosuggestEmojis: MutableList<String>? = null

override fun onCreateInputView(): View {
binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater)
setupCommandBarTheme(binding)
Expand All @@ -49,9 +43,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME("English") {
initializeEmojiButtons()
updateUI()
return keyboardHolder
dbHelper = DatabaseHelper(this)
dbHelper.loadDatabase("EN")
emojiKeywords = dbHelper.getEmojiKeywords("EN")
}

override fun onKey(code: Int) {
Expand Down Expand Up @@ -100,10 +91,9 @@ class EnglishKeyboardIME : SimpleKeyboardIME("English") {
}

lastWord = getLastWordBeforeCursor()
Log.d("Debug", "Last word before cursor: $lastWord")

Log.d("Debug", "$lastWord")
autosuggestEmojis = findEmojisForLastWord(emojiKeywords, lastWord)

Log.d("Debug", "$autosuggestEmojis")
updateButtonText(isAutoSuggestEnabled, autosuggestEmojis)

if (code != MyKeyboard.KEYCODE_SHIFT) {
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/be/scri/services/SimpleKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.widget.Button
import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.DatabaseHelper
import be.scri.helpers.MyKeyboard
import be.scri.helpers.SHIFT_OFF
import be.scri.helpers.SHIFT_ON_ONE_CHAR
Expand Down Expand Up @@ -60,11 +61,15 @@ abstract class SimpleKeyboardIME(
private var emojiBtnTablet2: Button? = null
private var emojiSpaceTablet2: View? = null
private var emojiBtnTablet3: Button? = null
private lateinit var dbHelper: DatabaseHelper
lateinit var emojiKeywords: HashMap<String, MutableList<String>>
var isAutoSuggestEnabled: Boolean = false
var lastWord: String? = null
var autosuggestEmojis: MutableList<String>? = null
// abstract var keyboardViewKeyboardBinding : KeyboardViewKeyboardBinding

protected var currentState: ScribeState = ScribeState.IDLE
protected lateinit var keyboardBinding: KeyboardViewKeyboardBinding
private var isAutoSuggestEnabled: Boolean = false

enum class ScribeState {
IDLE,
Expand Down Expand Up @@ -137,6 +142,7 @@ abstract class SimpleKeyboardIME(
setupIdleView()
initializeEmojiButtons()
updateButtonVisibility(isAutoSuggestEnabled)
updateButtonText(isAutoSuggestEnabled, autosuggestEmojis)
}

ScribeState.SELECT_COMMAND -> setupSelectCommandView()
Expand Down Expand Up @@ -399,10 +405,28 @@ abstract class SimpleKeyboardIME(
}
}

val languageAlias = getLanguageAlias(language)
dbHelper = DatabaseHelper(this)
dbHelper.loadDatabase(languageAlias)
emojiKeywords = dbHelper.getEmojiKeywords(languageAlias)

keyboard = MyKeyboard(this, keyboardXml, enterKeyType)
keyboardView?.setKeyboard(keyboard!!)
}

private fun getLanguageAlias(language: String): String =
when (language) {
"English" -> "EN"
"French" -> "FR"
"German" -> "DE"
"Italian" -> "IT"
"Portuguese" -> "PT"
"Russian" -> "RU"
"Spanish" -> "ES"
"Swedish" -> "SV"
else -> ""
}

fun updateShiftKeyState() {
if (keyboardMode == keyboardLetters) {
val editorInfo = currentInputEditorInfo
Expand Down

0 comments on commit 468ad0b

Please sign in to comment.