Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix complex condition detekt errors #201

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading