implementing a delegate pattern.
This commit is contained in:
parent
4fea0eb473
commit
ac13ac6025
@ -13,6 +13,8 @@ public protocol PagePlayAudioBehaviorConsumerProtocol {
|
|||||||
func pause()
|
func pause()
|
||||||
func stop()
|
func stop()
|
||||||
var isPlaying: Bool { get }
|
var isPlaying: Bool { get }
|
||||||
|
var messageID: String? { get }
|
||||||
|
var audioFileURL: URL? { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
|
public class PagePlayAudioBehaviorModel: PageBehaviorModelProtocol {
|
||||||
@ -27,7 +29,7 @@ public class PagePlayAudioBehavior: PageCustomActionHandlerBehavior {
|
|||||||
// MARK: - Active Model
|
// MARK: - Active Model
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var activeAudioPlayer: PagePlayAudioBehaviorConsumerProtocol?
|
public static var activeAudioPlayerDelegate: PagePlayAudioBehaviorConsumerProtocol?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Delegate
|
// MARK: - Delegate
|
||||||
@ -50,31 +52,27 @@ public class PagePlayAudioBehavior: PageCustomActionHandlerBehavior {
|
|||||||
// Either play or pause
|
// Either play or pause
|
||||||
public func handleAction(type actionType: String?, information: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) -> Bool {
|
public func handleAction(type actionType: String?, information: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) -> Bool {
|
||||||
|
|
||||||
// TODO: Has to grab the specific model that is active (expanded). Identify model holder of this action.
|
// TODO: Impose Activity Indicator.
|
||||||
|
|
||||||
// TODO: Update the model. play -> pause OR pause -> play
|
// Update the model. play -> pause OR pause -> play
|
||||||
|
if Self.activeAudioPlayerDelegate?.isPlaying ?? false {
|
||||||
|
Self.activeAudioPlayerDelegate?.pause()
|
||||||
|
|
||||||
// TODO: Download binary
|
} else {
|
||||||
|
|
||||||
// TODO: Store audio file in cache using some key (messageID???) to store it.
|
// Download binary
|
||||||
|
downloadAudioFile { url in
|
||||||
|
|
||||||
// TODO: Actually pause/play
|
// TODO: Actually pause/play
|
||||||
|
Self.activeAudioPlayerDelegate?.audioFileURL = url
|
||||||
|
Self.activeAudioPlayerDelegate?.togglePlayPause()
|
||||||
|
|
||||||
|
// TODO: Remove Activity Indicator.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Tell Template to update this cell (needs to be built). Currently it updates all cells.
|
// TODO: Tell Template to update this cell (needs to be built). Currently it updates all cells.
|
||||||
|
|
||||||
// let templateModel = (delegate?.moleculeDelegate as? PageProtocol)?.pageModel as? TemplateModelProtocol
|
|
||||||
Self.activeAudioPlayer?.play()
|
|
||||||
// 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +83,19 @@ public class PagePlayAudioBehavior: PageCustomActionHandlerBehavior {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Download Audio File
|
// MARK: - Download Audio File
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
func downloadAudioFile(_ completion: @escaping (URL) -> ()) {
|
||||||
|
|
||||||
|
// TODO: Check cache. Return if available
|
||||||
|
// let audioData = MVMCoreCache.shared()?.getCachedData(withName: PagePlayAudioBehavior.activeAudioPlayerDelegate!.messageID!)
|
||||||
|
|
||||||
|
guard let soundFileURL = Bundle.main.url(forResource: "sampleAudio", withExtension: "wav") else { return }
|
||||||
|
|
||||||
|
// TODO: Store audio file in cache using some key (messageID???) to store it.
|
||||||
|
// MVMCoreCache.shared()?.addData(toCache: soundFileURL.dataRepresentation, withName: PagePlayAudioBehavior.activeAudioPlayerDelegate!.messageID!)
|
||||||
|
completion(soundFileURL)
|
||||||
|
// return soundFileURL
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
// https://oneconfluence.verizon.com/pages/viewpage.action?spaceKey=EIM&title=FDV+API
|
// https://oneconfluence.verizon.com/pages/viewpage.action?spaceKey=EIM&title=FDV+API
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user