Skip to content

Commit b545da0

Browse files
committed
UI changes, changed step count persistence manager back to a struct.
1 parent 3044cf8 commit b545da0

8 files changed

Lines changed: 139 additions & 35 deletions

File tree

InfiniLink.xcodeproj/project.pbxproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
2675CA5A26DC81AA00967E4D /* DFUComplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2675CA5926DC81AA00967E4D /* DFUComplete.swift */; };
5151
267C2EF8273C8AB300F464B0 /* StepWeeklyGraph.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267C2EF7273C8AB300F464B0 /* StepWeeklyGraph.swift */; };
5252
267C2EFA273DB62800F464B0 /* StepsSettingsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267C2EF9273DB62800F464B0 /* StepsSettingsSheet.swift */; };
53+
267C2EFD273DDB5500F464B0 /* StepSettingsGoalChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267C2EFC273DDB5500F464B0 /* StepSettingsGoalChange.swift */; };
54+
267C2EFF273DDBFF00F464B0 /* StepSettingsDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267C2EFE273DDBFF00F464B0 /* StepSettingsDatePicker.swift */; };
5355
268E773C27174A2B000DF90D /* ChartSettingsSheetMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 268E773B27174A2B000DF90D /* ChartSettingsSheetMain.swift */; };
5456
268E773F27174B8B000DF90D /* ChartSettingsSheetSliders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 268E773E27174B8B000DF90D /* ChartSettingsSheetSliders.swift */; };
5557
268E774127175830000DF90D /* ChartSettingsSheetDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 268E774027175830000DF90D /* ChartSettingsSheetDatePicker.swift */; };
@@ -151,6 +153,8 @@
151153
2675CA5926DC81AA00967E4D /* DFUComplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUComplete.swift; sourceTree = "<group>"; };
152154
267C2EF7273C8AB300F464B0 /* StepWeeklyGraph.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepWeeklyGraph.swift; sourceTree = "<group>"; };
153155
267C2EF9273DB62800F464B0 /* StepsSettingsSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsSettingsSheet.swift; sourceTree = "<group>"; };
156+
267C2EFC273DDB5500F464B0 /* StepSettingsGoalChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepSettingsGoalChange.swift; sourceTree = "<group>"; };
157+
267C2EFE273DDBFF00F464B0 /* StepSettingsDatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepSettingsDatePicker.swift; sourceTree = "<group>"; };
154158
268E773B27174A2B000DF90D /* ChartSettingsSheetMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartSettingsSheetMain.swift; sourceTree = "<group>"; };
155159
268E773E27174B8B000DF90D /* ChartSettingsSheetSliders.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartSettingsSheetSliders.swift; sourceTree = "<group>"; };
156160
268E774027175830000DF90D /* ChartSettingsSheetDatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartSettingsSheetDatePicker.swift; sourceTree = "<group>"; };
@@ -373,6 +377,16 @@
373377
path = "View Utilities";
374378
sourceTree = "<group>";
375379
};
380+
267C2EFB273DDB3B00F464B0 /* StepsSettingsSheet */ = {
381+
isa = PBXGroup;
382+
children = (
383+
267C2EF9273DB62800F464B0 /* StepsSettingsSheet.swift */,
384+
267C2EFC273DDB5500F464B0 /* StepSettingsGoalChange.swift */,
385+
267C2EFE273DDBFF00F464B0 /* StepSettingsDatePicker.swift */,
386+
);
387+
path = StepsSettingsSheet;
388+
sourceTree = "<group>";
389+
};
376390
268E773D27174B6D000DF90D /* ChartSettingsSheet */ = {
377391
isa = PBXGroup;
378392
children = (
@@ -451,7 +465,7 @@
451465
26A40E842704E6F3007966F6 /* SheetManager.swift */,
452466
268E773D27174B6D000DF90D /* ChartSettingsSheet */,
453467
26C5FAD726FC129400921207 /* ArbitraryNotificationView.swift */,
454-
267C2EF9273DB62800F464B0 /* StepsSettingsSheet.swift */,
468+
267C2EFB273DDB3B00F464B0 /* StepsSettingsSheet */,
455469
26C5FAE226FEB0A400921207 /* DFUDownloadView.swift */,
456470
26C5FADB26FE7EB000921207 /* SheetCloseButton.swift */,
457471
2617EF3A27036D9100FE6F48 /* What's New */,
@@ -641,6 +655,7 @@
641655
26F426EF26C72D7D00D0866B /* ChartView.swift in Sources */,
642656
266F53E426F7FCA6007481A6 /* ChartManager.swift in Sources */,
643657
268E773C27174A2B000DF90D /* ChartSettingsSheetMain.swift in Sources */,
658+
267C2EFF273DDBFF00F464B0 /* StepSettingsDatePicker.swift in Sources */,
644659
26B2BAF726F139D600FBC9CE /* DebugView.swift in Sources */,
645660
26A40E912707C7A3007966F6 /* BLEDiscoveredCharacteristics.swift in Sources */,
646661
264BFE7426BC526C0050A223 /* BLEManager.swift in Sources */,
@@ -678,6 +693,7 @@
678693
26A6316326C4C6D6005AE404 /* BLEConnectView.swift in Sources */,
679694
2617EF37270364CE00FE6F48 /* ChartViewSelector.swift in Sources */,
680695
26A40E8D2704EB32007966F6 /* DebugViewApp.swift in Sources */,
696+
267C2EFD273DDB5500F464B0 /* StepSettingsGoalChange.swift in Sources */,
681697
26D7816526C9EB3800BBF555 /* BLEDelegates.swift in Sources */,
682698
267C2EF8273C8AB300F464B0 /* StepWeeklyGraph.swift in Sources */,
683699
26C5FAD526FBB76100921207 /* DeviceNameManager.swift in Sources */,

InfiniLink/Utilities/StepCountPersistenceManager.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010
import CoreData
1111
import SwiftUI
1212

13-
class StepCountPersistenceManager: ObservableObject {
14-
static let shared = StepCountPersistenceManager()
15-
@Published var currentCount: Int32 = 0
13+
struct StepCountPersistenceManager {
1614
let viewContext = PersistenceController.shared.container.viewContext
1715

18-
init() {
19-
retrieveStepCount(date: Date())
20-
}
21-
2216
func lookupStepCounts(write: Bool) -> [StepCounts] {
2317
var existingCounts: [StepCounts] = []
2418
let request = NSFetchRequest<StepCounts>(entityName: "StepCounts")
@@ -30,15 +24,6 @@ class StepCountPersistenceManager: ObservableObject {
3024
return existingCounts
3125
}
3226

33-
func retrieveStepCount(date: Date) {
34-
let existingCounts = lookupStepCounts(write: true)
35-
for i in existingCounts {
36-
if Calendar.current.isDate(i.timestamp!, inSameDayAs: date) {
37-
currentCount = i.steps
38-
}
39-
}
40-
}
41-
4227
func setStepCount(steps: Int, arbitrary: Bool, date: Date) {
4328
let existingCounts = lookupStepCounts(write: true)
4429

@@ -76,7 +61,6 @@ class StepCountPersistenceManager: ObservableObject {
7661
} catch {
7762
DebugLogManager.shared.debug(error: "Couldn't save step count: \(error)", log: .app, date: Date())
7863
}
79-
retrieveStepCount(date: Date())
8064
}
8165

8266
func saveNewStepCount(steps: Int, date: Date) {
@@ -88,6 +72,5 @@ class StepCountPersistenceManager: ObservableObject {
8872
} catch {
8973
DebugLogManager.shared.debug(error: "Couldn't save step count: \(error)", log: .app, date: Date())
9074
}
91-
retrieveStepCount(date: Date())
9275
}
9376
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// StepSettingsDatePicker.swift
3+
// InfiniLink
4+
//
5+
// Created by Alex Emry on 11/11/21.
6+
//
7+
//
8+
9+
10+
import SwiftUI
11+
12+
struct StepSettingsSheetDatePicker: View {
13+
@ObservedObject var addDateValue = NumbersOnly()
14+
@State var selectedDate: Date = Date()
15+
16+
func readyToSubmit(value: String) -> Bool {
17+
if value == "" {
18+
return true
19+
} else {
20+
return false
21+
}
22+
}
23+
24+
var body: some View {
25+
Text("Manually Add Step Count")
26+
.font(.title)
27+
.padding()
28+
DatePicker("Select Date", selection: $selectedDate, displayedComponents: [.date])
29+
.padding()
30+
TextField("Number of Steps", text: $addDateValue.value)
31+
.padding()
32+
.keyboardType(.decimalPad)
33+
Button {
34+
StepCountPersistenceManager().setStepCount(steps: Int(addDateValue.value)!, arbitrary: true, date: selectedDate)
35+
} label: {
36+
Text("Submit Count")
37+
}.disabled(readyToSubmit(value: addDateValue.value))
38+
.padding()
39+
}
40+
}
41+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// StepSettingsGoalChange.swift
3+
// InfiniLink
4+
//
5+
// Created by Alex Emry on 11/11/21.
6+
//
7+
//
8+
9+
10+
import SwiftUI
11+
12+
struct StepSettingsSheetGoalChange: View {
13+
@ObservedObject var setStepGoal = NumbersOnly()
14+
@AppStorage("stepCountGoal") var stepCountGoal = 10000
15+
16+
func readyToSubmit(value: String) -> Bool {
17+
if value == "" {
18+
return true
19+
} else {
20+
return false
21+
}
22+
}
23+
24+
var body: some View {
25+
Text("Change Step Count Goal")
26+
.font(.title)
27+
.padding()
28+
TextField("Step Goal", text: $setStepGoal.value)
29+
.padding()
30+
.keyboardType(.decimalPad)
31+
Button {
32+
stepCountGoal = Int(setStepGoal.value)!
33+
} label: {
34+
Text("Submit New Step Goal")
35+
}.disabled(readyToSubmit(value: setStepGoal.value))
36+
.padding()
37+
}
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// StepsSettingsSheet.swift
3+
// InfiniLink
4+
//
5+
// Created by Alex Emry on 11/11/21.
6+
//
7+
//
8+
9+
10+
import SwiftUI
11+
12+
struct StepSettingsSheet: View {
13+
14+
var body: some View {
15+
VStack (alignment: .leading) {
16+
SheetCloseButton()
17+
Text("Step Count Settings")
18+
.font(.largeTitle)
19+
.padding()
20+
.padding(.bottom, 20)
21+
StepSettingsSheetGoalChange()
22+
Divider()
23+
.padding()
24+
StepSettingsSheetDatePicker()
25+
Spacer()
26+
}
27+
}
28+
}
29+
30+
class NumbersOnly: ObservableObject {
31+
@Published var value = "" {
32+
didSet {
33+
let filtered = value.filter { $0.isNumber }
34+
35+
if value != filtered {
36+
value = filtered
37+
}
38+
}
39+
}
40+
}

InfiniLink/View Components/Steps View Components/StepCalendar/StepCalendarView.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ struct StepCalendarView: View {
1414

1515
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \StepCounts.timestamp, ascending: true)])
1616
private var existingStepCounts: FetchedResults<StepCounts>
17-
18-
@Binding var currentPercentage: Float
1917
@Binding var stepCountGoal: Int
2018

2119
private var year: DateInterval {

InfiniLink/View Components/Steps View Components/StepProgressGauge.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ struct StepProgressGauge: View {
1313
@ObservedObject var bleManager = BLEManager.shared
1414
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \StepCounts.timestamp, ascending: true)])
1515
private var existingStepCounts: FetchedResults<StepCounts>
16-
@Binding var currentPercentage: Float
1716
@Binding var stepCountGoal: Int
1817
var calendar: Bool
1918
@State var backgroundColor = Color.clear

InfiniLink/View Components/StepsView.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import SwiftUI
1212
struct StepsView: View {
1313

1414
@ObservedObject var bleManager = BLEManager.shared
15-
@ObservedObject var stepManager = StepCountPersistenceManager.shared
1615
@Environment(\.colorScheme) var colorScheme
1716
@AppStorage("stepCountGoal") var stepCountGoal = 10000
1817
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \StepCounts.timestamp, ascending: true)])
1918
private var chartPoints: FetchedResults<StepCounts>
20-
@State var stepGoalPercentage: Float = 0.0
2119
@State var selection: Int = 2
2220

2321
var body: some View {
@@ -48,7 +46,7 @@ struct StepsView: View {
4846
}
4947
.padding(.top)
5048
.tag(1)
51-
StepProgressGauge(currentPercentage: $stepGoalPercentage, stepCountGoal: $stepCountGoal, calendar: false)
49+
StepProgressGauge(stepCountGoal: $stepCountGoal, calendar: false)
5250
.padding()
5351
.frame(width: (g.size.width / 1.3), height: (g.size.width / 1.3), alignment: .center)
5452
.tabItem {
@@ -57,7 +55,7 @@ struct StepsView: View {
5755
}
5856
.padding(.top)
5957
.tag(2)
60-
StepCalendarView(currentPercentage: $stepGoalPercentage, stepCountGoal: $stepCountGoal)
58+
StepCalendarView(stepCountGoal: $stepCountGoal)
6159
.padding()
6260
.frame(alignment: .init(horizontal: .center, vertical: .top))
6361
.tabItem {
@@ -67,15 +65,6 @@ struct StepsView: View {
6765
.padding(.top)
6866
.tag(3)
6967
}
70-
.onChange(of: stepManager.currentCount) { _ in
71-
stepGoalPercentage = (Float(stepManager.currentCount)/Float(stepCountGoal))
72-
}
73-
.onChange(of: stepCountGoal) { _ in
74-
stepGoalPercentage = (Float(stepManager.currentCount)/Float(stepCountGoal))
75-
}
76-
.onAppear {
77-
stepGoalPercentage = (Float(stepManager.currentCount)/Float(stepCountGoal))
78-
}
7968
}
8069
}
8170
}

0 commit comments

Comments
 (0)