Skip to content

Commit

Permalink
Added onboarding/what's new handler to select the proper sheet to pul…
Browse files Browse the repository at this point in the history
…l up at open, and added what's new notes for this release. Added some logic so that the Connect screen doesn't start the scan until BLE is turned on.
  • Loading branch information
xan-m committed Sep 28, 2021
1 parent 9561cb2 commit 9918922
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 41 deletions.
16 changes: 16 additions & 0 deletions Infini-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
2617EF37270364CE00FE6F48 /* ChartViewSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2617EF36270364CE00FE6F48 /* ChartViewSelector.swift */; };
2617EF3927036C9B00FE6F48 /* WhatsNewSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2617EF3827036C9B00FE6F48 /* WhatsNewSheet.swift */; };
2617EF3D27036DC600FE6F48 /* WhatsNewBody090.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2617EF3C27036DC600FE6F48 /* WhatsNewBody090.swift */; };
26318B1626CB27E70036051E /* Infini_iOS.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 26318B1426CB27E70036051E /* Infini_iOS.xcdatamodeld */; };
2632388426F2531C00D72B43 /* DFUWithBLE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2632388326F2531C00D72B43 /* DFUWithBLE.swift */; };
2632388626F2548600D72B43 /* DFUWithoutBLE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2632388526F2548600D72B43 /* DFUWithoutBLE.swift */; };
Expand Down Expand Up @@ -82,6 +84,8 @@

