From 7a68f331b02f3a7d9d2d610b6d93fae378b79026 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Tue, 23 Sep 2025 23:05:07 +0800 Subject: [PATCH] Refactor haptic feedback type selection --- .../hippo/ehviewer/ui/tools/HapticFeedback.kt | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/HapticFeedback.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/HapticFeedback.kt index e5a59aebf..e4f6c09e9 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/HapticFeedback.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/HapticFeedback.kt @@ -28,34 +28,21 @@ fun rememberHapticFeedback(): HapticFeedback { class AndroidHapticFeedback(private val view: View) : HapticFeedback { override fun performHapticFeedback(hapticFeedbackType: HapticFeedbackType) { val feedbackConstant = when (hapticFeedbackType) { - HapticFeedbackType.START -> { - if (isAtLeastU) { - HapticFeedbackConstants.DRAG_START - } else if (isAtLeastR) { - HapticFeedbackConstants.GESTURE_START - } else if (isAtLeastOMR1) { - HapticFeedbackConstants.KEYBOARD_PRESS - } else { - HapticFeedbackConstants.VIRTUAL_KEY - } + HapticFeedbackType.START -> when { + isAtLeastU -> HapticFeedbackConstants.DRAG_START + isAtLeastR -> HapticFeedbackConstants.GESTURE_START + isAtLeastOMR1 -> HapticFeedbackConstants.KEYBOARD_PRESS + else -> HapticFeedbackConstants.VIRTUAL_KEY } - HapticFeedbackType.MOVE -> { - if (isAtLeastU) { - HapticFeedbackConstants.SEGMENT_FREQUENT_TICK - } else if (isAtLeastOMR1) { - HapticFeedbackConstants.TEXT_HANDLE_MOVE - } else { - HapticFeedbackConstants.CLOCK_TICK - } + HapticFeedbackType.MOVE -> when { + isAtLeastU -> HapticFeedbackConstants.SEGMENT_FREQUENT_TICK + isAtLeastOMR1 -> HapticFeedbackConstants.TEXT_HANDLE_MOVE + else -> HapticFeedbackConstants.CLOCK_TICK } - HapticFeedbackType.END -> { - if (isAtLeastR) { - HapticFeedbackConstants.GESTURE_END - } else if (isAtLeastOMR1) { - HapticFeedbackConstants.KEYBOARD_RELEASE - } else { - HapticFeedbackConstants.VIRTUAL_KEY - } + HapticFeedbackType.END -> when { + isAtLeastR -> HapticFeedbackConstants.GESTURE_END + isAtLeastOMR1 -> HapticFeedbackConstants.KEYBOARD_RELEASE + else -> HapticFeedbackConstants.VIRTUAL_KEY } } view.performHapticFeedback(feedbackConstant)