Fix issue causing keyboard to be recreated on any datastore setting change

This commit is contained in:
Aleksandras Kostarevas 2024-04-18 13:24:16 -05:00
parent 8ae3263822
commit d2de3dee38

View File

@ -4,6 +4,7 @@ import android.content.res.Configuration
import android.inputmethodservice.InputMethodService import android.inputmethodservice.InputMethodService
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.inputmethod.CompletionInfo import android.view.inputmethod.CompletionInfo
@ -129,6 +130,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
private fun recreateKeyboard() { private fun recreateKeyboard() {
latinIMELegacy.updateTheme() latinIMELegacy.updateTheme()
latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(latinIMELegacy.currentAutoCapsState, latinIMELegacy.currentRecapitalizeState); latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(latinIMELegacy.currentAutoCapsState, latinIMELegacy.currentRecapitalizeState);
Log.w("LatinIME", "Recreating keyboard")
} }
private fun updateDrawableProvider(colorScheme: ColorScheme) { private fun updateDrawableProvider(colorScheme: ColorScheme) {
@ -239,10 +241,11 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
dataStore.data.collect { dataStore.data.collect {
drawableProvider?.let { provider -> drawableProvider?.let { provider ->
if(provider is BasicThemeProvider) { if(provider is BasicThemeProvider) {
if (it[HiddenKeysSetting] != provider.expertMode if ((it[HiddenKeysSetting] ?: provider.expertMode) != provider.expertMode
|| it[KeyBordersSetting] != provider.keyBorders || (it[KeyBordersSetting] ?: provider.keyBorders) != provider.keyBorders
|| it[KeyHintsSetting] != provider.showKeyHints || (it[KeyHintsSetting] ?: provider.showKeyHints) != provider.showKeyHints
) { ) {
Log.w("LatinIME", "One of HiddenKeysSetting, KeyBordersSetting or KeyHintsSetting has changed")
activeThemeOption?.obtainColors?.let { f -> activeThemeOption?.obtainColors?.let { f ->
updateDrawableProvider(f(this@LatinIME)) updateDrawableProvider(f(this@LatinIME))
if (!uixManager.isMainKeyboardHidden) { if (!uixManager.isMainKeyboardHidden) {
@ -270,6 +273,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
} }
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
Log.w("LatinIME", "Configuration changed")
latinIMELegacy.onConfigurationChanged(newConfig) latinIMELegacy.onConfigurationChanged(newConfig)
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
} }
@ -281,6 +285,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
private var legacyInputView: View? = null private var legacyInputView: View? = null
private var touchableHeight: Int = 0 private var touchableHeight: Int = 0
override fun onCreateInputView(): View { override fun onCreateInputView(): View {
Log.w("LatinIME", "Create input view")
legacyInputView = latinIMELegacy.onCreateInputView() legacyInputView = latinIMELegacy.onCreateInputView()
val composeView = uixManager.createComposeView() val composeView = uixManager.createComposeView()
@ -328,6 +333,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
// necessary for when KeyboardSwitcher updates the theme // necessary for when KeyboardSwitcher updates the theme
fun updateLegacyView(newView: View) { fun updateLegacyView(newView: View) {
Log.w("LatinIME", "Updating legacy view")
legacyInputView = newView legacyInputView = newView
uixManager.setContent() uixManager.setContent()