Skip to content

Commit bb46879

Browse files
committed
Add BluetoothConnectionState
1 parent f7d86ee commit bb46879

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// BluetoothConnectionState.swift
3+
// AndroidBluetooth
4+
//
5+
// Created by Alsey Coleman Miller on 7/13/25.
6+
//
7+
8+
import JavaKit
9+
10+
/// Connection State
11+
public enum BluetoothConnectionState: Equatable, Hashable, Sendable, CaseIterable {
12+
13+
/// The profile is in connected state
14+
case connected
15+
16+
case connecting
17+
18+
case disconnecting
19+
20+
case disconnected
21+
}
22+
23+
internal extension BluetoothConnectionState {
24+
25+
static let javaClass = try! JavaClass<BluetoothProfile>()
26+
}
27+
28+
// MARK: - RawRepresentable
29+
30+
extension BluetoothConnectionState: RawRepresentable {
31+
32+
public init?(rawValue: Int32) {
33+
guard let value = Self.allCases.first(where: { $0.rawValue == rawValue }) else {
34+
return nil
35+
}
36+
self = value
37+
}
38+
39+
public var rawValue: Int32 {
40+
switch self {
41+
case .connected:
42+
Self.javaClass.STATE_CONNECTED
43+
case .connecting:
44+
Self.javaClass.STATE_CONNECTING
45+
case .disconnecting:
46+
Self.javaClass.STATE_DISCONNECTING
47+
case .disconnected:
48+
Self.javaClass.STATE_DISCONNECTED
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)