@@ -14,35 +14,76 @@ struct MyDevicesView: View {
1414 @ObservedObject var bleManager = BLEManager . shared
1515
1616 @State private var showConnectSheet = false
17+ @State private var showSettings = false
18+ @State private var showUnpairConfirmation = false
19+
20+ @State private var selectedWatch : Device !
1721
1822 var body : some View {
1923 NavigationView {
20- List {
21- Section {
22- ForEach ( deviceManager. watches, id: \. uuid) { watch in
23- Button {
24- bleManager. switchDevice ( device: watch)
25- dismiss ( )
26- } label: {
27- DeviceRowView ( watch: watch)
28- . foregroundStyle ( Color . primary)
24+ VStack {
25+ NavigationLink ( " " , isActive: $showSettings, destination: {
26+ if let selectedWatch {
27+ List {
28+ Section {
29+ AboutRowView ( " Name " , value: selectedWatch. name ?? " InfiniTime " )
30+ AboutRowView ( " Software Version " , value: selectedWatch. firmware ?? " Unknown " )
31+ AboutRowView ( " Manufacturer " , value: selectedWatch. manufacturer ?? " Unknown " )
32+ AboutRowView ( " Model Name " , value: selectedWatch. modelNumber ?? " Unknown " )
33+ AboutRowView ( " UUID " , value: selectedWatch. bleUUID ?? " Unknown " )
34+ }
35+ Section {
36+ AboutRowView ( " File System " , value: selectedWatch. blefsVersion ?? " Unknown " )
37+ AboutRowView ( " Hardware Revision " , value: selectedWatch. hardwareRevision ?? " Unknown " )
38+ }
39+ Section {
40+ Button ( " Unpair " , role: . destructive) {
41+ showUnpairConfirmation = true
42+ }
43+ . foregroundStyle ( . red)
44+ . alert ( " Are you sure you want to unpair from \( selectedWatch. name ?? " InfiniTime " ) ? " , isPresented: $showUnpairConfirmation) {
45+ Button ( role: . destructive) {
46+ bleManager. unpair ( device: selectedWatch)
47+ showSettings = false
48+ } label: {
49+ Text ( " Unpair " )
50+ }
51+ }
52+ }
2953 }
30- . disabled ( bleManager. pairedDeviceID ?? " " == watch. uuid ?? " " )
54+ . navigationTitle ( selectedWatch. name ?? " InfiniTime " )
55+ . navigationBarTitleDisplayMode ( . inline)
3156 }
32- . onDelete ( perform: { indexSet in
33- let watches = indexSet. map { deviceManager. watches [ $0] }
34-
35- for watch in watches {
36- bleManager. unpair ( device: watch)
57+ } )
58+ . hidden ( )
59+ List {
60+ Section {
61+ ForEach ( deviceManager. watches, id: \. self) { watch in
62+ HStack {
63+ Button {
64+ bleManager. switchDevice ( device: watch)
65+ dismiss ( )
66+ } label: {
67+ DeviceRowView ( watch: watch)
68+ }
69+ . disabled ( bleManager. pairedDeviceID ?? " " == watch. uuid ?? " " )
70+ Image ( systemName: " info.circle " )
71+ . foregroundStyle ( Color . accentColor)
72+ . onTapGesture {
73+ selectedWatch = watch
74+ showSettings = true
75+ }
76+ }
77+ . imageScale ( . large)
78+ }
79+ }
80+ Section {
81+ Button {
82+ showConnectSheet = true
83+ bleManager. isPairingNewDevice = true
84+ } label: {
85+ Text ( " Pair New Device " )
3786 }
38- } )
39- }
40- Section {
41- Button {
42- showConnectSheet = true
43- bleManager. isPairingNewDevice = true
44- } label: {
45- Text ( " Pair New Device " )
4687 }
4788 }
4889 }
@@ -55,9 +96,6 @@ struct MyDevicesView: View {
5596 . sheet ( isPresented: $showConnectSheet, onDismiss: { bleManager. isPairingNewDevice = false } ) {
5697 ConnectView ( )
5798 }
58- . onChange ( of: bleManager. pairedDevice) { _ in
59- deviceManager. fetchAllDevices ( )
60- }
6199 . onAppear {
62100 deviceManager. fetchAllDevices ( )
63101 }
@@ -67,28 +105,28 @@ struct MyDevicesView: View {
67105}
68106
69107struct DeviceRowView : View {
70- let watch : Device
108+ @ Environment ( \ . dismiss ) var dismiss
71109
72110 @ObservedObject var bleManager = BLEManager . shared
73111
112+ let watch : Device
113+
74114 var body : some View {
75115 HStack ( spacing: 8 ) {
116+ Image ( systemName: " checkmark " )
117+ . foregroundStyle ( . blue)
118+ . font ( . body. weight ( . semibold) )
119+ . opacity ( bleManager. pairedDeviceID == watch. uuid ? 1 : 0 )
76120 WatchFaceView ( watchface: . constant( UInt8 ( watch. watchface) ) , device: watch)
77121 . frame ( width: 90 , height: 90 )
78122 VStack ( alignment: . leading, spacing: 4 ) {
79123 Text ( watch. name ?? " InfiniTime " )
124+ . foregroundStyle ( Color . primary)
80125 . font ( . title2. weight ( . semibold) )
81- Group {
82- Text ( " InfiniTime " ) + Text( watch. firmware ?? " " ) . font ( . body. weight ( . semibold) )
83- }
84- . foregroundStyle ( . gray)
126+ Text ( " InfiniTime " + " \( watch. firmware ?? " " ) " )
127+ . foregroundStyle ( . gray)
85128 }
86129 Spacer ( )
87- if bleManager. pairedDeviceID == watch. uuid {
88- Image ( systemName: " checkmark " )
89- . foregroundStyle ( . blue)
90- . font ( . body. weight ( . semibold) )
91- }
92130 }
93131 }
94132}
0 commit comments