From 48a6b9903746422fcadbd3ed93b3d5dbc75254b6 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 17 Dec 2024 16:16:04 +0100 Subject: [PATCH] chore(Sonar): Fix some Sonar issues --- .../ui/components/SwissTransferChips.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferChips.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferChips.kt index c548cca9c..775fa636d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferChips.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferChips.kt @@ -71,6 +71,13 @@ fun SwissTransferInputChip(modifier: Modifier = Modifier, text: String, onDismis val focusManager = LocalFocusManager.current + fun handleBackspaceKey() { + when { + isSelected -> onDismiss() + isFocused -> isSelected = true + } + } + fun onKeyEvent(event: KeyEvent): Boolean { if (event.type != KeyEventType.KeyUp) return false @@ -80,10 +87,7 @@ fun SwissTransferInputChip(modifier: Modifier = Modifier, text: String, onDismis true } event.key == Key.Backspace || event.key == Key.Delete -> { - when { - isSelected -> onDismiss() - isFocused -> isSelected = true - } + handleBackspaceKey() true } event.key == Key.NavigateOut -> { @@ -143,9 +147,9 @@ private fun ChipLabel(text: String) { } private fun isDirectionalKey(key: Key): Boolean { - return key == Key.DirectionLeft || key == Key.DirectionRight || key == Key.DirectionUpLeft || key == Key.DirectionUp - || key == Key.DirectionDown || key == Key.DirectionCenter || key == Key.DirectionDownLeft || key == Key.DirectionDownRight - || key == Key.DirectionUpRight + return key == Key.DirectionLeft || key == Key.DirectionCenter || key == Key.DirectionRight + || key == Key.DirectionUpLeft || key == Key.DirectionUp || key == Key.DirectionUpRight + || key == Key.DirectionDownLeft || key == Key.DirectionDown || key == Key.DirectionDownRight || key == Key.SystemNavigationLeft || key == Key.SystemNavigationRight || key == Key.SystemNavigationUp || key == Key.SystemNavigationDown || key == Key.NavigatePrevious || key == Key.NavigateNext