From 0b3bf0a750ffbf707619467693b68801901dbe06 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 29 May 2023 17:01:23 +1000 Subject: [PATCH] Added safeStorageContext --- .../keyboard/extensions/Context.kt | 5 +++-- .../keyboard/services/SimpleKeyboardIME.kt | 5 +++-- .../keyboard/views/MyKeyboardView.kt | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 4862531..82b9eb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -22,11 +22,12 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao -val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - createDeviceProtectedStorageContext() + val deviceContext = createDeviceProtectedStorageContext() + deviceContext } else { this } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 8a08441..e8482de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -13,8 +13,10 @@ import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION import android.view.inputmethod.EditorInfo.IME_MASK_ACTION import android.view.inputmethod.ExtractedTextRequest import com.simplemobiletools.commons.extensions.getSharedPrefs +import com.simplemobiletools.commons.extensions.isDeviceLocked import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.config +import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.views.MyKeyboardView import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_holder @@ -40,7 +42,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL override fun onInitializeInterface() { super.onInitializeInterface() - getSharedPrefs().registerOnSharedPreferenceChangeListener(this) + safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this) } override fun onCreateInputView(): View { @@ -63,7 +65,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL super.onStartInput(attribute, restarting) inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS inputTypeClassVariation = attribute!!.inputType and TYPE_MASK_VARIATION - enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION) keyboard = createNewKeyboard() keyboardView?.setKeyboard(keyboard!!) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 76b4125..40f43fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -225,9 +225,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt() mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt() mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt() - mTextColor = context.getProperTextColor() - mBackgroundColor = context.getProperBackgroundColor() - mPrimaryColor = context.getProperPrimaryColor() + mTextColor = context.safeStorageContext.getProperTextColor() + mBackgroundColor = context.safeStorageContext.getProperBackgroundColor() + mPrimaryColor = context.safeStorageContext.getProperPrimaryColor() mPreviewPopup = PopupWindow(context) mPreviewText = inflater.inflate(resources.getLayout(R.layout.keyboard_key_preview), null) as TextView @@ -374,12 +374,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } fun setupKeyboard(changedView: View? = null) { - mTextColor = context.getProperTextColor() - mBackgroundColor = context.getProperBackgroundColor() - mPrimaryColor = context.getProperPrimaryColor() + with(context.safeStorageContext) { + mTextColor = getProperTextColor() + mBackgroundColor = getProperBackgroundColor() + mPrimaryColor = getProperPrimaryColor() + + mShowKeyBorders = config.showKeyBorders + mUsingSystemTheme = config.isUsingSystemTheme + } - mShowKeyBorders = context.config.showKeyBorders - mUsingSystemTheme = context.config.isUsingSystemTheme val isMainKeyboard = changedView == null || changedView != mini_keyboard_view mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {