Skip to content

Commit 68f8282

Browse files
committed
ui: improve "My Watches" view
1 parent 615235d commit 68f8282

3 files changed

Lines changed: 111 additions & 47 deletions

File tree

InfiniLink/Core/Connect/MyDevicesView.swift

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

69107
struct 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
}

InfiniLink/Core/Settings/General/About/AboutSettingsView.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ struct AboutSettingsView: View {
2323
NavigationLink {
2424
RenameView()
2525
} label: {
26-
AboutRowView(title: "Name", value: name)
26+
AboutRowView("Name", value: name)
2727
}
28-
AboutRowView(title: "Software Version", value: deviceManager.firmware)
29-
AboutRowView(title: "Manufacturer", value: deviceManager.manufacturer)
30-
AboutRowView(title: "Model Name", value: deviceManager.modelNumber)
31-
AboutRowView(title: "UUID", value: deviceManager.bleUUID)
28+
AboutRowView("Software Version", value: deviceManager.firmware)
29+
AboutRowView("Manufacturer", value: deviceManager.manufacturer)
30+
AboutRowView("Model Name", value: deviceManager.modelNumber)
31+
AboutRowView("UUID", value: deviceManager.bleUUID)
3232
}
3333
if let timeService = bleManager.currentTimeService{
3434
Section {
@@ -38,9 +38,9 @@ struct AboutSettingsView: View {
3838
}
3939
}
4040
Section {
41-
AboutRowView(title: "File System", value: deviceManager.blefsVersion)
42-
AboutRowView(title: "Hardware Revision", value: deviceManager.hardwareRevision)
43-
AboutRowView(title: "Settings Version", value: String(deviceManager.settings.version))
41+
AboutRowView("File System", value: deviceManager.blefsVersion)
42+
AboutRowView("Hardware Revision", value: deviceManager.hardwareRevision)
43+
AboutRowView("Settings Version", value: String(deviceManager.settings.version))
4444
}
4545
Section {
4646
Button("About InfiniLink") {
@@ -60,12 +60,17 @@ struct AboutSettingsView: View {
6060
}
6161

6262
struct AboutRowView: View {
63-
let title: String
63+
let title: LocalizedStringKey
6464
let value: String
6565

66+
init(_ title: LocalizedStringKey, value: String) {
67+
self.title = title
68+
self.value = value
69+
}
70+
6671
var body: some View {
6772
HStack {
68-
Text(NSLocalizedString(title, comment: ""))
73+
Text(title)
6974
Spacer()
7075
Text(value)
7176
.foregroundStyle(.gray)

InfiniLink/Localizable.xcstrings

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@
451451
},
452452
"H" : {
453453

454+
},
455+
"Hardware Revision" : {
456+
454457
},
455458
"Health" : {
456459

@@ -556,6 +559,9 @@
556559
},
557560
"M" : {
558561

562+
},
563+
"Manufacturer" : {
564+
559565
},
560566
"Maximum" : {
561567

@@ -565,6 +571,9 @@
565571
},
566572
"Minimum" : {
567573

574+
},
575+
"Model Name" : {
576+
568577
},
569578
"Music" : {
570579

@@ -574,6 +583,9 @@
574583
},
575584
"My Watches" : {
576585

586+
},
587+
"Name" : {
588+
577589
},
578590
"Navigation" : {
579591

@@ -679,6 +691,9 @@
679691
},
680692
"Settings" : {
681693

694+
},
695+
"Settings Version" : {
696+
682697
},
683698
"Several days ago" : {
684699

@@ -691,6 +706,9 @@
691706
},
692707
"Software Update" : {
693708

709+
},
710+
"Software Version" : {
711+
694712
},
695713
"Start Date" : {
696714

@@ -809,6 +827,9 @@
809827
},
810828
"user@watch:~ $ now" : {
811829

830+
},
831+
"UUID" : {
832+
812833
},
813834
"W" : {
814835

@@ -839,4 +860,4 @@
839860
}
840861
},
841862
"version" : "1.0"
842-
}
863+
}

0 commit comments

Comments
 (0)