2020-04-02 18:48:37 +02:00
|
|
|
package info.nightscout.androidaps.receivers
|
|
|
|
|
|
|
|
import android.bluetooth.BluetoothDevice
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import dagger.android.DaggerBroadcastReceiver
|
|
|
|
import info.nightscout.androidaps.events.EventBTChange
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
class BTReceiver : DaggerBroadcastReceiver() {
|
|
|
|
@Inject lateinit var rxBus: RxBusWrapper
|
|
|
|
|
|
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
super.onReceive(context, intent)
|
2020-04-24 19:09:42 +02:00
|
|
|
val device: BluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
|
2020-04-02 18:48:37 +02:00
|
|
|
|
|
|
|
when (intent.action) {
|
2020-04-24 19:09:42 +02:00
|
|
|
BluetoothDevice.ACTION_ACL_CONNECTED ->
|
|
|
|
rxBus.send(EventBTChange(EventBTChange.Change.CONNECT, deviceName = device.name, deviceAddress = device.address))
|
2020-04-02 18:48:37 +02:00
|
|
|
BluetoothDevice.ACTION_ACL_DISCONNECTED ->
|
2020-04-24 19:09:42 +02:00
|
|
|
rxBus.send(EventBTChange(EventBTChange.Change.DISCONNECT, deviceName = device.name, deviceAddress = device.address))
|
2020-04-02 18:48:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|