Skip to content

Commit

Permalink
Merge branch 'issue' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
PinYuanChen committed Aug 4, 2024
2 parents 06793dd + 87bbb91 commit f812ddd
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MorseCode/MorseFeature/FlashManagerPrototype.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions MorseCode/MorseFlash/FlashManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -37,7 +37,7 @@ public class FlashManager: FlashManagerPrototype {
flashTimer?.invalidate()
flashTimer = nil
index = 0
didFinishPlaying?()
completePlayingHandlers.compactMap { $0 }.forEach { $0() }
}

deinit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions MorseCodeApp/MorseCodeApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions MorseCodeTests/MorseFlash/FlashManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down

0 comments on commit f812ddd

Please sign in to comment.