-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GWL-142] 운동 시작 3,2,1 타이머 뷰컨트롤러 구현하기 #148
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
24f525a
feat: 타이머 VC 생성
MaraMincho 7a68ae1
feat: 로직 viewController에서 ViewModel로 이동
MaraMincho 53b97c4
style: workoutSetting -> WorkoutEnvironmentSetUp coordinator로 이름 수정
MaraMincho 9ebc673
docs: Entity 주석 추가
MaraMincho dd41835
move: 폴더구조 이동
MaraMincho d1445c6
docs: 코드 주석 변경
MaraMincho 51f5da4
feat: initTime추가
MaraMincho 15b00c6
refector: Init시점에서 시간을 받아서 타이머를 직접 만들 수 있게 수정
MaraMincho 3934c13
style: 필요없는 코드 삭제
MaraMincho a608ae1
style: 변수 명 변경
MaraMincho d797c9d
docs: 주석 수정
MaraMincho c89c369
feat: BeforeWorkoutStartTimer Usecase로 분리
MaraMincho 383bcb0
feat: UseCase VIewModel 연결 및 timerfinish될 때 ViewModel input subject 추가
MaraMincho 318116e
style: 피드백 반영
MaraMincho da4daa1
chore: 포메팅 적용
MaraMincho c60150d
style: 변수 명 수정
MaraMincho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...cts/Features/Record/Sources/Domain/UseCases/CountDownBeforeWorkoutStartTimerUsecase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// CountDownBeforeWorkoutStartTimerUsecase.swift | ||
// RecordFeature | ||
// | ||
// Created by MaraMincho on 11/28/23. | ||
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
// MARK: - CountDownBeforeWorkoutStartTimerUsecaseRepresentable | ||
|
||
protocol CountDownBeforeWorkoutStartTimerUsecaseRepresentable { | ||
func beforeWorkoutTimerTextPublisher() -> AnyPublisher<String, Never> | ||
mutating func startTimer() | ||
mutating func stopTimer() | ||
} | ||
|
||
// MARK: - CountDownBeforeWorkoutStartTimerUsecase | ||
|
||
struct CountDownBeforeWorkoutStartTimerUsecase { | ||
let initDate: Date | ||
var timerCancellable: AnyCancellable? | ||
let beforeWorkoutTimerTextSubject: CurrentValueSubject<String, Never> = .init("") | ||
init(initDate: Date) { | ||
self.initDate = initDate | ||
timerCancellable = nil | ||
} | ||
} | ||
|
||
// MARK: CountDownBeforeWorkoutStartTimerUsecaseRepresentable | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3: Usecase -> UseCase로 변경해주실 수 있나요? 저희 네이밍이 전부 그렇게 되어있어서요. |
||
extension CountDownBeforeWorkoutStartTimerUsecase: CountDownBeforeWorkoutStartTimerUsecaseRepresentable { | ||
func beforeWorkoutTimerTextPublisher() -> AnyPublisher<String, Never> { | ||
return beforeWorkoutTimerTextSubject.eraseToAnyPublisher() | ||
} | ||
|
||
func beforeStartingWorkoutTime() -> Double { | ||
return initDate.timeIntervalSince(.now) | ||
} | ||
|
||
/// 뷰컨트롤러의 던져줄 타이머에 관해서 세팅합니다. | ||
mutating func startTimer() { | ||
timerCancellable = Timer.publish(every: 0.1, on: RunLoop.main, in: .common) | ||
.autoconnect() | ||
.sink { [self] _ in | ||
let beforeTime = beforeStartingWorkoutTime() | ||
let firstMumberMilisecondsFromNow = String(format: "%.1f", beforeStartingWorkoutTime()).suffix(1) | ||
if firstMumberMilisecondsFromNow == "0" { | ||
let message = Int(beforeTime) | ||
// 중요 만약 던지는 뷰에 전달해야 할 타이머 숫자가 0 이라면, timerSubject의 complet시킨다. | ||
message != 0 | ||
? beforeWorkoutTimerTextSubject.send(message.description) | ||
: beforeWorkoutTimerTextSubject.send(completion: .finished) | ||
} | ||
} | ||
} | ||
|
||
mutating func stopTimer() { | ||
timerCancellable = nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// WorkoutSettingCoordinator.swift | ||
// WorkoutEnvironmentSetUpCoordinator.swift | ||
// RecordFeature | ||
// | ||
// Created by 안종표 on 2023/11/20. | ||
|
@@ -11,9 +11,9 @@ import Log | |
import Trinet | ||
import UIKit | ||
|
||
// MARK: - WorkoutSettingCoordinator | ||
// MARK: - WorkoutEnvironmentSetUpCoordinator | ||
|
||
final class WorkoutSettingCoordinator: WorkoutSettingCoordinating { | ||
final class WorkoutEnvironmentSetUpCoordinator: WorkoutEnvironmentSetUpCoordinating { | ||
var navigationController: UINavigationController | ||
var childCoordinators: [Coordinating] = [] | ||
weak var finishDelegate: CoordinatorFinishDelegate? | ||
|
@@ -67,12 +67,21 @@ final class WorkoutSettingCoordinator: WorkoutSettingCoordinating { | |
// TODO: 뷰 컨트롤러 시작 로직 작성 | ||
} | ||
|
||
func finish(workoutSetting: WorkoutSetting) { | ||
settingDidFinishedDelegate?.workoutSettingCoordinatorDidFinished(workoutSetting: workoutSetting) | ||
func finish(workoutSetting _: WorkoutSetting) { | ||
let useCase = CountDownBeforeWorkoutStartTimerUsecase(initDate: .now + 8) | ||
|
||
let vm = CountDownBeforeWorkoutViewModel(coordinator: self, useCase: useCase) | ||
|
||
let vc = CountDownBeforeWorkoutViewController(viewModel: vm) | ||
navigationController.pushViewController(vc, animated: true) | ||
|
||
// TODO: 주석 풀고 코디네이팅 연결 하는 작업 필요 | ||
// 현재는 타이머 뷰컨 실험할려고 잠깐 죽인 코드 | ||
// settingDidFinishedDelegate?.workoutSettingCoordinatorDidFinished(workoutSetting: workoutSetting) | ||
Comment on lines
+78
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3: PR에 불필요한 코드라면 |
||
} | ||
} | ||
|
||
private extension WorkoutSettingCoordinator { | ||
private extension WorkoutEnvironmentSetUpCoordinator { | ||
func makeMockDataFromRnaomMatching() -> URLSessionProtocol { | ||
let mockSession = MockURLSession(mockDataByURLString: makeMockDataFromRnaomMatchingDataByURLString()) | ||
return mockSession | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...ion/CountDownBeforeWorkoutScene/ViewController/CountDownBeforeWorkoutViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// | ||
// CountDownBeforeWorkoutViewController.swift | ||
// RecordFeature | ||
// | ||
// Created by MaraMincho on 11/27/23. | ||
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import DesignSystem | ||
import Log | ||
import UIKit | ||
|
||
// MARK: - CountDownBeforeWorkoutViewController | ||
|
||
final class CountDownBeforeWorkoutViewController: UIViewController { | ||
// MARK: Properties | ||
|
||
private let viewModel: CountDownBeforeWorkoutViewModelRepresentable | ||
|
||
private var subscriptions: Set<AnyCancellable> = [] | ||
|
||
private var didFinishTimerTextSubscriptionSubject: PassthroughSubject<Void, Never> = .init() | ||
private var viewDidAppearSubject: PassthroughSubject<Void, Never> = .init() | ||
|
||
// MARK: UI Components | ||
|
||
private let countDownLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = UIConsts.contDownFontSize | ||
label.textColor = DesignSystemColor.primaryBackground | ||
|
||
label.translatesAutoresizingMaskIntoConstraints = false | ||
return label | ||
}() | ||
|
||
private let countDownLabelCover: UIView = { | ||
let view = UIView() | ||
view.backgroundColor = DesignSystemColor.main03 | ||
|
||
view.layer.cornerRadius = Metrics.coverWidthAndHeight / 2 | ||
view.clipsToBounds = true | ||
|
||
view.translatesAutoresizingMaskIntoConstraints = false | ||
return view | ||
}() | ||
|
||
// MARK: Initializations | ||
|
||
init(viewModel: CountDownBeforeWorkoutViewModelRepresentable) { | ||
self.viewModel = viewModel | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: Life Cycles | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
setup() | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
viewDidAppearSubject.send(()) | ||
} | ||
} | ||
|
||
private extension CountDownBeforeWorkoutViewController { | ||
// MARK: Configuration | ||
|
||
private func setup() { | ||
setupHierarchyAndConstraints() | ||
bind() | ||
setupStyles() | ||
} | ||
|
||
func setupHierarchyAndConstraints() { | ||
view.addSubview(countDownLabelCover) | ||
countDownLabelCover.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | ||
countDownLabelCover.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true | ||
countDownLabelCover.widthAnchor.constraint(equalToConstant: Metrics.coverWidthAndHeight).isActive = true | ||
countDownLabelCover.heightAnchor.constraint(equalToConstant: Metrics.coverWidthAndHeight).isActive = true | ||
|
||
view.addSubview(countDownLabel) | ||
countDownLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | ||
countDownLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true | ||
} | ||
|
||
func setupStyles() { | ||
view.backgroundColor = DesignSystemColor.primaryBackground | ||
} | ||
|
||
func bindViewModel() { | ||
let input = CountDownBeforeWorkoutViewModelInput( | ||
viewDidApperPubilsehr: viewDidAppearSubject.eraseToAnyPublisher(), | ||
didFinsihTimerSubscrion: didFinishTimerTextSubscriptionSubject.eraseToAnyPublisher() | ||
) | ||
|
||
viewModel | ||
.transform(input: input) | ||
.sink(receiveCompletion: { [weak self] stateResults in | ||
switch stateResults { | ||
case .failure(_), | ||
.finished: | ||
self?.didFinishTimerTextSubscriptionSubject.send(()) | ||
} | ||
}, receiveValue: { [weak self] state in | ||
switch state { | ||
case let .updateMessage(message): self?.makeLabelAnimation(labelText: message) | ||
case .idle: break | ||
} | ||
}) | ||
.store(in: &subscriptions) | ||
} | ||
|
||
func bind() { | ||
subscriptions.removeAll() | ||
|
||
bindViewModel() | ||
} | ||
|
||
func makeLabelAnimation(labelText: String) { | ||
Log.make().debug("viewController makeLabelAnimation: \(labelText)") | ||
countDownLabel.text = labelText | ||
countDownLabel.transform = CGAffineTransform(scaleX: 1, y: 1) | ||
view.layoutIfNeeded() | ||
|
||
UIView.animate(withDuration: 0.4, delay: 0, options: .curveEaseOut) { [weak self] in | ||
guard let self else { return } | ||
let scale = UIConsts.minFontTransormScale | ||
countDownLabel.transform = CGAffineTransform(scaleX: scale, y: scale) | ||
} | ||
} | ||
|
||
enum Metrics { | ||
static let coverWidthAndHeight: CGFloat = 240 | ||
} | ||
|
||
enum UIConsts { | ||
static let contDownFontSize: UIFont = .systemFont(ofSize: 120, weight: .bold) | ||
static let minFontTransormScale: CGFloat = 0.6 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굳