Skip to content

Commit

Permalink
Merge pull request #201 from albendz/albendz_complexcondition
Browse files Browse the repository at this point in the history
fix: Fix complex condition detekt errors
  • Loading branch information
andrewtavis authored Oct 24, 2024
2 parents 90c9205 + 3a257fa commit 5541547
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
47 changes: 21 additions & 26 deletions app/src/main/java/be/scri/views/MyKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,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().uppercase(Locale.getDefault())
}
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(Locale.getDefault())
} else {
label
}
} ?: label

public override fun onMeasure(
widthMeasureSpec: Int,
Expand Down Expand Up @@ -546,10 +541,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 @@ -778,17 +773,17 @@ 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
}
val pressedKeys =
listOf(
KEYCODE_SHIFT,
KEYCODE_MODE_CHANGE,
KEYCODE_DELETE,
KEYCODE_ENTER,
KEYCODE_SPACE,
)

newKey.pressed = code in pressedKeys

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 5541547

Please sign in to comment.