Skip to content

Commit 9561cb2

Browse files
committed
Refactored chart display method so it doesn't rely on a cascading tree of bools. Polish and bug fixes.
Version 0.9.0 is complete!
1 parent 518af75 commit 9561cb2

10 files changed

Lines changed: 59 additions & 43 deletions

File tree

Infini-iOS.xcodeproj/project.pbxproj

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
2617EF37270364CE00FE6F48 /* ChartViewSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2617EF36270364CE00FE6F48 /* ChartViewSelector.swift */; };
1011
26318B1626CB27E70036051E /* Infini_iOS.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 26318B1426CB27E70036051E /* Infini_iOS.xcdatamodeld */; };
1112
2632388426F2531C00D72B43 /* DFUWithBLE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2632388326F2531C00D72B43 /* DFUWithBLE.swift */; };
1213
2632388626F2548600D72B43 /* DFUWithoutBLE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2632388526F2548600D72B43 /* DFUWithoutBLE.swift */; };
@@ -59,7 +60,7 @@
5960
26D7816E26CA003B00BBF555 /* SettingsFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26D7816D26CA003B00BBF555 /* SettingsFunctions.swift */; };
6061
26D7817026CA004B00BBF555 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26D7816F26CA004B00BBF555 /* SettingsView.swift */; };
6162
26D7817A26CAD19F00BBF555 /* ColorPalette.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26D7817926CAD19F00BBF555 /* ColorPalette.swift */; };
62-
26F426EF26C72D7D00D0866B /* BLEStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F426EE26C72D7D00D0866B /* BLEStatusView.swift */; };
63+
26F426EF26C72D7D00D0866B /* ChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F426EE26C72D7D00D0866B /* ChartView.swift */; };
6364
/* End PBXBuildFile section */
6465

6566
/* Begin PBXContainerItemProxy section */
@@ -80,6 +81,7 @@
8081
/* End PBXContainerItemProxy section */
8182

8283
/* Begin PBXFileReference section */
84+
2617EF36270364CE00FE6F48 /* ChartViewSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewSelector.swift; sourceTree = "<group>"; };
8385
26318B1526CB27E70036051E /* Infini_iOS.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Infini_iOS.xcdatamodel; sourceTree = "<group>"; };
8486
2632388326F2531C00D72B43 /* DFUWithBLE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUWithBLE.swift; sourceTree = "<group>"; };
8587
2632388526F2548600D72B43 /* DFUWithoutBLE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUWithoutBLE.swift; sourceTree = "<group>"; };
@@ -137,7 +139,7 @@
137139
26D7816D26CA003B00BBF555 /* SettingsFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsFunctions.swift; sourceTree = "<group>"; };
138140
26D7816F26CA004B00BBF555 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
139141
26D7817926CAD19F00BBF555 /* ColorPalette.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPalette.swift; sourceTree = "<group>"; };
140-
26F426EE26C72D7D00D0866B /* BLEStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEStatusView.swift; sourceTree = "<group>"; };
142+
26F426EE26C72D7D00D0866B /* ChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartView.swift; sourceTree = "<group>"; };
141143
/* End PBXFileReference section */
142144

143145
/* Begin PBXFrameworksBuildPhase section */
@@ -177,16 +179,17 @@
177179
path = Onboarding;
178180
sourceTree = "<group>";
179181
};
180-
263B20B626CD673D00676BF0 /* Status View Components */ = {
182+
263B20B626CD673D00676BF0 /* Chart View Components */ = {
181183
isa = PBXGroup;
182184
children = (
183185
266F53EB26FAABE7007481A6 /* TimeRangeTabs.swift */,
184186
263B20B426CD673900676BF0 /* ChartTabs.swift */,
185187
263B20B926CDF13400676BF0 /* HeartChart.swift */,
186188
263B20BB26CDF20400676BF0 /* BatteryChart.swift */,
187189
266F53E326F7FCA6007481A6 /* ChartManager.swift */,
190+
2617EF36270364CE00FE6F48 /* ChartViewSelector.swift */,
188191
);
189-
path = "Status View Components";
192+
path = "Chart View Components";
190193
sourceTree = "<group>";
191194
};
192195
263B20C826CF07BE00676BF0 /* DFU View */ = {
@@ -277,12 +280,12 @@
277280
2632388B26F265B100D72B43 /* MainView.swift */,
278281
266F53E526FA7676007481A6 /* HomeScreen.swift */,
279282
264DB80A26C62ED600E812C3 /* SideMenu.swift */,
280-
26F426EE26C72D7D00D0866B /* BLEStatusView.swift */,
283+
26F426EE26C72D7D00D0866B /* ChartView.swift */,
281284
26D7816F26CA004B00BBF555 /* SettingsView.swift */,
282285
26C5FAD626FC126F00921207 /* Sheets */,
283286
263B20C826CF07BE00676BF0 /* DFU View */,
284287
2675CA5826DC5C9400967E4D /* View Utilities */,
285-
263B20B626CD673D00676BF0 /* Status View Components */,
288+
263B20B626CD673D00676BF0 /* Chart View Components */,
286289
);
287290
path = "View Components";
288291
sourceTree = "<group>";
@@ -510,7 +513,7 @@
510513
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */,
511514
2632388C26F265B100D72B43 /* MainView.swift in Sources */,
512515
2632388826F2576D00D72B43 /* DFUFileSelectButton.swift in Sources */,
513-
26F426EF26C72D7D00D0866B /* BLEStatusView.swift in Sources */,
516+
26F426EF26C72D7D00D0866B /* ChartView.swift in Sources */,
514517
266F53E426F7FCA6007481A6 /* ChartManager.swift in Sources */,
515518
264BFE7426BC526C0050A223 /* BLEManager.swift in Sources */,
516519
2632388E26F297CB00D72B43 /* OnboardingBody.swift in Sources */,
@@ -538,6 +541,7 @@
538541
263B20B526CD673900676BF0 /* ChartTabs.swift in Sources */,
539542
26D7816E26CA003B00BBF555 /* SettingsFunctions.swift in Sources */,
540543
26A6316326C4C6D6005AE404 /* BLEConnectView.swift in Sources */,
544+
2617EF37270364CE00FE6F48 /* ChartViewSelector.swift in Sources */,
541545
26D7816526C9EB3800BBF555 /* BLEDelegates.swift in Sources */,
542546
26C5FAD526FBB76100921207 /* DeviceNameManager.swift in Sources */,
543547
26A6315B26C49841005AE404 /* DFU.swift in Sources */,
@@ -709,7 +713,7 @@
709713
"$(inherited)",
710714
"@executable_path/Frameworks",
711715
);
712-
MARKETING_VERSION = 0.8.5;
716+
MARKETING_VERSION = 0.9.0;
713717
PRODUCT_BUNDLE_IDENTIFIER = "com.alexemry.Infini-iOS";
714718
PRODUCT_NAME = "$(TARGET_NAME)";
715719
SWIFT_VERSION = 5.0;
@@ -732,7 +736,7 @@
732736
"$(inherited)",
733737
"@executable_path/Frameworks",
734738
);
735-
MARKETING_VERSION = 0.8.5;
739+
MARKETING_VERSION = 0.9.0;
736740
PRODUCT_BUNDLE_IDENTIFIER = "com.alexemry.Infini-iOS";
737741
PRODUCT_NAME = "$(TARGET_NAME)";
738742
SWIFT_VERSION = 5.0;

Infini-iOS/View Components/Status View Components/BatteryChart.swift renamed to Infini-iOS/View Components/Chart View Components/BatteryChart.swift

File renamed without changes.

Infini-iOS/View Components/Status View Components/ChartManager.swift renamed to Infini-iOS/View Components/Chart View Components/ChartManager.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ class ChartManager: ObservableObject {
3434
case hour
3535
case day
3636
case week
37-
case all
37+
//case all
38+
}
39+
40+
enum chartSelection {
41+
case heart
42+
case battery
3843
}
3944

4045
enum DateValue: Double {
@@ -43,7 +48,8 @@ class ChartManager: ObservableObject {
4348
case week = -604800
4449
}
4550

46-
@Published var dateRange: DateRange = .all
51+
@Published var dateRange: DateRange = .day//.all
52+
@Published var currentChart: chartSelection = .battery
4753

4854
let viewContext = PersistenceController.shared.container.viewContext
4955

@@ -93,8 +99,8 @@ class ChartManager: ObservableObject {
9399
dateValue = -86400
94100
case .week:
95101
dateValue = -604800
96-
case .all:
97-
dateValue = 0
102+
// case .all:
103+
// dateValue = 0
98104
}
99105
return dateValue
100106
}

