From d261cdd2b295ed33b172782e1e737cdadd35ace6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Inge=20Berg?= Date: Sat, 21 Oct 2023 21:13:14 +0200 Subject: [PATCH] Insert cannula view improvements for OmniKit --- OmniKit.xcodeproj/project.pbxproj | 27 ++++++++ .../ViewModels/InsertCannulaViewModel.swift | 12 +++- OmniKitUI/Views/InsertCannulaView.swift | 68 ++++++++++++++++--- 3 files changed, 96 insertions(+), 11 deletions(-) diff --git a/OmniKit.xcodeproj/project.pbxproj b/OmniKit.xcodeproj/project.pbxproj index f445a65..1bf43a5 100644 --- a/OmniKit.xcodeproj/project.pbxproj +++ b/OmniKit.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 275A98C02AE456EA0097F476 /* SlideButton in Frameworks */ = {isa = PBXBuildFile; productRef = 275A98BF2AE456EA0097F476 /* SlideButton */; }; C1229C1A29C7E5BC0066A89C /* RileyLinkBLEKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1229C1729C7E5BC0066A89C /* RileyLinkBLEKit.framework */; }; C1229C1B29C7E5BC0066A89C /* RileyLinkBLEKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C1229C1729C7E5BC0066A89C /* RileyLinkBLEKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C1229C1C29C7E5BC0066A89C /* RileyLinkKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1229C1829C7E5BC0066A89C /* RileyLinkKit.framework */; }; @@ -454,6 +455,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 275A98C02AE456EA0097F476 /* SlideButton in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -885,6 +887,9 @@ dependencies = ( ); name = OmniKitUI; + packageProductDependencies = ( + 275A98BF2AE456EA0097F476 /* SlideButton */, + ); productName = OmniKitUI; productReference = C124020B29C7D92700B32844 /* OmniKitUI.framework */; productType = "com.apple.product-type.framework"; @@ -989,6 +994,9 @@ hi, ); mainGroup = C124016229C7D87A00B32844; + packageReferences = ( + 275A98BE2AE456EA0097F476 /* XCRemoteSwiftPackageReference "SlideButton" */, + ); productRefGroup = C124016D29C7D87A00B32844 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -1782,6 +1790,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 275A98BE2AE456EA0097F476 /* XCRemoteSwiftPackageReference "SlideButton" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/no-comment/SlideButton"; + requirement = { + branch = main; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 275A98BF2AE456EA0097F476 /* SlideButton */ = { + isa = XCSwiftPackageProductDependency; + package = 275A98BE2AE456EA0097F476 /* XCRemoteSwiftPackageReference "SlideButton" */; + productName = SlideButton; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = C124016329C7D87A00B32844 /* Project object */; } diff --git a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift index c35617f..029ef7d 100644 --- a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift +++ b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift @@ -30,7 +30,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { var actionButtonAccessibilityLabel: String { switch self { case .ready, .startingInsertion: - return LocalizedString("Insert Cannula", comment: "Insert cannula action button accessibility label while ready to pair") + return LocalizedString("Slide Button to insert Cannula", comment: "Insert cannula slider button accessibility label while ready to pair") case .inserting: return LocalizedString("Inserting. Please wait.", comment: "Insert cannula action button accessibility label while pairing") case .checkingInsertion: @@ -54,7 +54,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { var nextActionButtonDescription: String { switch self { case .ready: - return LocalizedString("Insert Cannula", comment: "Cannula insertion button text while ready to insert") + return LocalizedString("Slide to Insert Cannula", comment: "Cannula insertion button text while ready to insert") case .error: return LocalizedString("Retry", comment: "Cannula insertion button text while showing error") case .inserting, .startingInsertion: @@ -125,6 +125,14 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { } @Published var state: InsertCannulaViewModelState = .ready + public var stateNeedsDeliberateUserAcceptance : Bool { + switch state { + case .ready: + true + default: + false + } + } var didFinish: (() -> Void)? diff --git a/OmniKitUI/Views/InsertCannulaView.swift b/OmniKitUI/Views/InsertCannulaView.swift index b2e1e23..c1761ff 100644 --- a/OmniKitUI/Views/InsertCannulaView.swift +++ b/OmniKitUI/Views/InsertCannulaView.swift @@ -8,6 +8,8 @@ import SwiftUI import LoopKitUI +import SlideButton +import OmniKit struct InsertCannulaView: View { @@ -24,7 +26,7 @@ struct InsertCannulaView: View { HStack { InstructionList(instructions: [ - LocalizedString("Tap below to start cannula insertion.", comment: "Label text for step one of insert cannula instructions"), + LocalizedString("Slide the switch below to start cannula insertion.", comment: "Label text for step one of insert cannula instructions"), LocalizedString("Wait until insertion is completed.", comment: "Label text for step two of insert cannula instructions"), ]) .disabled(viewModel.state.instructionsDisabled) @@ -65,14 +67,7 @@ struct InsertCannulaView: View { } if (self.viewModel.error == nil || self.viewModel.error?.recoverable == true) { - Button(action: { - self.viewModel.continueButtonTapped() - }) { - Text(self.viewModel.state.nextActionButtonDescription) - .accessibility(identifier: "button_next_action") - .accessibility(label: Text(self.viewModel.state.actionButtonAccessibilityLabel)) - .actionButtonStyle(.primary) - } + actionButton .disabled(self.viewModel.state.isProcessing) .zIndex(1) } @@ -85,6 +80,37 @@ struct InsertCannulaView: View { .navigationBarBackButtonHidden(true) .navigationBarItems(trailing: cancelButton) } + var actionText : some View { + Text(self.viewModel.state.nextActionButtonDescription) + .accessibility(identifier: "button_next_action") + .accessibility(label: Text(self.viewModel.state.actionButtonAccessibilityLabel)) + .font(.headline) + + } + + + @ViewBuilder + var actionButton: some View { + if self.viewModel.stateNeedsDeliberateUserAcceptance { + SlideButton(action: { + self.viewModel.continueButtonTapped() + }) { + actionText + } + + } else { + Button(action: { + self.viewModel.continueButtonTapped() + }) { + actionText + .actionButtonStyle(.primary) + } + + } + + + } + var cancelButton: some View { Button(LocalizedString("Cancel", comment: "Cancel button text in navigation bar on insert cannula screen")) { @@ -103,3 +129,27 @@ struct InsertCannulaView: View { } } + +class MockCannulaInserter: CannulaInserter { + public func insertCannula(completion: @escaping (Result) -> Void) { + let mockDelay = TimeInterval(seconds: 3) + let result :Result = .success(mockDelay) + completion(result) + } + + func checkCannulaInsertionFinished(completion: @escaping (OmnipodPumpManagerError?) -> Void) { + completion(nil) + } + + +} +struct InsertCannulaView_Previews: PreviewProvider { + static var mockInserter = MockCannulaInserter() + static var model = InsertCannulaViewModel(cannulaInserter: mockInserter) + static var previews: some View { + InsertCannulaView(viewModel: model) + + + + } +}