Skip to content
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

⚓️ :: [#171] 타이머 View 작업 #178

Merged
merged 30 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b100fd0
🍗 :: [#171] Int형으로 리펙토링
Eunho0922 Feb 13, 2024
518252c
🍗 :: [#171] 타이머 Int형으로 변경
Eunho0922 Feb 13, 2024
16392ce
🍗 :: [#171] 타이머 Int형으로 변경
Eunho0922 Feb 13, 2024
c7c6a47
🍗 :: [#171] 타이머 Int형으로 변경
Eunho0922 Feb 13, 2024
de49131
⚓️ :: [#171] core에 tokenManager 추가
Eunho0922 Feb 13, 2024
bcd093a
🍗 :: [#171] Double 자료형으로 변경
Eunho0922 Feb 13, 2024
931b73a
🍗 :: [#171] Double 자료형으로 변경
Eunho0922 Feb 13, 2024
09455c4
🍗 :: [#171] 마음가짐 타이머 킷
Eunho0922 Feb 13, 2024
6962eba
🍗 :: [#171] Double자료형으로 변경
Eunho0922 Feb 13, 2024
f07bb79
🍗 :: [#171] 타이머 종료 조건 변경
Eunho0922 Feb 13, 2024
f5b9ced
⚓️ :: [#171] 멀티 타이머 적용
Eunho0922 Feb 14, 2024
42f6d05
🍗 :: [#171] 변수 이름 리펙토링
Eunho0922 Feb 14, 2024
2895c22
⚓️ :: [#171] 인덱스 data 함수 추가
Eunho0922 Feb 14, 2024
2007f32
🍗 :: [#171] collectionView 파일 구조 변경
Eunho0922 Feb 14, 2024
e40a223
🍗 :: [#171] 상단 view 파일 구조 변경
Eunho0922 Feb 14, 2024
479d22c
🍗 :: [#171] 이름 중복 변경
Eunho0922 Feb 14, 2024
6da27e6
⚓️ :: [#171] 임시 데이터 추가
Eunho0922 Feb 14, 2024
839d186
🍗 :: [#171] homeTimerView 수정중
Eunho0922 Feb 14, 2024
23e6809
⚓️ :: [#171] 타이머 추가 view 파일 추가
Eunho0922 Feb 14, 2024
1d6d0d2
⚓️ :: [#171] 타이머 피커 View 파일 추가
Eunho0922 Feb 15, 2024
dc6d34a
⚓️ :: [#171] 타이머 추가 View
Eunho0922 Feb 15, 2024
9bda47a
⚓️ :: [#171] 타이머 피커 view 추가
Eunho0922 Feb 15, 2024
fc4efac
🍗 :: [#171] 홈 타이머 view
Eunho0922 Feb 15, 2024
555a34e
🍗 :: [#171] 타이머 콜렉션 뷰 cell 리펙토링
Eunho0922 Feb 15, 2024
caa4ff8
🍗 :: [#171] 타이머 VC 수정중
Eunho0922 Feb 15, 2024
75e91dd
🍗 :: [#171] conflict 해결
Eunho0922 Feb 15, 2024
5e154c3
🍗 :: [#171] conflict 해결
Eunho0922 Feb 15, 2024
031cd97
🍗 :: [#171] conflict 해결
Eunho0922 Feb 15, 2024
e65609b
🍗 :: [#171] conflict 해결
Eunho0922 Feb 15, 2024
d4b7815
🍗 :: [#171] conflict 해결
Eunho0922 Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Projects/Domain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let project = Project.makeModule(
name: "Domain",
targets: [.unitTest, .dynamicFramework],
internalDependencies: [
.core
.core,
.Modules.tokenManager
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import UIKit

import SnapKit
import Then

import Core
import DSKit

public class AddTimerView: BaseView {

private var containerView = UIView().then {
$0.backgroundColor = UIColor.black.withAlphaComponent(0.4)
}

private let timerAddBackView = UIView().then {
$0.backgroundColor = .white
$0.layer.cornerRadius = 20.0
}

private let addTimerLabel = UILabel().then {
$0.text = "타이머 추가"
$0.font = UIFont.Pretendard.titleMedium
$0.textAlignment = .left
$0.textColor = .black
}

private let timerPickerView = TimerPickerView()

public override func layout() {
addSubviews([containerView])
containerView.addSubviews([timerAddBackView])
timerAddBackView.addSubviews([addTimerLabel, timerPickerView])

containerView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

timerAddBackView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview()
$0.bottom.equalTo(containerView.safeAreaLayoutGuide)
$0.top.equalTo(containerView.snp.centerY).offset(-62.0)
}

addTimerLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(24.0)
$0.leading.trailing.equalToSuperview().inset(20.0)
$0.height.equalTo(32.0)
}

timerPickerView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(20.0)
$0.top.equalToSuperview().offset(80.0)
$0.bottom.equalToSuperview().offset(-74.0)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@ import Then
import DSKit

public class HomeTimerView: UIView {
private var homeTimer = MindGymTimerKit()

public var homeTimer = MindGymTimerKit()

private var radius: Double!
private var colorCircle: UIColor!
private var trackLayer: CAShapeLayer!
private var circleShapeLayer: CAShapeLayer!

private var initTime: Double = 0.0
private var cancelTime: Double = 0.0
private var currentTime: Double = 0.0

let disposeBag = DisposeBag()

private var timerInitTitle = UILabel().then {
$0.text = ""
$0.textAlignment = .center
$0.font = UIFont.Pretendard.bodyLarge
$0.textColor = .black
}

private var timerMainTitle = UILabel().then {
$0.text = ""
$0.textAlignment = .center
$0.font = UIFont.monospacedDigitSystemFont(ofSize: UIFont.Pretendard.light.pointSize, weight: .light)
$0.textColor = .black
}

private var timerAlarmTitle = UILabel().then {
$0.text = ""
$0.textAlignment = .center
$0.font = UIFont.Pretendard.bodyMedium
$0.textColor = DSKitAsset.Colors.gray400.color
}

public init(
center: CGPoint,
radius: Double,
Expand All @@ -52,49 +52,49 @@ public class HomeTimerView: UIView {
origin: CGPoint(x: center.x - CGFloat(radius), y: center.y - CGFloat(radius)),
size: CGSize(width: radius * 2, height: radius * 2))
)

self.colorCircle = color
self.radius = radius
self.backgroundColor = .clear

self.trackLayer = setTrackLayer()
self.layer.addSublayer(trackLayer)

self.circleShapeLayer = setCircleLayer()
self.layer.addSublayer(circleShapeLayer)

layout()
}

required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func layout() {
addSubviews([timerInitTitle, timerMainTitle, timerAlarmTitle])

timerInitTitle.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.height.equalTo(24.0)
$0.width.equalToSuperview()
$0.top.equalToSuperview().offset(89.0)
}

timerMainTitle.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.height.equalTo(64.0)
$0.width.equalToSuperview()
$0.top.equalTo(timerInitTitle.snp.bottom).offset(32.0)
}

timerAlarmTitle.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.height.equalTo(20.0)
$0.width.equalToSuperview()
$0.top.equalTo(timerMainTitle.snp.bottom).offset(32.0)
}
}

public func timerSetting(for seconds: Int) {
homeTimer.setting(count: Double(seconds))
initTime = Double(seconds)
Expand All @@ -105,7 +105,7 @@ public class HomeTimerView: UIView {
setTimerTimeLabel()
setInitAlarmTimeLabel()
}

private func setInitialTimeLabel() {
if cancelTime == 0 {
timerInitTitle.text = "0분"
Expand All @@ -116,7 +116,7 @@ public class HomeTimerView: UIView {
time[0] = initTimeInt / 3600
time[1] = (initTimeInt % 3600) / 60
time[2] = initTimeInt % 60

if time[0] > 0 && time[1] > 0 && time[2] > 0 {
timerInitTitle.text = "\(time[0])시간 \(time[1])분 \(time[2])초"
} else if time[0] > 0 && time[2] > 0 {
Expand All @@ -125,23 +125,23 @@ public class HomeTimerView: UIView {
timerInitTitle.text = "\(time[0])시간 \(time[1])분"
} else if time[0] > 0 {
timerInitTitle.text = "\(time[0])시간"
} else if time[1] > 0 && time[2] > 0{
} else if time[1] > 0 && time[2] > 0 {
timerInitTitle.text = "\(time[1])분 \(time[2])초"
} else if time[1] > 0 {
timerInitTitle.text = "\(time[1])분"
} else {
timerInitTitle.text = "\(time[2])초"
}
}

private func setTimerTimeLabel() {
if cancelTime == 0 {
timerMainTitle.text = "00 : 00"
return
}

timerMainTitle.text = setTimerTimeLabelText(from: homeTimer.presentTimer())

homeTimer.mainTimer.timeUpdate
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] timeString in
Expand All @@ -152,8 +152,7 @@ public class HomeTimerView: UIView {
})
.disposed(by: disposeBag)
}



private func setTimerTimeLabelText(from counter: Double) -> String {
let totalSeconds = Int(counter)
let hours: String = String(format: "%02d", totalSeconds / 3600)
Expand All @@ -168,33 +167,33 @@ public class HomeTimerView: UIView {
return "00 : \(seconds)"
}
}

private func setInitAlarmTimeLabel() {
if cancelTime == 0 {
timerAlarmTitle.text = ""
return
}
let formatter_time = DateFormatter()
formatter_time.dateFormat = "a h:mm"
formatter_time.amSymbol = "오전"
formatter_time.pmSymbol = "오후"
let current_time_string = formatter_time.string(from: Date().addingTimeInterval(initTime))
DispatchQueue.main.async {
self.timerAlarmTitle.text = current_time_string
}
// let formatter_time = DateFormatter()
// formatter_time.dateFormat = "a h:mm"
// formatter_time.amSymbol = "오전"
// formatter_time.pmSymbol = "오후"
// let current_time_string = formatter_time.string(from: Date().addingTimeInterval(initTime))
// DispatchQueue.main.async {
// self.timerAlarmTitle.text = current_time_string
// }
}

private func setAlarmTimeLabel() {
let formatter_time = DateFormatter()
formatter_time.dateFormat = "a h:mm"
formatter_time.amSymbol = "오전"
formatter_time.pmSymbol = "오후"
let current_time_string = formatter_time.string(from: Date().addingTimeInterval(homeTimer.presentTimer()))
DispatchQueue.main.async {
self.timerAlarmTitle.text = current_time_string
}
// let formatter_time = DateFormatter()
// formatter_time.dateFormat = "a h:mm"
// formatter_time.amSymbol = "오전"
// formatter_time.pmSymbol = "오후"
// let current_time_string = formatter_time.string(from: Date().addingTimeInterval(homeTimer.presentTimer()))
// DispatchQueue.main.async {
// self.timerAlarmTitle.text = current_time_string
// }
}

public func startTimer() -> Bool {
if homeTimer.presentTimer() == 0.0 {
return false
Expand All @@ -218,7 +217,7 @@ public class HomeTimerView: UIView {
stopCricleAnimation()
homeTimer.stopTimer()
}

public func cancelTimer() {
cancelTime = 0.0
homeTimer.setting(count: Double(0))
Expand All @@ -229,7 +228,7 @@ public class HomeTimerView: UIView {
setInitAlarmTimeLabel()
setInitialTimeLabel()
}

public func restartTimer() {
homeTimer.setting(count: Double(initTime))
cancelTime = initTime
Expand All @@ -239,7 +238,7 @@ public class HomeTimerView: UIView {
setAlarmTimeLabel()
setInitialTimeLabel()
}

public func currentTimer() -> Double {
return homeTimer.presentTimer()
}
Expand All @@ -254,7 +253,7 @@ public class HomeTimerView: UIView {
}
return circleLayer
}

private func setTrackLayer() -> CAShapeLayer {
let trackLayer = CAShapeLayer().then {
$0.path = setCirclePath()
Expand All @@ -265,13 +264,13 @@ public class HomeTimerView: UIView {
}
return trackLayer
}

private func stopCricleAnimation() {
let pausedTime = circleShapeLayer.convertTime(CACurrentMediaTime(), from: nil)
circleShapeLayer.speed = 0
circleShapeLayer.timeOffset = pausedTime
}

private func restartCricleAnimation() {
let pausedTime = circleShapeLayer.timeOffset
circleShapeLayer.speed = 1.0
Expand All @@ -280,18 +279,18 @@ public class HomeTimerView: UIView {
let timeSincePause = circleShapeLayer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
circleShapeLayer.beginTime = timeSincePause
}

private func setCirclePath() -> CGPath {
UIBezierPath(arcCenter: CGPoint(x: radius, y: radius),
radius: CGFloat(radius),
startAngle: -CGFloat.pi / 2,
endAngle: 2 * CGFloat.pi - CGFloat.pi / 2,
clockwise: true).cgPath
}

private func createCircleAnimation() -> CABasicAnimation {
let strokeAnimation = CABasicAnimation(keyPath: #keyPath(CAShapeLayer.strokeEnd))

strokeAnimation.toValue = 0
strokeAnimation.fromValue = 1
strokeAnimation.duration = CFTimeInterval(homeTimer.presentTimer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import RxSwift

open class MindGaGymKitTimer: NSObject, TimerControl {

private var initCounter: Double = 0.0
private var counter: Double = 0.0
private var timer: Timer?
Expand Down Expand Up @@ -49,11 +49,11 @@ open class MindGaGymKitTimer: NSObject, TimerControl {
let timeString = self.timeString(from: self.counter)
self.timerSubject.onNext(timeString)
}

public func presentTime() -> Double {
return self.counter
}

private func timeString(from counter: Double) -> String {
let totalSeconds = Int(counter)
let hours: String = String(format: "%02d", totalSeconds / 3600)
Expand All @@ -69,4 +69,3 @@ open class MindGaGymKitTimer: NSObject, TimerControl {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class MindGymTimerKit {
public func restartTimer() {
(mainTimer as? MindGaGymKitTimer)?.restart()
}

public func presentTimer() -> Double {
let presentTime: Double = mainTimer.presentTime()
return presentTime
Expand Down
Loading