diff --git a/MorseCode/MorseFeature/FlashManagerPrototype.swift b/MorseCode/MorseFeature/FlashManagerPrototype.swift index f9efc84..971839f 100644 --- a/MorseCode/MorseFeature/FlashManagerPrototype.swift +++ b/MorseCode/MorseFeature/FlashManagerPrototype.swift @@ -9,7 +9,7 @@ public protocol FlashManagerPrototype { var currentStatus: FlashStatusType { get } func startPlaySignals(signals: [FlashType], uuid: UUID) func stopPlayingSignals() - var didFinishPlaying: (() -> Void)? { get set } + var completePlayingHandlers: [(() -> Void)?] { get set } } public enum FlashStatusType: Equatable { diff --git a/MorseCode/MorseFlash/FlashManager.swift b/MorseCode/MorseFlash/FlashManager.swift index aa1c7a8..0e38992 100644 --- a/MorseCode/MorseFlash/FlashManager.swift +++ b/MorseCode/MorseFlash/FlashManager.swift @@ -8,7 +8,7 @@ public class FlashManager: FlashManagerPrototype { public private(set) var currentStatus: FlashStatusType = .stop public let timerScheduler: TimerSchedulerPrototype - public var didFinishPlaying: (() -> Void)? + public var completePlayingHandlers: [(() -> Void)?] = [] public private(set) var index = 0 public init(timerScheduler: TimerSchedulerPrototype = RunLoop.current) { @@ -37,7 +37,7 @@ public class FlashManager: FlashManagerPrototype { flashTimer?.invalidate() flashTimer = nil index = 0 - didFinishPlaying?() + completePlayingHandlers.compactMap { $0 }.forEach { $0() } } deinit { diff --git a/MorseCodeApp/MorseCodeApp/Convert/Presenter/MorseCodePresenter.swift b/MorseCodeApp/MorseCodeApp/Convert/Presenter/MorseCodePresenter.swift index ee26c04..20108f7 100644 --- a/MorseCodeApp/MorseCodeApp/Convert/Presenter/MorseCodePresenter.swift +++ b/MorseCodeApp/MorseCodeApp/Convert/Presenter/MorseCodePresenter.swift @@ -41,9 +41,9 @@ public class MorseCodePresenter: MorseCodePresenterPrototype { self.flashManager = flashManager self.localLoader = localLoader - self.flashManager.didFinishPlaying = { [unowned self] in + self.flashManager.completePlayingHandlers.append({ [unowned self] in self.delegate?.updateFlashButton(status: .stop, enable: self.presentedUUID != nil) - } + }) } public func checkFirstTime() { diff --git a/MorseCodeApp/MorseCodeApp/Convert/ViewControllers/MorseCodeViewController.swift b/MorseCodeApp/MorseCodeApp/Convert/ViewControllers/MorseCodeViewController.swift index 04aafd4..9901bcb 100644 --- a/MorseCodeApp/MorseCodeApp/Convert/ViewControllers/MorseCodeViewController.swift +++ b/MorseCodeApp/MorseCodeApp/Convert/ViewControllers/MorseCodeViewController.swift @@ -59,7 +59,8 @@ extension MorseCodeViewController: MorseCodePresenterDelegate { public func updateFlashButton(status: FlashStatusType, enable: Bool) { let imageName = switch status { - case .playing(_): "flashlight.slash.circle.fill" + case .playing(_): + "flashlight.slash.circle.fill" case .stop: "flashlight.on.circle.fill" } diff --git a/MorseCodeApp/MorseCodeApp/Info.plist b/MorseCodeApp/MorseCodeApp/Info.plist index 0eb786d..7c5f0be 100644 --- a/MorseCodeApp/MorseCodeApp/Info.plist +++ b/MorseCodeApp/MorseCodeApp/Info.plist @@ -2,6 +2,8 @@ + ITSAppUsesNonExemptEncryption + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/MorseCodeApp/MorseCodeApp/Records/Presenter/RecordsPresenter.swift b/MorseCodeApp/MorseCodeApp/Records/Presenter/RecordsPresenter.swift index 91c7dc8..8ef7650 100644 --- a/MorseCodeApp/MorseCodeApp/Records/Presenter/RecordsPresenter.swift +++ b/MorseCodeApp/MorseCodeApp/Records/Presenter/RecordsPresenter.swift @@ -38,9 +38,9 @@ public class RecordsPresenter: RecordsPresenterPrototype { self.flashManager = flashManager self.loader = loader - self.flashManager.didFinishPlaying = { [unowned self] in + self.flashManager.completePlayingHandlers.append ({ [unowned self] in self.delegate?.reloadData() - } + }) } public func loadRecords() { diff --git a/MorseCodeTests/MorseFlash/FlashManagerTests.swift b/MorseCodeTests/MorseFlash/FlashManagerTests.swift index 27bf097..03c4a91 100644 --- a/MorseCodeTests/MorseFlash/FlashManagerTests.swift +++ b/MorseCodeTests/MorseFlash/FlashManagerTests.swift @@ -27,10 +27,10 @@ final class FlashManagerTests: XCTestCase { func test_validDevice_stopPlayingSignals_didStop() { let sut = makeSUT() - sut.didFinishPlaying = { [weak sut] in + sut.completePlayingHandlers.append({ [weak sut] in guard let sut = sut else { return } XCTAssertEqual(sut.currentStatus, FlashStatusType.stop) - } + }) sut.startPlaySignals(signals: anySignals()) sut.stopPlayingSignals() } @@ -50,11 +50,11 @@ final class FlashManagerTests: XCTestCase { let sut = makeSUT(timerScheduler: timerScheduler) let exp = expectation(description: "Wait for stop") - sut.didFinishPlaying = { [weak sut] in + sut.completePlayingHandlers.append({ [weak sut] in guard let sut = sut else { return } XCTAssertEqual(sut.index, 0) exp.fulfill() - } + }) sut.startPlaySignals(signals: [.di]) wait(for: [exp], timeout: 1)