forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnboardingUI.swift
More file actions
205 lines (166 loc) · 8.61 KB
/
OnboardingUI.swift
File metadata and controls
205 lines (166 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
// OnboardingUI.swift
// LoopKitUI
//
// Created by Darin Krauss on 12/10/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
import HealthKit
import LoopKit
public enum NotificationAuthorization: Int {
/// User has not yet made a choice regarding whether the application may schedule or receive user notifications.
case notDetermined
/// User has explicitly denied this application from scheduling or receiving user notifications.
case denied
/// User has authorized this application to schedule or receive non-interruptive user notifications.
case provisional
/// User has authorized this application to schedule or receive any user notifications.
case authorized
}
public protocol NotificationAuthorizationProvider: AnyObject {
/// The current notification authorization.
///
/// - Parameters:
/// - completion: Invoked when notification authorization is available.
func getNotificationAuthorization(_ completion: @escaping (NotificationAuthorization) -> Void)
/// Authorize notification. Should only be invoked if notificationAuthorization is .notDetermined.
///
/// - Parameters:
/// - completion: Invoked when notification authorization is complete along with the resulting authorization.
func authorizeNotification(_ completion: @escaping (NotificationAuthorization) -> Void)
}
public enum HealthStoreAuthorization: Int {
/// User has not yet made a choice regarding permissions for one or more health store data types.
case notDetermined
/// User has explicitly chosen permissions for each health store data type.
case determined
}
public protocol HealthStoreAuthorizationProvider: AnyObject {
/// The current health store authorization.
///
/// - Parameters:
/// - completion: Invoked when health store authorization is available.
func getHealthStoreAuthorization(_ completion: @escaping (HealthStoreAuthorization) -> Void)
/// Authorize health store. Should only be invoked if healthStoreAuthorization is .notDetermined.
///
/// - Parameters:
/// - completion: Invoked when health store authorization is complete along with the resulting authorization.
func authorizeHealthStore(_ completion: @escaping (HealthStoreAuthorization) -> Void)
}
public typealias OnboardingResult = SetupUIResult
public protocol CGMManagerProvider: AnyObject {
/// The active CGM manager.
var activeCGMManager: CGMManager? { get }
/// The descriptor list of available CGM managers.
var availableCGMManagers: [CGMManagerDescriptor] { get }
/// An image for the CGM manager with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the CGM manager.
/// - Returns: An image for the CGM manager with the specified identifier.
func imageForCGMManager(withIdentifier identifier: String) -> UIImage?
/// Onboard the CGM manager with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the CGM manager to onboard.
/// - Returns: Either a conforming view controller to onboard the CGM manager, a newly onboarded CGM manager, or an error.
func onboardCGMManager(withIdentifier identifier: String, prefersToSkipUserInteraction: Bool) -> Result<OnboardingResult<CGMManagerViewController, CGMManager>, Error>
}
public protocol PumpManagerProvider: AnyObject {
/// The active pump manager.
var activePumpManager: PumpManager? { get }
/// The descriptor list of available pump managers.
var availablePumpManagers: [PumpManagerDescriptor] { get }
/// An image for the pump manager with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the pump manager.
/// - Returns: An image for the pump manager with the specified identifier.
func imageForPumpManager(withIdentifier identifier: String) -> UIImage?
/// An supported increments for the pump manager with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the pump manager.
/// - Returns: An supported increments for the pump manager with the specified identifier.
func supportedIncrementsForPumpManager(withIdentifier identifier: String) -> PumpSupportedIncrements?
/// Onboard the pump manager with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the pump manager to onboard.
/// - Returns: Either a conforming view controller to onboard the pump manager, a newly onboarded pump manager, or an error.
func onboardPumpManager(withIdentifier identifier: String, initialSettings settings: PumpManagerSetupSettings, prefersToSkipUserInteraction: Bool) -> Result<OnboardingResult<PumpManagerViewController, PumpManager>, Error>
}
public protocol ServiceProvider: AnyObject {
/// The active services.
var activeServices: [Service] { get }
/// The descriptor list of available services.
var availableServices: [ServiceDescriptor] { get }
/// Onboard the service with the specified identifier.
///
/// - Parameters:
/// - identifier: The identifier of the service to onboard.
/// - Returns: Either a conforming view controller to onboard the service, a newly onboarded service, or an error.
func onboardService(withIdentifier identifier: String) -> Result<OnboardingResult<ServiceViewController, Service>, Error>
}
public protocol TherapySettingsProvider {
var onboardingTherapySettings: TherapySettings { get }
}
public protocol SupportProvider: AnyObject {
var availableSupports: [SupportUI] { get }
}
public protocol OnboardingProvider: NotificationAuthorizationProvider, HealthStoreAuthorizationProvider, BluetoothProvider, CGMManagerProvider, PumpManagerProvider, StatefulPluggableProvider, ServiceProvider, TherapySettingsProvider, SupportProvider {
var allowDebugFeatures: Bool { get } // NOTE: DEBUG FEATURES - DEBUG AND TEST ONLY
}
public protocol OnboardingDelegate: AnyObject {
/// Informs the delegate that the state of the onboarding was updated and the delegate should persist the onboarding. May
/// be invoked prior to the onboarding being fully complete.
///
/// - Parameters:
/// - onboarding: The onboarding that updated state.
func onboardingDidUpdateState(_ onboarding: OnboardingUI)
/// Informs the delegate that onboarding has new therapy settings that should be persisted.
///
/// - Parameters:
/// - onboarding: The onboarding that has new therapy settings.
/// - therapySettings: The new therapy settings.
func onboarding(_ onboarding: OnboardingUI, hasNewTherapySettings therapySettings: TherapySettings)
/// Informs the delegate that onboarding has new dosing enabled that should be persisted.
///
/// - Parameters:
/// - onboarding: The onboarding that has new dosing enabled.
/// - isClosedLoop: The new dosing enabled.
func onboarding(_ onboarding: OnboardingUI, hasNewDosingEnabled dosingEnabled: Bool)
/// Informs the delegate the onboarding has suspended.
///
/// - Parameters:
/// - onboarding: The onboarding that has suspended.
func onboardingDidSuspend(_ onboarding: OnboardingUI)
}
public typealias OnboardingViewController = (UIViewController & CGMManagerOnboarding & PumpManagerOnboarding & ServiceOnboarding & CompletionNotifying)
public protocol OnboardingUI: Pluggable {
typealias RawState = [String: Any]
/// Create a new onboarding.
///
/// - Returns: A newly created onboarding.
static func createOnboarding() -> OnboardingUI
/// Delegate to notify about onboarding changes.
var onboardingDelegate: OnboardingDelegate? { get set }
/// Initializes the onboarding with the previously-serialized state.
///
/// - Parameters:
/// - rawState: The previously-serialized state of the onboarding.
init?(rawState: RawState)
/// The current, serializable state of the onboarding.
var rawState: RawState { get }
/// Is the onboarding complete?
var isOnboarded: Bool { get }
/// Provides a view controller to configure onboarding, if needed.
///
/// - Parameters:
/// - onboardingProvider: The provider of auxillary services that support onboarding.
/// - displayGlucosePreference: The glucose unit to use for display.
/// - colorPalette: The colors to use in any UI,
/// - Returns: A view controller to create and configure a new onboarding.
func onboardingViewController(onboardingProvider: OnboardingProvider, displayGlucosePreference: DisplayGlucosePreference, colorPalette: LoopUIColorPalette) -> OnboardingViewController
}