mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 14:45:22 +00:00
- Created MeshDelegateHandler.kt to handle all BluetoothMeshDelegate callbacks - Created ChatViewModelUtils.kt for utility functions like haptic feedback - ChatViewModel now delegates all mesh events to MeshDelegateHandler - Final ChatViewModel size: 337 lines (down from 1000+ original) This completes the refactoring while maintaining 100% functionality.
38 lines
1.3 KiB
Kotlin
38 lines
1.3 KiB
Kotlin
package com.bitchat.android.ui
|
|
|
|
import android.content.Context
|
|
import android.os.Build
|
|
import android.os.VibrationEffect
|
|
import android.os.Vibrator
|
|
import android.os.VibratorManager
|
|
|
|
/**
|
|
* Utility functions for the ChatViewModel
|
|
*/
|
|
object ChatViewModelUtils {
|
|
|
|
/**
|
|
* Trigger haptic feedback
|
|
*/
|
|
fun triggerHapticFeedback(context: Context) {
|
|
try {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
|
val vibrator = vibratorManager.defaultVibrator
|
|
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
|
|
} else {
|
|
@Suppress("DEPRECATION")
|
|
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE))
|
|
} else {
|
|
@Suppress("DEPRECATION")
|
|
vibrator.vibrate(50)
|
|
}
|
|
}
|
|
} catch (e: Exception) {
|
|
// Silently ignore vibration errors
|
|
}
|
|
}
|
|
}
|