Skip to content

Commit 1595298

Browse files
committed
multiple: UI improvements and bugfixes
1 parent dff63f7 commit 1595298

10 files changed

Lines changed: 50 additions & 35 deletions

File tree

InfiniLink/Core/Components/Charts/StepChartView.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct StepChartView: View {
7878
y: .value("Steps", $0.steps)
7979
)
8080
.foregroundStyle(.blue)
81-
.opacity(!showSelectionBar || selectedDate.formatted(.dateTime.dayOfYear()) == $0.date.formatted(.dateTime.dayOfYear()) ? 1 : 0.5)
81+
.opacity(!showSelectionBar || selectedDate.comparable() == $0.date.comparable() ? 1 : 0.5)
8282
}
8383
}
8484
.chartOverlay { proxy in
@@ -103,7 +103,7 @@ struct StepChartView: View {
103103

104104
let (day, _) = proxy.value(at: location, as: (Date, Int).self) ?? (Date(), 0)
105105
// We compare the formatted dates because the dates are too specific otherwise
106-
let steps = weekSteps().first(where: { $0.date.formatted(.dateTime.dayOfYear()) == day.formatted(.dateTime.dayOfYear()) })?.steps ?? 0
106+
let steps = weekSteps().first(where: { $0.date.comparable() == day.comparable() })?.steps ?? 0
107107

108108
selectedDate = day
109109
selectedSteps = steps
@@ -128,11 +128,11 @@ struct StepChartView: View {
128128
if showSelectionBar {
129129
return "\(selectedSteps) "
130130
} else if !weekSteps().isEmpty {
131-
return "\(weekSteps().reduce(0) { $0 + $1.steps }) "
131+
return "\(weekSteps().reduce(0) { $0 + $1.steps } / weekSteps().count) "
132132
}
133133
return "0 "
134134
}())
135-
.font(.system(.title, design: .rounded))
135+
.font(.system(size: 28))
136136
.foregroundColor(.primary)
137137
+ Text("steps")
138138
Text(showSelectionBar ? "\(selectedDate.formatted(date: .abbreviated, time: .omitted))" : "\(earliestDate.formatted(date: .abbreviated, time: .omitted)) - \(latestDate.formatted(date: .abbreviated, time: .omitted))")
@@ -149,17 +149,23 @@ struct StepChartView: View {
149149
if (stepCountManager.stepGoal - bleManager.stepCount) <= 1000 {
150150
return "Take a short walk or a start an activity to complete your goal."
151151
}
152-
return "Set aside some time to complete a few activities to reach your goal."
152+
return "Complete a few activities to reach your goal."
153153
}()
154154

155-
Text("Your daily step goal is \(stepCountManager.stepGoal - bleManager.stepCount) steps away. \(encouragementString)")
155+
Text("You're \(stepCountManager.stepGoal - bleManager.stepCount) steps away your daily step goal! \(encouragementString)")
156156
}
157157
}
158+
// TODO: move to separate component
158159
Section {
159160
// TODO: add a monthly overview chart
160161
} header: {
161-
Text("Monthly Overview • \(earliestDate.formatted(date: .abbreviated, time: .omitted)) - \(latestDate.formatted(date: .abbreviated, time: .omitted))")
162-
.fontWeight(.semibold)
162+
VStack(alignment: .leading, spacing: 7) {
163+
Text("Monthly Overview")
164+
Text("\(earliestDate.formatted(.dateTime.month(.abbreviated).day())) - \(latestDate.formatted(date: .abbreviated, time: .omitted))")
165+
.font(.system(size: 20))
166+
.foregroundColor(.primary)
167+
}
168+
.fontWeight(.semibold)
163169
}
164170
.listRowBackground(Color.clear)
165171
.listRowInsets(EdgeInsets(top: 18, leading: 0, bottom: 0, trailing: 0))

