Skip to content

Commit

Permalink
ui: improve "My Watches" view
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcharger committed Feb 1, 2025
1 parent 615235d commit 68f8282
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 47 deletions.
110 changes: 74 additions & 36 deletions InfiniLink/Core/Connect/MyDevicesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,76 @@ struct MyDevicesView: View {
@ObservedObject var bleManager = BLEManager.shared

@State private var showConnectSheet = false
@State private var showSettings = false
@State private var showUnpairConfirmation = false

@State private var selectedWatch: Device!

var body: some View {
NavigationView {
List {
Section {
ForEach(deviceManager.watches, id: \.uuid) { watch in
Button {
bleManager.switchDevice(device: watch)
dismiss()
} label: {
DeviceRowView(watch: watch)
.foregroundStyle(Color.primary)
VStack {
NavigationLink("", isActive: $showSettings, destination: {
if let selectedWatch {
List {
Section {
AboutRowView("Name", value: selectedWatch.name ?? "InfiniTime")
AboutRowView("Software Version", value: selectedWatch.firmware ?? "Unknown")
AboutRowView("Manufacturer", value: selectedWatch.manufacturer ?? "Unknown")
AboutRowView("Model Name", value: selectedWatch.modelNumber ?? "Unknown")
AboutRowView("UUID", value: selectedWatch.bleUUID ?? "Unknown")
}
Section {
AboutRowView("File System", value: selectedWatch.blefsVersion ?? "Unknown")
AboutRowView("Hardware Revision", value: selectedWatch.hardwareRevision ?? "Unknown")
}
Section {
Button("Unpair", role: .destructive) {
showUnpairConfirmation = true
}
.foregroundStyle(.red)
.alert("Are you sure you want to unpair from \(selectedWatch.name ?? "InfiniTime")?", isPresented: $showUnpairConfirmation) {
Button(role: .destructive) {
bleManager.unpair(device: selectedWatch)
showSettings = false
} label: {
Text("Unpair")
}
}
}
}
.disabled(bleManager.pairedDeviceID ?? "" == watch.uuid ?? "")
.navigationTitle(selectedWatch.name ?? "InfiniTime")
.navigationBarTitleDisplayMode(.inline)
}
.onDelete(perform: { indexSet in
let watches = indexSet.map { deviceManager.watches[$0] }

for watch in watches {
bleManager.unpair(device: watch)
})
.hidden()
List {
Section {
ForEach(deviceManager.watches, id: \.self) { watch in
HStack {
Button {
bleManager.switchDevice(device: watch)
dismiss()
} label: {
DeviceRowView(watch: watch)
}
.disabled(bleManager.pairedDeviceID ?? "" == watch.uuid ?? "")
Image(systemName: "info.circle")
.foregroundStyle(Color.accentColor)
.onTapGesture {
selectedWatch = watch
showSettings = true
}
}
.imageScale(.large)
}
}
Section {
Button {
showConnectSheet = true
bleManager.isPairingNewDevice = true
} label: {
Text("Pair New Device")
}
})
}
Section {
Button {
showConnectSheet = true
bleManager.isPairingNewDevice = true
} label: {
Text("Pair New Device")
}
}
}
Expand All @@ -55,9 +96,6 @@ struct MyDevicesView: View {
.sheet(isPresented: $showConnectSheet, onDismiss: { bleManager.isPairingNewDevice = false }) {
ConnectView()
}
.onChange(of: bleManager.pairedDevice) { _ in
deviceManager.fetchAllDevices()
}
.onAppear {
deviceManager.fetchAllDevices()
}
Expand All @@ -67,28 +105,28 @@ struct MyDevicesView: View {
}

struct DeviceRowView: View {
let watch: Device
@Environment(\.dismiss) var dismiss

@ObservedObject var bleManager = BLEManager.shared

let watch: Device

var body: some View {
HStack(spacing: 8) {
Image(systemName: "checkmark")
.foregroundStyle(.blue)
.font(.body.weight(.semibold))
.opacity(bleManager.pairedDeviceID == watch.uuid ? 1 : 0)
WatchFaceView(watchface: .constant(UInt8(watch.watchface)), device: watch)
.frame(width: 90, height: 90)
VStack(alignment: .leading, spacing: 4) {
Text(watch.name ?? "InfiniTime")
.foregroundStyle(Color.primary)
.font(.title2.weight(.semibold))
Group {
Text("InfiniTime ") + Text(watch.firmware ?? "").font(.body.weight(.semibold))
}
.foregroundStyle(.gray)
Text("InfiniTime " + "\(watch.firmware ?? "")")
.foregroundStyle(.gray)
}
Spacer()
if bleManager.pairedDeviceID == watch.uuid {
Image(systemName: "checkmark")
.foregroundStyle(.blue)
.font(.body.weight(.semibold))
}
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions InfiniLink/Core/Settings/General/About/AboutSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ struct AboutSettingsView: View {
NavigationLink {
RenameView()
} label: {
AboutRowView(title: "Name", value: name)
AboutRowView("Name", value: name)
}
AboutRowView(title: "Software Version", value: deviceManager.firmware)
AboutRowView(title: "Manufacturer", value: deviceManager.manufacturer)
AboutRowView(title: "Model Name", value: deviceManager.modelNumber)
AboutRowView(title: "UUID", value: deviceManager.bleUUID)
AboutRowView("Software Version", value: deviceManager.firmware)
AboutRowView("Manufacturer", value: deviceManager.manufacturer)
AboutRowView("Model Name", value: deviceManager.modelNumber)
AboutRowView("UUID", value: deviceManager.bleUUID)
}
if let timeService = bleManager.currentTimeService{
Section {
Expand All @@ -38,9 +38,9 @@ struct AboutSettingsView: View {
}
}
Section {
AboutRowView(title: "File System", value: deviceManager.blefsVersion)
AboutRowView(title: "Hardware Revision", value: deviceManager.hardwareRevision)
AboutRowView(title: "Settings Version", value: String(deviceManager.settings.version))
AboutRowView("File System", value: deviceManager.blefsVersion)
AboutRowView("Hardware Revision", value: deviceManager.hardwareRevision)
AboutRowView("Settings Version", value: String(deviceManager.settings.version))
}
Section {
Button("About InfiniLink") {
Expand All @@ -60,12 +60,17 @@ struct AboutSettingsView: View {
}

struct AboutRowView: View {
let title: String
let title: LocalizedStringKey
let value: String

init(_ title: LocalizedStringKey, value: String) {
self.title = title
self.value = value
}

var body: some View {
HStack {
Text(NSLocalizedString(title, comment: ""))
Text(title)
Spacer()
Text(value)
.foregroundStyle(.gray)
Expand Down
23 changes: 22 additions & 1 deletion InfiniLink/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@
},
"H" : {

},
"Hardware Revision" : {

},
"Health" : {

Expand Down Expand Up @@ -556,6 +559,9 @@
},
"M" : {

},
"Manufacturer" : {

},
"Maximum" : {

Expand All @@ -565,6 +571,9 @@
},
"Minimum" : {

},
"Model Name" : {

},
"Music" : {

Expand All @@ -574,6 +583,9 @@
},
"My Watches" : {

},
"Name" : {

},
"Navigation" : {

Expand Down Expand Up @@ -679,6 +691,9 @@
},
"Settings" : {

},
"Settings Version" : {

},
"Several days ago" : {

Expand All @@ -691,6 +706,9 @@
},
"Software Update" : {

},
"Software Version" : {

},
"Start Date" : {

Expand Down Expand Up @@ -809,6 +827,9 @@
},
"user@watch:~ $ now" : {

},
"UUID" : {

},
"W" : {

Expand Down Expand Up @@ -839,4 +860,4 @@
}
},
"version" : "1.0"
}
}

0 comments on commit 68f8282

Please sign in to comment.