Skip to content

Commit 999c19c

Browse files
committed
Refactoring
1 parent f46bc36 commit 999c19c

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.appcompat.app.AlertDialog
1212
import androidx.core.content.res.ResourcesCompat
1313
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1414
import com.simplemobiletools.commons.extensions.*
15+
import com.simplemobiletools.commons.helpers.isNougatPlus
1516
import com.simplemobiletools.commons.models.RadioItem
1617
import com.simplemobiletools.commons.views.MyTextView
1718
import com.simplemobiletools.keyboard.R
@@ -22,7 +23,7 @@ import com.simplemobiletools.keyboard.interfaces.ClipsDao
2223
val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext)
2324

2425
val Context.safeStorageContext: Context
25-
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) {
26+
get() = if (isNougatPlus() && isDeviceLocked) {
2627
createDeviceProtectedStorageContext()
2728
} else {
2829
this

app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@ enum class ShiftState {
3030
if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) {
3131
return OFF
3232
}
33-
return when (context.config.enableSentencesCapitalization) {
34-
true -> ON_ONE_CHAR
35-
else -> OFF
33+
34+
return if (context.config.enableSentencesCapitalization) {
35+
ON_ONE_CHAR
36+
} else {
37+
OFF
3638
}
3739
}
3840

3941
fun getShiftStateForText(context: Context, inputTypeClassVariation: Int, text: String?): ShiftState {
4042
if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) {
4143
return OFF
4244
}
43-
return when {
44-
shouldCapitalize(context, text) -> {
45-
ON_ONE_CHAR
46-
}
4745

48-
else -> {
49-
OFF
50-
}
46+
return if (shouldCapitalize(context, text)) {
47+
ON_ONE_CHAR
48+
} else {
49+
OFF
5150
}
5251
}
5352

app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
105105
return
106106
} else {
107107
// try capitalizing based on the editor info like google keep or google messenger apps
108-
val editorInfo = currentInputEditorInfo
109-
110-
if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL) {
111-
if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) {
108+
if (currentInputEditorInfo != null && currentInputEditorInfo.inputType != InputType.TYPE_NULL) {
109+
if (currentInputConnection.getCursorCapsMode(currentInputEditorInfo.inputType) != 0) {
112110
keyboard?.setShifted(ShiftState.ON_ONE_CHAR)
113111
keyboardView?.invalidateAllKeys()
114112
return
@@ -117,7 +115,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
117115
}
118116
}
119117

120-
// in other cases reset shift to OFF
121118
keyboard?.setShifted(ShiftState.OFF)
122119
keyboardView?.invalidateAllKeys()
123120
}

0 commit comments

Comments
 (0)