Skip to content

Commit

Permalink
fix: Fix complex condition detekt errors
Browse files Browse the repository at this point in the history
  • Loading branch information
albendz committed Oct 15, 2024
1 parent 3889184 commit d03787e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions app/src/main/java/be/scri/views/MyKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,14 @@ class MyKeyboardView
}
}

private fun adjustCase(label: CharSequence): CharSequence? {
var newLabel: CharSequence? = label
if (newLabel != null && newLabel.isNotEmpty() && mKeyboard!!.mShiftState > SHIFT_OFF && newLabel.length < 3 && Character.isLowerCase(newLabel[0])) {
newLabel = newLabel.toString().toUpperCase()
}
return newLabel
}
private fun adjustCase(label: CharSequence?): CharSequence? =
label?.takeIf { it.length in 1..2 }?.let {
if (mKeyboard?.mShiftState?.let { state -> state > SHIFT_OFF } == true) {
label.toString().uppercase()
} else {
label
}
} ?: label

public override fun onMeasure(
widthMeasureSpec: Int,
Expand Down Expand Up @@ -528,10 +529,10 @@ class MyKeyboardView
val keyMargin = 8
val shadowOffset = 3
if (mBuffer == null || mKeyboardChanged) {
if (mBuffer == null || mKeyboardChanged && (mBuffer!!.width != width || mBuffer!!.height != height)) {
if (mBuffer?.let { buffer -> buffer.width != width || buffer.height != height } != false) {
// Make sure our bitmap is at least 1x1
val width = Math.max(1, width)
val height = Math.max(1, height)
val width = 1.coerceAtLeast(width)
val height = 1.coerceAtLeast(height)
mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
mCanvas = Canvas(mBuffer!!)
}
Expand Down Expand Up @@ -752,11 +753,9 @@ class MyKeyboardView

if (mCurrentKeyIndex != NOT_A_KEY && keys.size > mCurrentKeyIndex) {
val newKey = keys[mCurrentKeyIndex]

val code = newKey.code
if (code == KEYCODE_SHIFT || code == KEYCODE_MODE_CHANGE || code == KEYCODE_DELETE || code == KEYCODE_ENTER || code == KEYCODE_SPACE) {
newKey.pressed = true
}

newKey.pressed = code in listOf(KEYCODE_SHIFT, KEYCODE_MODE_CHANGE, KEYCODE_DELETE, KEYCODE_ENTER, KEYCODE_SPACE)

invalidateKey(mCurrentKeyIndex)
sendAccessibilityEventForUnicodeCharacter(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, code)
Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ complexity:
NestedBlockDepth:
active: false
ComplexCondition:
active: false
active: true
LongParameterList:
active: false
LongMethod:
Expand Down

0 comments on commit d03787e

Please sign in to comment.