Revising for play audio behavior.

This commit is contained in:
Kevin G Christiano 2021-04-14 11:23:14 -04:00
parent 06a42cfa21
commit 6b61063811
4 changed files with 47 additions and 32 deletions

View File

@ -475,10 +475,12 @@ import UIKit
addFormParams(requestParameters)
requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
var pageForwardedData = additionalData ?? [:]
executeBehaviors { (behavior: PageLocalDataShareBehavior) in
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
pageForwardedData.merge(dataMap) { (current, _) in current }
pageForwardedData.merge(dataMap) { current, _ in current }
}
MVMCoreActionHandler.defaultHandleOpenPage(for: requestParameters, actionInformation: actionInformation, additionalData: pageForwardedData, delegateObject: delegateObject())
}
@ -486,14 +488,16 @@ import UIKit
MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: self, actionInformation: actionInformation, additionalData: additionalData)
}
open func handleUnknownActionType(_ actionType: String?, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) {
open func handleUnknownActionType(_ actionType: String?, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
var handled = false
executeBehaviors { (behavior: PageCustomActionHandlerBehavior) in
if (!handled) {
if !handled {
handled = behavior.handleAction(type: actionType, information: actionInformation, additionalData: additionalData)
}
}
if (!handled) {
if !handled {
MVMCoreUIActionHandler.defaultHandleUnknownActionType(actionType, actionInformation: actionInformation, additionalData: additionalData, delegateObject: delegateObjectIVar)
}
}

View File

@ -9,6 +9,7 @@
import Foundation
import Contacts
public protocol PageGetContactBehaviorConsumerProtocol {
func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])?
func consume(contacts: [CNContact])
@ -18,7 +19,7 @@ public class PageGetContactBehaviorModel: PageBehaviorModelProtocol {
public class var identifier: String { "pageGetContactBehavior" }
public var shouldAllowMultipleInstances: Bool { false }
public init() {}
public init() { }
}
public class PageGetContactBehavior: PageVisibilityBehavior {
@ -51,5 +52,5 @@ public class PageGetContactBehavior: PageVisibilityBehavior {
}
}
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {}
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) { }
}

View File

@ -8,8 +8,9 @@
public protocol PagePlayAudioBehaviorConsumerProtocol {
// func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])?
// func consume(contacts: [CNContact])
func playPause()
func stop()
func isPlaying()
}
public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
@ -19,36 +20,44 @@ public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
public init() { }
}
public class PagePlayAudioBehavior: PageVisibilityBehavior {
public class PagePlayAudioBehavior: PageCustomActionHandlerBehavior {
//--------------------------------------------------
// MARK: - Delegate
//--------------------------------------------------
var delegate: MVMCoreUIDelegateObject?
//--------------------------------------------------
// MARK: - Init
//--------------------------------------------------
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()
// })
// }
//--------------------------------------------------
// MARK: - Custom Action
//--------------------------------------------------
public func handleAction(type actionType: String?, information: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) -> Bool {
let templateModel = (delegate?.moleculeDelegate as? PageProtocol)?.pageModel as? TemplateModelProtocol
let consumers: [PagePlayAudioBehaviorConsumerProtocol] = templateModel!.allMoleculesOfType()
for consumer in consumers {
consumer.playPause()
}
// Tell template to update.
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
// TODO: move to protocol function instead
(self?.delegate?.moleculeDelegate as? ViewController)?.handleNewData()
})
return true
}
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {}
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {
// TODO: Stop player
}
}

View File

@ -224,6 +224,7 @@ open class CoreUIModelMapping: ModelMapping {
open class func registerBehaviors() {
try? ModelRegistry.register(handler: ScreenBrightnessModifierBehavior.self, for: ScreenBrightnessModifierBehaviorModel.self)
try? ModelRegistry.register(handler: PageGetContactBehavior.self, for: PageGetContactBehaviorModel.self)
try? ModelRegistry.register(handler: PagePlayAudioBehavior.self, for: PagePlayAudioBehaviorModel.self)
}
open override class func registerActions() {