mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 09:25:19 +00:00
REFACTOR STEP 2: Extract mesh delegate handling to separate class
- 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.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user