From 999c19cb7434e5bab091fa5c454d8e541be82d06 Mon Sep 17 00:00:00 2001 From: merkost Date: Thu, 8 Jun 2023 15:55:13 +1000 Subject: [PATCH] Refactoring --- .../keyboard/extensions/Context.kt | 3 ++- .../keyboard/helpers/ShiftState.kt | 19 +++++++++---------- .../keyboard/services/SimpleKeyboardIME.kt | 7 ++----- 3 files changed, 13 insertions(+), 16 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 cd8c494f..3091e45b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -12,6 +12,7 @@ import androidx.appcompat.app.AlertDialog import androidx.core.content.res.ResourcesCompat import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyTextView import com.simplemobiletools.keyboard.R @@ -22,7 +23,7 @@ import com.simplemobiletools.keyboard.interfaces.ClipsDao val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) { + get() = if (isNougatPlus() && isDeviceLocked) { createDeviceProtectedStorageContext() } else { this diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt index 8b29258d..b00b4bca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt @@ -30,9 +30,11 @@ enum class ShiftState { if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) { return OFF } - return when (context.config.enableSentencesCapitalization) { - true -> ON_ONE_CHAR - else -> OFF + + return if (context.config.enableSentencesCapitalization) { + ON_ONE_CHAR + } else { + OFF } } @@ -40,14 +42,11 @@ enum class ShiftState { if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) { return OFF } - return when { - shouldCapitalize(context, text) -> { - ON_ONE_CHAR - } - else -> { - OFF - } + return if (shouldCapitalize(context, text)) { + ON_ONE_CHAR + } else { + OFF } } 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 3054377a..05752c8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -105,10 +105,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL return } else { // try capitalizing based on the editor info like google keep or google messenger apps - val editorInfo = currentInputEditorInfo - - if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL) { - if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) { + if (currentInputEditorInfo != null && currentInputEditorInfo.inputType != InputType.TYPE_NULL) { + if (currentInputConnection.getCursorCapsMode(currentInputEditorInfo.inputType) != 0) { keyboard?.setShifted(ShiftState.ON_ONE_CHAR) keyboardView?.invalidateAllKeys() return @@ -117,7 +115,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } } - // in other cases reset shift to OFF keyboard?.setShifted(ShiftState.OFF) keyboardView?.invalidateAllKeys() }