InfiniLink/Core/DeviceView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ struct DeviceView: View {
225225

226226
self.showNavigationTitle = (value <= -135)
227227
}
228-
.onChange(of: bleManager.blefsTransfer) { _ in
229-
if bleManager.blefsTransfer != nil {
228+
.onChange(of: bleManager.blefsTransfer) { blefsTransfer in
229+
if blefsTransfer != nil {
230230
BLEFSHandler.shared.readSettings { settings in
231231
deviceManager.updateSettings(settings: settings)
232232
}

InfiniLink/Core/HeartView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct HeartView: View {
1515
@FetchRequest(sortDescriptors: [SortDescriptor(\.timestamp)]) var heartDataPoints: FetchedResults<HeartDataPoint>
1616

1717
var heartPointValues: [Double] {
18-
return chartManager.heartPoints().compactMap({ $0.value })
18+
return heartDataPoints.compactMap({ $0.value })
1919
}
2020

2121
func heartRate(for val: Double) -> String {
@@ -47,7 +47,7 @@ struct HeartView: View {
4747
List {
4848
Group {
4949
Section {
50-
DetailHeaderView(Header(title: String(format: "%.0f", heartPointValues.last ?? 0), subtitle: timestamp(for: chartManager.heartPoints().last), units: "BPM", icon: "heart.fill", accent: .red), width: geo.size.width, animate: (heartDataPoints.last?.timestamp?.timeIntervalSinceNow ?? 60) < 60) {
50+
DetailHeaderView(Header(title: String(format: "%.0f", heartPointValues.last ?? 0), subtitle: timestamp(for: heartDataPoints.last), units: "BPM", icon: "heart.fill", accent: .red), width: geo.size.width, animate: (heartDataPoints.last?.timestamp?.timeIntervalSinceNow ?? 60) < 60) {
5151
HStack {
5252
DetailHeaderSubItemView(
5353
title: "Min",

InfiniLink/Core/Settings/BatterySettingsView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct BatterySettingsView: View {
1111
@AppStorage("sendLowBatteryNotification") var sendLowBatteryNotification = true
1212
@AppStorage("sendLowBatteryNotificationToiPhone") var sendLowBatteryNotificationToiPhone = true
1313
@AppStorage("sendLowBatteryNotificationToWatch") var sendLowBatteryNotificationToWatch = true
14+
@AppStorage("watchNotifications") var watchNotifications = true
1415

1516
@ObservedObject var bleManager = BLEManager.shared
1617

@@ -52,9 +53,10 @@ struct BatterySettingsView: View {
5253
Toggle("Notify on Low Battery", isOn: $sendLowBatteryNotification)
5354
}
5455
if sendLowBatteryNotification {
55-
Section {
56+
Section(footer: watchNotifications ? nil : Text("Watch notifications are currently disabled.")) {
5657
Toggle("Send to iPhone", isOn: $sendLowBatteryNotificationToiPhone)
5758
Toggle("Send to Watch", isOn: $sendLowBatteryNotificationToWatch)
59+
.disabled(!watchNotifications)
5860
}
5961
}
6062
}

InfiniLink/Core/Settings/Notifications/NotificationsSettingsView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ struct NotificationsSettingsView: View {
6868
if heartRangeReminder {
6969
HStack {
7070
Text("Minimum")
71+
Spacer()
72+
Text("\(minHeartRange)")
7173
Stepper("\(minHeartRange)", value: $minHeartRange, in: 40...(maxHeartRange - 1), step: 1)
7274
.fontWeight(.semibold)
75+
.labelsHidden()
7376
}
7477
HStack {
7578
Text("Maximum")
79+
Spacer()
80+
Text("\(maxHeartRange)")
7681
Stepper("\(maxHeartRange)", value: $maxHeartRange, in: (minHeartRange + 1)...220, step: 1)
7782
.fontWeight(.semibold)
83+
.labelsHidden()
7884
}
7985
}
8086
}

InfiniLink/Date+Extension.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import Foundation
99

1010
extension Date {
11+
func comparable() -> String {
12+
return self.formatted(.dateTime.dayOfYear())
13+
}
14+
1115
static var startOfMonth: Date {
1216
let calendar = Calendar.current
1317
let components = calendar.dateComponents([.year, .month], from: Date())

InfiniLink/Localizable.xcstrings

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,8 @@
565565
"Model Name" : {
566566

567567
},
568-
"Monthly Overview • %@ - %@" : {
569-
"localizations" : {
570-
"en" : {
571-
"stringUnit" : {
572-
"state" : "new",
573-
"value" : "Monthly Overview • %1$@ - %2$@"
574-
}
575-
}
576-
}
568+
"Monthly Overview" : {
569+
577570
},
578571
"Music" : {
579572

@@ -833,6 +826,9 @@
833826
},
834827
"W" : {
835828

829+
},
830+
"Watch notifications are currently disabled." : {
831+
836832
},
837833
"Water Reminder" : {
838834

@@ -848,6 +844,16 @@
848844
},
849845
"You can start one by choosing one from the list below." : {
850846

847+
},
848+
"You're %lld steps away your daily step goal! %@" : {
849+
"localizations" : {
850+
"en" : {
851+
"stringUnit" : {
852+
"state" : "new",
853+
"value" : "You're %1$lld steps away your daily step goal! %2$@"
854+
}
855+
}
856+
}
851857
},
852858
"You've reached your steps goal" : {
853859

@@ -857,16 +863,6 @@
857863
},
858864
"Your approximate weight, in lbs." : {
859865

860-
},
861-
"Your daily step goal is %lld steps away. %@" : {
862-
"localizations" : {
863-
"en" : {
864-
"stringUnit" : {
865-
"state" : "new",
866-
"value" : "Your daily step goal is %1$lld steps away. %2$@"
867-
}
868-
}
869-
}
870866
}
871867
},
872868
"version" : "1.0"

InfiniLink/Utils/HealthKitManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class HealthKitManager: ObservableObject {
9595

9696
guard let healthStore = self.healthStore else { return }
9797

98-
healthStore.requestAuthorization(toShare: [steps, heartRate], read: []) { success, error in
98+
healthStore.requestAuthorization(toShare: [steps, heartRate], read: [steps]) { success, error in
9999
if let error = error {
100100
log(error.localizedDescription, caller: "HealthKitManager")
101101
}

InfiniLink/Utils/NotificationManager.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class NotificationManager: ObservableObject {
3232
@Published var canSendNotifications = false
3333

3434
@AppStorage("watchNotifications") var watchNotifications = true
35+
@AppStorage("sendLowBatteryNotification") var sendBatteryNotifications = true
3536
@AppStorage("sendLowBatteryNotificationToiPhone") var sendLowBatteryNotificationToiPhone = true
3637
@AppStorage("sendLowBatteryNotificationToWatch") var sendLowBatteryNotificationToWatch = true
3738

@@ -102,10 +103,10 @@ extension NotificationManager {
102103
let bat = bleManager.batteryLevel
103104
let notif = AppNotification(title: NSLocalizedString("Battery Low", comment: ""), subtitle: "\(String(format: "%.0f", bat))% " + NSLocalizedString("battery remaining", comment: ""))
104105

105-
if sendLowBatteryNotificationToWatch {
106+
if sendLowBatteryNotificationToWatch && sendBatteryNotifications {
106107
self.bleWriteManager.sendNotification(notif)
107108
}
108-
if sendLowBatteryNotificationToiPhone {
109+
if sendLowBatteryNotificationToiPhone && sendBatteryNotifications {
109110
self.sendNotificationToHost(notif)
110111
}
111112
}

assets/AppIcon/appIcon.psd

-251 KB
Binary file not shown.

0 commit comments

Comments
 (0)