Skip to content

Commit 665619d

Browse files
committed
chore: update formatting to appease ktlint
1 parent 607b802 commit 665619d

File tree

5 files changed

+46
-32
lines changed

5 files changed

+46
-32
lines changed

packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/ble/BleWrapper.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ data class ScanInfo(
4141
}
4242
}
4343

44-
data class BondUpdate(val deviceId: String, val bondState: Int)
45-
4644
sealed class ConnectionUpdate
4745

4846
data class ConnectionUpdateSuccess(val deviceId: String, val connectionState: Int) : ConnectionUpdate()
@@ -73,6 +71,11 @@ data class RequestConnectionPrioritySuccess(val deviceId: String) : RequestConne
7371

7472
data class RequestConnectionPriorityFailed(val deviceId: String, val errorMessage: String) : RequestConnectionPriorityResult()
7573

74+
data class BondUpdate(
75+
val deviceId: String,
76+
val bondState: Int,
77+
)
78+
7679
enum class BleStatus(val code: Int) {
7780
UNKNOWN(code = 0),
7881
UNSUPPORTED(code = 1),

packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/ble/ReactiveBleClient.kt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ open class ReactiveBleClient(private val context: Context) : BleClient {
7272

7373
context.applicationContext.registerReceiver(
7474
bondStateReceiver,
75-
IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
75+
IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED),
7676
)
7777
}
7878

@@ -428,31 +428,37 @@ open class ReactiveBleClient(private val context: Context) : BleClient {
428428
is ConnectionUpdateSuccess -> {
429429
val device = rxBleClient.getBleDevice(update.deviceId)
430430
bondUpdateBehaviorSubject.onNext(
431-
BondUpdate(update.deviceId, device.getBondState().code)
431+
BondUpdate(update.deviceId, device.getBondState().code),
432432
)
433433
}
434+
434435
is ConnectionUpdateError -> {
435436
val device = rxBleClient.getBleDevice(update.deviceId)
436437
bondUpdateBehaviorSubject.onNext(
437-
BondUpdate(update.deviceId, device.getBondState().code)
438+
BondUpdate(update.deviceId, device.getBondState().code),
438439
)
439440
}
440441
}
441442

442443
connectionUpdateBehaviorSubject.onNext(update)
443-
444444
}
445445

446-
private val bondStateReceiver = object : BroadcastReceiver() {
447-
override fun onReceive(context: Context, intent: Intent) {
448-
val device = intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
449-
val state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR)
450-
451-
if (device != null && state != BluetoothDevice.ERROR) {
452-
bondUpdateBehaviorSubject.onNext(
453-
BondUpdate(device.address, BondState.fromRaw(state).code)
454-
)
446+
private val bondStateReceiver =
447+
object : BroadcastReceiver() {
448+
override fun onReceive(
449+
context: Context,
450+
intent: Intent,
451+
) {
452+
val device =
453+
intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
454+
val state =
455+
intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR)
456+
457+
if (device != null && state != BluetoothDevice.ERROR) {
458+
bondUpdateBehaviorSubject.onNext(
459+
BondUpdate(device.address, BondState.fromRaw(state).code),
460+
)
461+
}
455462
}
456463
}
457-
}
458464
}

packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/channelhandlers/DeviceBondHandler.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import io.flutter.plugin.common.EventChannel
55
import io.reactivex.android.schedulers.AndroidSchedulers
66
import io.reactivex.disposables.Disposable
77

8-
class DeviceBondHandler(private val bleClient: com.signify.hue.flutterreactiveble.ble.BleClient) : EventChannel.StreamHandler {
8+
class DeviceBondHandler(
9+
private val bleClient: com.signify.hue.flutterreactiveble.ble.BleClient,
10+
) : EventChannel.StreamHandler {
911
private var sink: EventChannel.EventSink? = null
1012
private val converter = ProtobufMessageConverter()
1113

@@ -17,16 +19,17 @@ class DeviceBondHandler(private val bleClient: com.signify.hue.flutterreactivebl
1719
) {
1820
eventSink?.let {
1921
sink = eventSink
20-
disposable = bleClient.bondUpdateSubject
21-
.distinct()
22-
.observeOn(AndroidSchedulers.mainThread())
23-
.map(converter::convertToBondInfo)
24-
.map { it.toByteArray() }
25-
.subscribe { sink?.success(it) }
22+
disposable =
23+
bleClient.bondUpdateSubject
24+
.distinct()
25+
.observeOn(AndroidSchedulers.mainThread())
26+
.map(converter::convertToBondInfo)
27+
.map { it.toByteArray() }
28+
.subscribe { sink?.success(it) }
2629
}
2730
}
2831

2932
override fun onCancel(objectSink: Any?) {
3033
disposable.dispose()
3134
}
32-
}
35+
}

packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/converters/ProtobufMessageConverter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class ProtobufMessageConverter {
5757
.build()
5858

5959
fun convertToBondInfo(update: BondUpdate): pb.BondInfo =
60-
pb.BondInfo.newBuilder()
60+
pb.BondInfo
61+
.newBuilder()
6162
.setId(update.deviceId)
6263
.setBondState(update.bondState)
6364
.build()

packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/model/BondState.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ package com.signify.hue.flutterreactiveble.model
33
import android.bluetooth.BluetoothDevice
44
import com.polidea.rxandroidble2.RxBleDevice
55

6-
enum class BondState(val code: Int) {
6+
enum class BondState(
7+
val code: Int,
8+
) {
79
NONE(0),
810
BONDING(1),
9-
BONDED(2);
11+
BONDED(2),
12+
;
1013

1114
companion object {
12-
fun fromRaw(raw: Int): BondState {
13-
return when (raw) {
15+
fun fromRaw(raw: Int): BondState =
16+
when (raw) {
1417
BluetoothDevice.BOND_BONDING -> BONDING
1518
BluetoothDevice.BOND_BONDED -> BONDED
1619
else -> NONE
1720
}
18-
}
1921
}
2022
}
2123

22-
fun RxBleDevice.getBondState(): BondState =
23-
BondState.fromRaw(bluetoothDevice.bondState)
24+
fun RxBleDevice.getBondState(): BondState = BondState.fromRaw(bluetoothDevice.bondState)

0 commit comments

Comments
 (0)