ServiceUI.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /// - pluginHost: Object that provides namd and version information about host to the service plugin.
  27. /// - Returns: Either a conforming view controller to create and onboard the service or a newly created and onboarded service.
  28. static func setupViewController(colorPalette: LoopUIColorPalette, pluginHost: PluginHost) -> SetupUIResult<ServiceViewController, ServiceUI>
  29. /// Configure settings for an existing service.
  30. ///
  31. /// - Parameters:
  32. /// - colorPalette: Color palette to use for any UI.
  33. /// - Returns: A view controller to configure an existing service.
  34. func settingsViewController(colorPalette: LoopUIColorPalette) -> ServiceViewController
  35. }
  36. public extension ServiceUI {
  37. var image: UIImage? { return type(of: self).image }
  38. }
  39. public protocol ServiceOnboardingDelegate: AnyObject {
  40. /// Informs the delegate that the specified service was created.
  41. ///
  42. /// - Parameters:
  43. /// - service: The service created.
  44. func serviceOnboarding(didCreateService service: Service)
  45. /// Informs the delegate that the specified service was onboarded.
  46. ///
  47. /// - Parameters:
  48. /// - service: The service onboarded.
  49. func serviceOnboarding(didOnboardService service: Service)
  50. }
  51. public protocol ServiceOnboarding {
  52. /// Delegate to notify about service onboarding.
  53. var serviceOnboardingDelegate: ServiceOnboardingDelegate? { get set }
  54. }