/* Begin PBXFileReference section */
2617EF36270364CE00FE6F48 /* ChartViewSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewSelector.swift; sourceTree = "<group>"; };
2617EF3827036C9B00FE6F48 /* WhatsNewSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatsNewSheet.swift; sourceTree = "<group>"; };
2617EF3C27036DC600FE6F48 /* WhatsNewBody090.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatsNewBody090.swift; sourceTree = "<group>"; };
26318B1526CB27E70036051E /* Infini_iOS.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Infini_iOS.xcdatamodel; sourceTree = "<group>"; };
2632388326F2531C00D72B43 /* DFUWithBLE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUWithBLE.swift; sourceTree = "<group>"; };
2632388526F2548600D72B43 /* DFUWithoutBLE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUWithoutBLE.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +173,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
2617EF3A27036D9100FE6F48 /* What's New */ = {
isa = PBXGroup;
children = (
2617EF3827036C9B00FE6F48 /* WhatsNewSheet.swift */,
2617EF3C27036DC600FE6F48 /* WhatsNewBody090.swift */,
);
path = "What's New";
sourceTree = "<group>";
};
2632389326F29A4100D72B43 /* Onboarding */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -338,6 +351,7 @@
26C5FAD726FC129400921207 /* ArbitraryNotificationView.swift */,
26C5FAE226FEB0A400921207 /* DFUDownloadView.swift */,
26C5FADB26FE7EB000921207 /* SheetCloseButton.swift */,
2617EF3A27036D9100FE6F48 /* What's New */,
2632389326F29A4100D72B43 /* Onboarding */,
);
path = Sheets;
Expand Down Expand Up @@ -508,6 +522,7 @@
26A6315526C0297A005AE404 /* BLEWriteManager.swift in Sources */,
26C5FAE126FE98F500921207 /* BLEAutoconnectManager.swift in Sources */,
26A6316026C4BC25005AE404 /* DFUView.swift in Sources */,
2617EF3927036C9B00FE6F48 /* WhatsNewSheet.swift in Sources */,
2632389026F2980A00D72B43 /* OnboardingDismissButton.swift in Sources */,
264AE04627026BD6001504A7 /* UptimeManager.swift in Sources */,
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */,
Expand All @@ -529,6 +544,7 @@
26318B1626CB27E70036051E /* Infini_iOS.xcdatamodeld in Sources */,
266F53EC26FAABE7007481A6 /* TimeRangeTabs.swift in Sources */,
26C5FAD826FC129400921207 /* ArbitraryNotificationView.swift in Sources */,
2617EF3D27036DC600FE6F48 /* WhatsNewBody090.swift in Sources */,
264BFE7626BC52720050A223 /* HexStringToData.swift in Sources */,
2632388626F2548600D72B43 /* DFUWithoutBLE.swift in Sources */,
26C5FADC26FE7EB000921207 /* SheetCloseButton.swift in Sources */,
Expand Down
34 changes: 20 additions & 14 deletions Infini-iOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ struct ContentView: View {
@AppStorage("autoconnect") var autoconnect: Bool = false
@AppStorage("autoconnectUUID") var autoconnectUUID: String = ""
@AppStorage("batteryNotification") var batteryNotification: Bool = false
@AppStorage("onboarding") var onboarding: Bool = true
@AppStorage("onboarding") var onboarding: Bool!// = false
@AppStorage("lastVersion") var lastVersion: String = ""
let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""


init() {
Expand Down Expand Up @@ -60,10 +62,11 @@ struct ContentView: View {
.sheet(isPresented: $sheetManager.showSheet, content: {
SheetManager.CurrentSheet()
.onDisappear {
if onboarding {
onboarding = false
sheetManager.sheetSelection = .connect
SheetManager.shared.showSheet = true
if !sheetManager.upToDate {
if onboarding == nil {
onboarding = false
}
sheetManager.setNextSheet()
}
}
})
Expand Down Expand Up @@ -96,15 +99,18 @@ struct ContentView: View {
self.bleManager.startScanning()
}

if onboarding {
SheetManager.shared.sheetSelection = .onboarding
SheetManager.shared.showSheet = true
}

if (autoconnect && autoconnectUUID.isEmpty) || (!autoconnect && !bleManager.isConnectedToPinetime) && !onboarding {
SheetManager.shared.sheetSelection = .connect
SheetManager.shared.showSheet = true
}
sheetManager.setNextSheet()
sheetManager.showSheet = true
//
// if onboarding {
// SheetManager.shared.sheetSelection = .onboarding
// SheetManager.shared.showSheet = true
// }
//
// if (autoconnect && autoconnectUUID.isEmpty) || (!autoconnect && !bleManager.isConnectedToPinetime) && !onboarding {
// SheetManager.shared.sheetSelection = .connect
// SheetManager.shared.showSheet = true
// }
})
}
}
Expand Down
27 changes: 15 additions & 12 deletions Infini-iOS/View Components/Chart View Components/ChartManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ struct DataPoint {

class ChartManager: ObservableObject {

@Published var dateRange: DateRange = .day
@Published var currentChart: chartSelection = .battery
var lastChartWasHeart = UserDefaults.standard.value(forKey: "lastStatusViewWasHeart") as? Bool ?? false

let viewContext = PersistenceController.shared.container.viewContext

static let shared = ChartManager()
private init() {}

private init() {
if lastChartWasHeart {
currentChart = .heart
} else {
currentChart = .battery
}
}

@Published var trueIfHeart = true
@Published var trueIfBat = false
Expand All @@ -48,10 +61,7 @@ class ChartManager: ObservableObject {
case week = -604800
}

@Published var dateRange: DateRange = .day//.all
@Published var currentChart: chartSelection = .battery

let viewContext = PersistenceController.shared.container.viewContext


func addItem(dataPoint: DataPoint) {
let newItem = ChartDataPoint(context: viewContext)
Expand Down Expand Up @@ -99,8 +109,6 @@ class ChartManager: ObservableObject {
dateValue = -86400
case .week:
dateValue = -604800
// case .all:
// dateValue = 0
}
return dateValue
}
Expand All @@ -119,9 +127,4 @@ class ChartManager: ObservableObject {
}
return dataPoints
}

func filterDates(results: FetchedResults<ChartDataPoint>) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct StatusTabs: View {
HStack {
Button (action: {
chartManager.currentChart = .heart
lastStatusViewWasHeart = true
}) {
(Text(Image(systemName: "heart"))
.foregroundColor(Color.pink) +
Expand All @@ -32,20 +33,23 @@ struct StatusTabs: View {
.font(.body))
.frame(maxWidth:.infinity, alignment: .center)
.padding()
.background(colorScheme == .dark ? (chartManager.currentChart == .heart ? Color.darkGray : Color.darkestGray) : (chartManager.currentChart == .heart ? Color.gray : Color.lightGray))
.background(colorScheme == .dark ? (chartManager.currentChart == .heart ? Color.darkGray : Color.darkestGray) : Color.blue)
.opacity(colorScheme == .dark ? 1.0 : (chartManager.currentChart == .heart ? 1.0 : 0.3))
.cornerRadius(5)
.font(.title)
}.padding(.leading, 10)
Button (action: {
chartManager.currentChart = .battery
lastStatusViewWasHeart = false
}) {
(Text(Image(systemName: "battery.100"))
.foregroundColor(Color.green) +
Text(": " + String(format: "%.0f", bleManager.batteryLevel) + "%")
.foregroundColor(Color.white))
.frame(maxWidth: .infinity, alignment: .center)
.padding()
.background(colorScheme == .dark ? (chartManager.currentChart == .battery ? Color.darkGray : Color.darkestGray) : (chartManager.currentChart == .battery ? Color.gray : Color.lightGray))
.background(colorScheme == .dark ? (chartManager.currentChart == .battery ? Color.darkGray : Color.darkestGray) : Color.blue)
.opacity(colorScheme == .dark ? 1.0 : (chartManager.currentChart == .battery ? 1.0 : 0.3))
.cornerRadius(5)
.font(.title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct TimeRangeTabs: View {
.foregroundColor(Color.white))
.frame(maxWidth: .infinity, alignment: .center)
.padding()
.background(colorScheme == .dark ? (chartManager.dateRange == .hour ? Color.darkGray : Color.darkestGray) : (chartManager.dateRange == .hour ? Color.gray : Color.lightGray))
.background(colorScheme == .dark ? (chartManager.dateRange == .hour ? Color.darkGray : Color.darkestGray) : (Color.blue))
.opacity(colorScheme == .dark ? 1.0 : (chartManager.dateRange == .hour ? 1.0 : 0.3))
.cornerRadius(5)
.font(.title)
}
Expand All @@ -50,7 +51,8 @@ struct TimeRangeTabs: View {
.foregroundColor(Color.white))
.frame(maxWidth: .infinity, alignment: .center)
.padding()
.background(colorScheme == .dark ? (chartManager.dateRange == .day ? Color.darkGray : Color.darkestGray) : (chartManager.dateRange == .day ? Color.gray : Color.lightGray))
.background(colorScheme == .dark ? (chartManager.dateRange == .day ? Color.darkGray : Color.darkestGray) : (Color.blue))
.opacity(colorScheme == .dark ? 1.0 : (chartManager.dateRange == .day ? 1.0 : 0.3))
.cornerRadius(5)
.font(.title)
}
Expand All @@ -64,7 +66,8 @@ struct TimeRangeTabs: View {
.foregroundColor(Color.white))
.frame(maxWidth: .infinity, alignment: .center)
.padding()
.background(colorScheme == .dark ? (chartManager.dateRange == .week ? Color.darkGray : Color.darkestGray) : (chartManager.dateRange == .week ? Color.gray : Color.lightGray))
.background(colorScheme == .dark ? (chartManager.dateRange == .week ? Color.darkGray : Color.darkestGray) : (Color.blue))
.opacity(colorScheme == .dark ? 1.0 : (chartManager.dateRange == .week ? 1.0 : 0.3))
.cornerRadius(5)
.font(.title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct DFUStartTransferButton: View {
dfuUpdater.firmwareSelected = false
dfuUpdater.firmwareFilename = ""
} else {
dfuUpdater.percentComplete = 0
if dfuUpdater.local {
dfuUpdater.transfer()
updateStarted = true
Expand Down
17 changes: 17 additions & 0 deletions Infini-iOS/View Components/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ struct Settings_Page: View {
(Text("Clear All Battery Chart Data"))
}
}

Section(header: Text("Onboarding Information")) {

Button {
SheetManager.shared.sheetSelection = .onboarding
SheetManager.shared.showSheet = true
} label: {
Text("Open Onboarding Page")
}
Button {
SheetManager.shared.sheetSelection = .whatsNew
SheetManager.shared.showSheet = true
} label: {
Text("Open 'What's New' Page for This Version")
}
}

Section(header: Text("Links")) {
Link("Infini-iOS GitHub", destination: URL(string: "https://github.com/xan-m/Infini-iOS")!)
Link("Matrix", destination: URL(string: "https://matrix.to/#/@xanm:matrix.org")!)
Expand Down
25 changes: 18 additions & 7 deletions Infini-iOS/View Components/Sheets/BLEConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ struct Connect: View {
var body: some View {
SheetCloseButton()
VStack (){
Text("Available Devices")
.font(.largeTitle)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.onAppear {
bleManager.startScanning()
}
if bleManager.isSwitchedOn {
Text("Available Devices")
.font(.largeTitle)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.onAppear {
bleManager.startScanning()
}
} else {
Text("Available Devices")
.font(.largeTitle)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
Text("Waiting for Bluetooth")
.font(.title)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
List(bleManager.peripherals) { peripheral in
let deviceName = DeviceNameManager.init().getName(deviceUUID: peripheral.stringUUID)
HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//


import Foundation

import SwiftUI

struct OnboardingBody: View {
Expand Down
47 changes: 47 additions & 0 deletions Infini-iOS/View Components/Sheets/SheetManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,58 @@ enum SheetSelection {
case connect
case notification
case downloadUpdate
case whatsNew
}

class SheetManager: ObservableObject {
static let shared = SheetManager()

@Published var showSheet: Bool = false
@Published var sheetSelection: SheetSelection = .connect
@Published var upToDate: Bool = false

private var whatsNew: Bool = true

let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
var lastVersion = UserDefaults.standard.value(forKey: "lastVersion") as? String ?? ""

func showWhatsNew () -> Bool {
if !whatsNew {
return false
} else {
var showSheet = false

print("before: ", lastVersion, " <last | current> ", currentVersion)
if lastVersion == "" {
lastVersion = "0.0.0"
}

let comparison = currentVersion.compare(lastVersion, options: .numeric)
if comparison == .orderedDescending {
showSheet = true
}
lastVersion = currentVersion
whatsNew = false

print(showSheet)
return showSheet
}
}

func setNextSheet() {
let onboarding = UserDefaults.standard.value(forKey: "onboarding")// as? Bool ?? true
if onboarding == nil {
SheetManager.shared.sheetSelection = .onboarding
SheetManager.shared.showSheet = true
} else if SheetManager.shared.showWhatsNew() {
SheetManager.shared.sheetSelection = .whatsNew
SheetManager.shared.showSheet = true
} else {
SheetManager.shared.sheetSelection = .connect
SheetManager.shared.showSheet = true
SheetManager.shared.upToDate = true
}
}

struct CurrentSheet: View {
var body: some View {
Expand All @@ -34,6 +79,8 @@ class SheetManager: ObservableObject {
ArbitraryNotificationSheet()
case .downloadUpdate:
DownloadView()
case .whatsNew:
WhatsNew()
}
}
}
Expand Down
Loading

0 comments on commit 9918922

Please sign in to comment.