From 06a42cfa21d4ffb1f0c6f8462f35fe2d834b8f5b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 13 Apr 2021 15:07:44 -0400 Subject: [PATCH] audio behavior --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Behaviors/PlayAudioBehavior.swift | 54 +++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 MVMCoreUI/Behaviors/PlayAudioBehavior.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index cb13de6f..fc435de1 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -61,6 +61,7 @@ 01EB369323609801006832FA /* HeaderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368C23609801006832FA /* HeaderModel.swift */; }; 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368D23609801006832FA /* HeadlineBodyModel.swift */; }; 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */; }; + 0A01DE272626236300C2CAAC /* PlayAudioBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A01DE262626236300C2CAAC /* PlayAudioBehavior.swift */; }; 0A0FEC7425D42A5E00AF2548 /* BaseItemPickerEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A0FEC7325D42A5E00AF2548 /* BaseItemPickerEntryField.swift */; }; 0A0FEC7825D42A8500AF2548 /* BaseItemPickerEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A0FEC7725D42A8500AF2548 /* BaseItemPickerEntryFieldModel.swift */; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; @@ -622,6 +623,7 @@ 01EB368C23609801006832FA /* HeaderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderModel.swift; sourceTree = ""; }; 01EB368D23609801006832FA /* HeadlineBodyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyModel.swift; sourceTree = ""; }; 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaretLinkModel.swift; sourceTree = ""; }; + 0A01DE262626236300C2CAAC /* PlayAudioBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayAudioBehavior.swift; sourceTree = ""; }; 0A0FEC7325D42A5E00AF2548 /* BaseItemPickerEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseItemPickerEntryField.swift; sourceTree = ""; }; 0A0FEC7725D42A8500AF2548 /* BaseItemPickerEntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseItemPickerEntryFieldModel.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; @@ -1311,6 +1313,7 @@ 0A1C30972620F61A00B47F3B /* Protocols */, 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */, D23A900826125FFB007E14CE /* GetContactBehavior.swift */, + 0A01DE262626236300C2CAAC /* PlayAudioBehavior.swift */, ); path = Behaviors; sourceTree = ""; @@ -2878,6 +2881,7 @@ D2092355244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift in Sources */, 0AE14F64238315D2005417F8 /* TextField.swift in Sources */, 0A51F3E22475CB73002E08B6 /* LoadingSpinnerModel.swift in Sources */, + 0A01DE272626236300C2CAAC /* PlayAudioBehavior.swift in Sources */, D2169303251E53D9002A6324 /* SectionListTemplateModel.swift in Sources */, 0AB764D124460F6300E7FE72 /* UIDatePicker+Extension.swift in Sources */, BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */, diff --git a/MVMCoreUI/Behaviors/PlayAudioBehavior.swift b/MVMCoreUI/Behaviors/PlayAudioBehavior.swift new file mode 100644 index 00000000..9b1e1ba9 --- /dev/null +++ b/MVMCoreUI/Behaviors/PlayAudioBehavior.swift @@ -0,0 +1,54 @@ +// +// PlayAudioBehavior.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/9/21. +// Copyright © 2021 Verizon Wireless. All rights reserved. +// + + +public protocol PagePlayAudioBehaviorConsumerProtocol { +// func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])? +// func consume(contacts: [CNContact]) +} + +public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol { + public class var identifier: String { "pagePlayAudioBehavior" } + public var shouldAllowMultipleInstances: Bool { false } + + public init() { } +} + +public class PagePlayAudioBehavior: PageVisibilityBehavior { + var delegate: MVMCoreUIDelegateObject? + + public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { + self.delegate = delegateObject + } + + public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) { + // Ask for permission +// CNContactStore().requestAccess(for: .contacts) { [weak self] (access, error) in +// guard access, +// error == nil, +// // TODO: Clean up this interface +// let model = (self?.delegate?.moleculeDelegate as? PageProtocol)?.pageModel as? TemplateModelProtocol else { return } +// // Iterate models and provide contact +// let store = CNContactStore() +// let consumers: [PagePlayAudioBehaviorConsumerProtocol] = model.allMoleculesOfType() +// for consumer in consumers { +// guard let parameters = consumer.getMatchParameters(), +// let contacts = try? store.unifiedContacts(matching: parameters.0, keysToFetch: parameters.1) else { return } +// consumer.consume(contacts: contacts) +// } +// +// // Tell template to update +// MVMCoreDispatchUtility.performBlock(onMainThread: { +// // TODO: move to protocol function instead +// (self?.delegate?.moleculeDelegate as? ViewController)?.handleNewData() +// }) +// } + } + + public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {} +}