From 468ad0ba14a9158faba6a5cf54ebce94f6493f8d Mon Sep 17 00:00:00 2001 From: Linfye <3158203624@qq.com> Date: Thu, 24 Oct 2024 09:48:18 +0800 Subject: [PATCH] Fix rebase issues --- .../be/scri/services/EnglishKeyboardIME.kt | 16 +++--------- .../be/scri/services/SimpleKeyboardIME.kt | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt index 00cbfe25..fe033f05 100644 --- a/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/EnglishKeyboardIME.kt @@ -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 @@ -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> - private var lastWord: String? = null - private var autosuggestEmojis: MutableList? = null - override fun onCreateInputView(): View { binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater) setupCommandBarTheme(binding) @@ -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) { @@ -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) { diff --git a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt index 92cc5dee..12aa1e03 100644 --- a/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt +++ b/app/src/main/java/be/scri/services/SimpleKeyboardIME.kt @@ -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 @@ -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> + var isAutoSuggestEnabled: Boolean = false + var lastWord: String? = null + var autosuggestEmojis: MutableList? = 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, @@ -137,6 +142,7 @@ abstract class SimpleKeyboardIME( setupIdleView() initializeEmojiButtons() updateButtonVisibility(isAutoSuggestEnabled) + updateButtonText(isAutoSuggestEnabled, autosuggestEmojis) } ScribeState.SELECT_COMMAND -> setupSelectCommandView() @@ -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