mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 07:24:22 +01:00
Make test with service working
This commit is contained in:
@@ -31,41 +31,11 @@
|
||||
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import no.nordicsemi.android.kotlin.ble.core.ServerDevice
|
||||
import javax.inject.Inject
|
||||
|
||||
const val DEVICE_DATA = "device-data"
|
||||
|
||||
class ServiceManager @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context
|
||||
) {
|
||||
interface ServiceManager {
|
||||
|
||||
fun <T> startService(service: Class<T>, device: ServerDevice) {
|
||||
val intent = Intent(context, service).apply {
|
||||
putExtra(DEVICE_DATA, device)
|
||||
}
|
||||
context.startService(intent)
|
||||
}
|
||||
|
||||
fun <T> startService(service: Class<T>, device: BluetoothDevice) {
|
||||
val intent = Intent(context, service).apply {
|
||||
putExtra(DEVICE_DATA, device)
|
||||
}
|
||||
context.startService(intent)
|
||||
}
|
||||
|
||||
fun <T> startService(service: Class<T>) {
|
||||
val intent = Intent(context, service)
|
||||
context.startService(intent)
|
||||
}
|
||||
|
||||
fun <T> stopService(service: Class<T>) {
|
||||
val intent = Intent(context, service)
|
||||
context.stopService(intent)
|
||||
}
|
||||
fun <T> startService(service: Class<T>, device: ServerDevice)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class ServiceManagerHiltModule {
|
||||
|
||||
@Provides
|
||||
fun createServiceManager(
|
||||
@ApplicationContext
|
||||
context: Context,
|
||||
): ServiceManager {
|
||||
return ServiceManagerImpl(context)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package no.nordicsemi.android.service
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import no.nordicsemi.android.kotlin.ble.core.ServerDevice
|
||||
import javax.inject.Inject
|
||||
|
||||
class ServiceManagerImpl @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context
|
||||
): ServiceManager {
|
||||
|
||||
override fun <T> startService(service: Class<T>, device: ServerDevice) {
|
||||
val intent = Intent(context, service).apply {
|
||||
putExtra(DEVICE_DATA, device)
|
||||
}
|
||||
context.startService(intent)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user