Revising for play audio behavior.
This commit is contained in:
parent
06a42cfa21
commit
6b61063811
@ -475,10 +475,12 @@ import UIKit
|
|||||||
addFormParams(requestParameters)
|
addFormParams(requestParameters)
|
||||||
requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
|
requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
|
||||||
var pageForwardedData = additionalData ?? [:]
|
var pageForwardedData = additionalData ?? [:]
|
||||||
|
|
||||||
executeBehaviors { (behavior: PageLocalDataShareBehavior) in
|
executeBehaviors { (behavior: PageLocalDataShareBehavior) in
|
||||||
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
|
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())
|
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)
|
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
|
var handled = false
|
||||||
|
|
||||||
executeBehaviors { (behavior: PageCustomActionHandlerBehavior) in
|
executeBehaviors { (behavior: PageCustomActionHandlerBehavior) in
|
||||||
if (!handled) {
|
if !handled {
|
||||||
handled = behavior.handleAction(type: actionType, information: actionInformation, additionalData: additionalData)
|
handled = behavior.handleAction(type: actionType, information: actionInformation, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!handled) {
|
|
||||||
|
if !handled {
|
||||||
MVMCoreUIActionHandler.defaultHandleUnknownActionType(actionType, actionInformation: actionInformation, additionalData: additionalData, delegateObject: delegateObjectIVar)
|
MVMCoreUIActionHandler.defaultHandleUnknownActionType(actionType, actionInformation: actionInformation, additionalData: additionalData, delegateObject: delegateObjectIVar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Contacts
|
import Contacts
|
||||||
|
|
||||||
|
|
||||||
public protocol PageGetContactBehaviorConsumerProtocol {
|
public protocol PageGetContactBehaviorConsumerProtocol {
|
||||||
func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])?
|
func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])?
|
||||||
func consume(contacts: [CNContact])
|
func consume(contacts: [CNContact])
|
||||||
@ -18,7 +19,7 @@ public class PageGetContactBehaviorModel: PageBehaviorModelProtocol {
|
|||||||
public class var identifier: String { "pageGetContactBehavior" }
|
public class var identifier: String { "pageGetContactBehavior" }
|
||||||
public var shouldAllowMultipleInstances: Bool { false }
|
public var shouldAllowMultipleInstances: Bool { false }
|
||||||
|
|
||||||
public init() {}
|
public init() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PageGetContactBehavior: PageVisibilityBehavior {
|
public class PageGetContactBehavior: PageVisibilityBehavior {
|
||||||
@ -51,5 +52,5 @@ public class PageGetContactBehavior: PageVisibilityBehavior {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) {}
|
public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
|
|
||||||
public protocol PagePlayAudioBehaviorConsumerProtocol {
|
public protocol PagePlayAudioBehaviorConsumerProtocol {
|
||||||
// func getMatchParameters() -> (NSPredicate, [CNKeyDescriptor])?
|
func playPause()
|
||||||
// func consume(contacts: [CNContact])
|
func stop()
|
||||||
|
func isPlaying()
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
|
public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
|
||||||
@ -19,36 +20,44 @@ public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
|
|||||||
public init() { }
|
public init() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PagePlayAudioBehavior: PageVisibilityBehavior {
|
public class PagePlayAudioBehavior: PageCustomActionHandlerBehavior {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Delegate
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
var delegate: MVMCoreUIDelegateObject?
|
var delegate: MVMCoreUIDelegateObject?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Init
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) {
|
public required init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) {
|
||||||
self.delegate = delegateObject
|
self.delegate = delegateObject
|
||||||
}
|
}
|
||||||
|
|
||||||
public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) {
|
//--------------------------------------------------
|
||||||
// Ask for permission
|
// MARK: - Custom Action
|
||||||
// CNContactStore().requestAccess(for: .contacts) { [weak self] (access, error) in
|
//--------------------------------------------------
|
||||||
// guard access,
|
|
||||||
// error == nil,
|
public func handleAction(type actionType: String?, information: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) -> Bool {
|
||||||
// // TODO: Clean up this interface
|
|
||||||
// let model = (self?.delegate?.moleculeDelegate as? PageProtocol)?.pageModel as? TemplateModelProtocol else { return }
|
let templateModel = (delegate?.moleculeDelegate as? PageProtocol)?.pageModel as? TemplateModelProtocol
|
||||||
// // Iterate models and provide contact
|
|
||||||
// let store = CNContactStore()
|
let consumers: [PagePlayAudioBehaviorConsumerProtocol] = templateModel!.allMoleculesOfType()
|
||||||
// let consumers: [PagePlayAudioBehaviorConsumerProtocol] = model.allMoleculesOfType()
|
for consumer in consumers {
|
||||||
// for consumer in consumers {
|
consumer.playPause()
|
||||||
// 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: { [weak self] in
|
||||||
//
|
// TODO: move to protocol function instead
|
||||||
// // Tell template to update
|
(self?.delegate?.moleculeDelegate as? ViewController)?.handleNewData()
|
||||||
// MVMCoreDispatchUtility.performBlock(onMainThread: {
|
})
|
||||||
// // 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -224,6 +224,7 @@ open class CoreUIModelMapping: ModelMapping {
|
|||||||
open class func registerBehaviors() {
|
open class func registerBehaviors() {
|
||||||
try? ModelRegistry.register(handler: ScreenBrightnessModifierBehavior.self, for: ScreenBrightnessModifierBehaviorModel.self)
|
try? ModelRegistry.register(handler: ScreenBrightnessModifierBehavior.self, for: ScreenBrightnessModifierBehaviorModel.self)
|
||||||
try? ModelRegistry.register(handler: PageGetContactBehavior.self, for: PageGetContactBehaviorModel.self)
|
try? ModelRegistry.register(handler: PageGetContactBehavior.self, for: PageGetContactBehaviorModel.self)
|
||||||
|
try? ModelRegistry.register(handler: PagePlayAudioBehavior.self, for: PagePlayAudioBehaviorModel.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func registerActions() {
|
open override class func registerActions() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user