Infini-iOS/View Components/Status View Components/ChartTabs.swift renamed to Infini-iOS/View Components/Chart View Components/ChartTabs.swift

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ struct StatusTabs: View {
2121
VStack {
2222
HStack {
2323
Button (action: {
24-
chartManager.trueIfHeart = true
25-
chartManager.trueIfBat = false
26-
lastStatusViewWasHeart = true
24+
chartManager.currentChart = .heart
2725
}) {
2826
(Text(Image(systemName: "heart"))
2927
.foregroundColor(Color.pink) +
@@ -34,41 +32,25 @@ struct StatusTabs: View {
3432
.font(.body))
3533
.frame(maxWidth:.infinity, alignment: .center)
3634
.padding()
37-
.background(colorScheme == .dark ? (chartManager.trueIfHeart ? Color.darkGray : Color.darkestGray) : (chartManager.trueIfHeart ? Color.gray : Color.lightGray))
35+
.background(colorScheme == .dark ? (chartManager.currentChart == .heart ? Color.darkGray : Color.darkestGray) : (chartManager.currentChart == .heart ? Color.gray : Color.lightGray))
3836
.cornerRadius(5)
3937
.font(.title)
4038
}.padding(.leading, 10)
4139
Button (action: {
42-
chartManager.trueIfHeart = false
43-
chartManager.trueIfBat = true
44-
lastStatusViewWasHeart = false
40+
chartManager.currentChart = .battery
4541
}) {
4642
(Text(Image(systemName: "battery.100"))
4743
.foregroundColor(Color.green) +
4844
Text(": " + String(format: "%.0f", bleManager.batteryLevel) + "%")
4945
.foregroundColor(Color.white))
5046
.frame(maxWidth: .infinity, alignment: .center)
5147
.padding()
52-
.background(colorScheme == .dark ? (chartManager.trueIfBat ? Color.darkGray : Color.darkestGray) : (chartManager.trueIfBat ? Color.gray : Color.lightGray))
48+
.background(colorScheme == .dark ? (chartManager.currentChart == .battery ? Color.darkGray : Color.darkestGray) : (chartManager.currentChart == .battery ? Color.gray : Color.lightGray))
5349
.cornerRadius(5)
5450
.font(.title)
5551
}
5652
.padding(.trailing, 10)
5753
}
58-
if lastStatusViewWasHeart {
59-
HeartChart()
60-
.onAppear() {
61-
chartManager.trueIfHeart = true
62-
chartManager.trueIfBat = false
63-
}
64-
} else {
65-
BatteryChart()
66-
.onAppear() {
67-
chartManager.trueIfHeart = false
68-
chartManager.trueIfBat = true
69-
}
70-
}
7154
}
72-
7355
}
7456
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// ChartViewSelector.swift
3+
// Infini-iOS
4+
//
5+
// Created by Alex Emry on 9/28/21.
6+
//
7+
//
8+
9+
10+
import Foundation
11+
import SwiftUI
12+
13+
struct CurrentChart: View {
14+
@ObservedObject var chartManager = ChartManager.shared
15+
16+
var body: some View {
17+
switch chartManager.currentChart {
18+
case .heart:
19+
HeartChart()
20+
case .battery:
21+
BatteryChart()
22+
}
23+
}
24+
}

Infini-iOS/View Components/Status View Components/HeartChart.swift renamed to Infini-iOS/View Components/Chart View Components/HeartChart.swift

File renamed without changes.

Infini-iOS/View Components/Status View Components/TimeRangeTabs.swift renamed to Infini-iOS/View Components/Chart View Components/TimeRangeTabs.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ struct TimeRangeTabs: View {
2525
@ObservedObject var bleManager = BLEManager.shared
2626
@ObservedObject var chartManager = ChartManager.shared
2727
@Environment(\.colorScheme) var colorScheme
28-
@AppStorage("lastStatusViewWasHeart") var lastStatusViewWasHeart: Bool = false
2928

3029
var body: some View{
3130
HStack {
@@ -55,7 +54,7 @@ struct TimeRangeTabs: View {
5554
.cornerRadius(5)
5655
.font(.title)
5756
}
58-
.padding(.horizontal, 3)
57+
//.padding(.horizontal, 1)
5958

6059
// set date range to last week
6160
Button (action: {

Infini-iOS/View Components/BLEStatusView.swift renamed to Infini-iOS/View Components/ChartView.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import SwiftUI
1010

11-
struct StatusView: View {
11+
struct ChartView: View {
1212

1313
@ObservedObject var bleManager = BLEManager.shared
1414
@Environment(\.colorScheme) var colorScheme
@@ -20,14 +20,15 @@ struct StatusView: View {
2020
.padding()
2121
.frame(maxWidth: .infinity, alignment: .leading)
2222
TimeRangeTabs()
23-
StatusTabs().environmentObject(bleManager)
23+
StatusTabs()
24+
CurrentChart()
2425
}
2526
}
2627
}
2728

28-
struct StatusView_Previews: PreviewProvider {
29+
struct ChartView_Previews: PreviewProvider {
2930
static var previews: some View {
30-
StatusView()
31+
ChartView()
3132
.environmentObject(PageSwitcher())
3233
.environmentObject(BLEManager())
3334
}

Infini-iOS/View Components/MainView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct MainView: View {
2121
case .dfu:
2222
DFUView()
2323
case .status:
24-
StatusView()
24+
ChartView()
2525
case .settings:
2626
Settings_Page()
2727
case .home:

Infini-iOS/View Components/SettingsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct Settings_Page: View {
6262
}
6363
}
6464

65-
Section(header: Text("Firmware Updates")) {
65+
Section(header: Text("Firmware Update Downloads")) {
6666
Toggle("Show Newer Versions Only", isOn: $showNewDownloadsOnly)
6767
}
6868

0 commit comments

Comments
 (0)