ServiceUI.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // ServiceUI.swift
  3. // LoopKitUI
  4. //
  5. // Created by Darin Krauss on 5/17/19.
  6. // Copyright © 2019 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKit
  10. public struct ServiceDescriptor {
  11. public let identifier: String
  12. public let localizedTitle: String
  13. public init(identifier: String, localizedTitle: String) {
  14. self.identifier = identifier
  15. self.localizedTitle = localizedTitle
  16. }
  17. }
  18. public typealias ServiceViewController = (UIViewController & ServiceOnboarding & CompletionNotifying)
  19. public protocol ServiceUI: Service {
  20. /// The image for this type of service.
  21. static var image: UIImage? { get }
  22. /// Create and onboard a new service.
  23. ///
  24. /// - Parameters:
  25. /// - colorPalette: Color palette to use for any UI.
  26. /// - Returns: Either a conforming view controller to create and onboard the service or a newly created and onboarded service.
  27. static func setupViewController(colorPalette: LoopUIColorPalette) -> SetupUIResult<ServiceViewController, ServiceUI>
  28. /// Configure settings for an existing service.
  29. ///
  30. /// - Parameters:
  31. /// - colorPalette: Color palette to use for any UI.
  32. /// - Returns: A view controller to configure an existing service.
  33. func settingsViewController(colorPalette: LoopUIColorPalette) -> ServiceViewController
  34. }
  35. public extension ServiceUI {
  36. var image: UIImage? { return type(of: self).image }
  37. }
  38. public protocol ServiceOnboardingDelegate: AnyObject {
  39. /// Informs the delegate that the specified service was created.
  40. ///
  41. /// - Parameters:
  42. /// - service: The service created.
  43. func serviceOnboarding(didCreateService service: Service)
  44. /// Informs the delegate that the specified service was onboarded.
  45. ///
  46. /// - Parameters:
  47. /// - service: The service onboarded.
  48. func serviceOnboarding(didOnboardService service: Service)
  49. }
  50. public protocol ServiceOnboarding {
  51. /// Delegate to notify about service onboarding.
  52. var serviceOnboardingDelegate: ServiceOnboardingDelegate? { get set }
  53. }