Updated on 2026-08-14
This commit is contained in:
parent
326352be30
commit
75e2b0b554
27 changed files with 194 additions and 2 deletions
37
app/src/main/java/com/tangem/tap/di/HapticModule.kt
Normal file
37
app/src/main/java/com/tangem/tap/di/HapticModule.kt
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package com.tangem.tap.di
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Vibrator
|
||||
import android.os.VibratorManager
|
||||
import com.tangem.tap.common.haptic.DefaultHapticManager
|
||||
import com.tangem.core.ui.haptic.HapticManager
|
||||
import com.tangem.core.ui.haptic.MockHapticManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class HapticModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideHapticManager(@ApplicationContext context: Context): HapticManager {
|
||||
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||
vibratorManager.defaultVibrator
|
||||
} else {
|
||||
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
}
|
||||
|
||||
return if (vibrator.hasVibrator()) {
|
||||
DefaultHapticManager(vibrator = vibrator)
|
||||
} else {
|
||||
MockHapticManager
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue