Skip to content

Commit

Permalink
[Feat] Stopwatch: 기록날짜 불일치시 경고 로직 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
minsangKang committed May 27, 2022
1 parent 8311382 commit 0d5b902
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Project_Timer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 6.5.1;
MARKETING_VERSION = 6.5.2;
PRODUCT_BUNDLE_IDENTIFIER = com.FDEE.TiTi;
PRODUCT_NAME = TiTi;
SUPPORTS_MACCATALYST = YES;
Expand All @@ -736,7 +736,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 6.5.1;
MARKETING_VERSION = 6.5.2;
PRODUCT_BUNDLE_IDENTIFIER = com.FDEE.TiTi;
PRODUCT_NAME = TiTi;
SUPPORTS_MACCATALYST = YES;
Expand Down
25 changes: 22 additions & 3 deletions Project_Timer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,22 @@
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" alpha="0.0" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zHl-6H-tfo">
<rect key="frame" x="199.66666666666666" y="53" width="32" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="32" id="J11-uU-Lrm"/>
<constraint firstAttribute="height" constant="32" id="wkO-KG-mkS"/>
</constraints>
<color key="tintColor" name="Text"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="exclamationmark.circle" catalog="system">
<preferredSymbolConfiguration key="preferredSymbolConfiguration" configurationType="pointSize" pointSize="13" weight="semibold"/>
</state>
<connections>
<action selector="showRecordDateAlert:" destination="oQm-sw-2wm" eventType="touchUpInside" id="1gV-6A-pln"/>
<action selector="showRecordDateAlert:" destination="uTZ-Xd-FDk" eventType="touchUpInside" id="r2F-HX-hbA"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="yCZ-3D-BLQ"/>
<color key="backgroundColor" name="Background2"/>
Expand All @@ -658,11 +674,13 @@
<constraint firstItem="nRK-jy-UJa" firstAttribute="centerX" secondItem="yCZ-3D-BLQ" secondAttribute="centerX" id="FaX-mt-MMY"/>
<constraint firstItem="rzE-75-v4U" firstAttribute="centerY" secondItem="ujV-QO-P1Y" secondAttribute="centerY" id="FcF-vb-Ssx"/>
<constraint firstItem="Hfx-iS-Kvh" firstAttribute="centerY" secondItem="nRK-jy-UJa" secondAttribute="centerY" id="H7n-Vz-6gJ"/>
<constraint firstItem="zHl-6H-tfo" firstAttribute="leading" secondItem="nRK-jy-UJa" secondAttribute="trailing" constant="-5" id="KJK-D6-U80"/>
<constraint firstItem="rzE-75-v4U" firstAttribute="centerX" secondItem="yCZ-3D-BLQ" secondAttribute="centerX" id="Mv3-R4-L8P"/>
<constraint firstItem="qOs-fm-jq5" firstAttribute="centerX" secondItem="yCZ-3D-BLQ" secondAttribute="centerX" id="NQX-fB-w0a"/>
<constraint firstItem="qOs-fm-jq5" firstAttribute="leading" secondItem="diS-gV-uEz" secondAttribute="trailing" constant="25" id="Rvk-cQ-x1q"/>
<constraint firstItem="qOs-fm-jq5" firstAttribute="top" secondItem="rzE-75-v4U" secondAttribute="bottom" constant="50" id="STX-BM-U7e"/>
<constraint firstItem="4jf-oH-8Jq" firstAttribute="leading" secondItem="qOs-fm-jq5" secondAttribute="trailing" constant="25" id="Xax-vO-yAl"/>
<constraint firstItem="zHl-6H-tfo" firstAttribute="centerY" secondItem="nRK-jy-UJa" secondAttribute="centerY" id="Y8A-px-rxo"/>
<constraint firstItem="rzE-75-v4U" firstAttribute="centerY" secondItem="ujV-QO-P1Y" secondAttribute="centerY" id="ZDw-gQ-0Rw"/>
<constraint firstItem="VkP-ZL-Ulq" firstAttribute="centerX" secondItem="qOs-fm-jq5" secondAttribute="centerX" id="g7d-rL-IXZ"/>
<constraint firstItem="4jf-oH-8Jq" firstAttribute="centerY" secondItem="qOs-fm-jq5" secondAttribute="centerY" id="r9Q-P2-FTV"/>
Expand Down Expand Up @@ -698,6 +716,7 @@
<outlet property="targetTimeLabel" destination="FTo-xw-CXf" id="BPc-gB-prr"/>
<outlet property="taskButton" destination="gEt-rS-lNf" id="6Zg-9Y-grc"/>
<outlet property="todayLabel" destination="nRK-jy-UJa" id="R5X-lK-yO9"/>
<outlet property="warningRecordDate" destination="zHl-6H-tfo" id="Tx2-KV-9Fp"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bzB-XJ-Egh" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -2187,18 +2206,18 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wmi-uK-Eee">
<rect key="frame" x="31.666666666666671" y="0.0" width="127.00000000000001" height="20"/>
<subviews>
<view alpha="0.5" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ssj-HI-VEv">
<view alpha="0.5" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ssj-HI-VEv">
<rect key="frame" x="2.3333333333333286" y="1.6666666666666661" width="76" height="17"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Swift 프로그래밍" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qk5-hC-CrC">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Swift 프로그래밍" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qk5-hC-CrC">
<rect key="frame" x="5" y="3.333333333333333" width="71" height="13.333333333333336"/>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="95" id="AL5-WL-sbA"/>
</constraints>
<fontDescription key="fontDescription" name="HGGGothicssiP60g" family="HGGGothicssi_Pro" pointSize="10.5"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="12:59:59" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TZj-4u-8my">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="12:59:59" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TZj-4u-8my">
<rect key="frame" x="81" y="2.666666666666667" width="41" height="14.666666666666664"/>
<fontDescription key="fontDescription" name="HGGGothicssiP80g" family="HGGGothicssi_Pro" pointSize="12"/>
<color key="textColor" name="CCC1"/>
Expand Down
10 changes: 10 additions & 0 deletions Project_Timer/Stopwatch/StopwatchVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class StopwatchVM {
@Published private(set) var daily: Daily
@Published private(set) var task: String
@Published private(set) var runningUI = false
@Published private(set) var warningNewDate = false
private(set) var timerRunning = false
private var timerCount: Int = 0
private let userNotificationCenter = UNUserNotificationCenter.current()
Expand All @@ -30,6 +31,8 @@ final class StopwatchVM {
if RecordController.shared.recordTimes.recording {
print("automatic start")
self.timerStart()
} else {
self.checkRecordDate()
}
}

Expand All @@ -43,6 +46,13 @@ final class StopwatchVM {
}
}

private func checkRecordDate() {
let today = Date().YYYYMMDDstyleString
if today != self.daily.day.YYYYMMDDstyleString {
self.warningNewDate = true
}
}

var settedGoalTime: Int {
return RecordController.shared.recordTimes.settedGoalTime
}
Expand Down
35 changes: 35 additions & 0 deletions Project_Timer/Stopwatch/StopwatchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class StopwatchViewController: UIViewController {
@IBOutlet var settingBT: UIButton!
@IBOutlet weak var colorSelector: UIButton!
@IBOutlet weak var todayLabel: UILabel!
@IBOutlet weak var warningRecordDate: UIButton!

var COLOR = UIColor(named: "Background2")
let RED = UIColor(named: "Text")
Expand Down Expand Up @@ -88,6 +89,12 @@ final class StopwatchViewController: UIViewController {
@IBAction func colorSelect(_ sender: Any) {
self.showColorSelectVC()
}

@IBAction func showRecordDateAlert(_ sender: Any) {
self.showAlertWithAction(title: "Check the date of recording".localized(), text: "Do you want to start the New record?".localized()) { [weak self] in
self?.showSettingView()
}
}
}

// MARK: - Configure
Expand Down Expand Up @@ -119,6 +126,9 @@ extension StopwatchViewController {
NotificationCenter.default.addObserver(self, selector: #selector(pauseWhenBackground(noti:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(noti:)), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(deviceRotated), name: UIDevice.orientationDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(forName: .removeNewRecordWarning, object: nil, queue: .main) { [weak self] _ in
self?.hideWarningRecordDate()
}
}
private func configureViewModel() {
self.viewModel = StopwatchVM()
Expand Down Expand Up @@ -158,6 +168,7 @@ extension StopwatchViewController {
self.bindDaily()
self.bindTask()
self.bindUI()
self.bindWaringNewDate()
}
private func bindTimes() {
self.viewModel?.$times
Expand Down Expand Up @@ -200,6 +211,15 @@ extension StopwatchViewController {
})
.store(in: &self.cancellables)
}
private func bindWaringNewDate() {
self.viewModel?.$warningNewDate
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] warning in
guard warning else { return }
self?.showWarningRecordDate()
})
.store(in: &self.cancellables)
}
}

// MARK: - logic
Expand Down Expand Up @@ -320,6 +340,20 @@ extension StopwatchViewController {
print("stopwatch: \(times.stopwatch.toTimeString)")
print("goal: \(times.goal.toTimeString)")
}

private func showWarningRecordDate() {
UIView.animate(withDuration: 0.15) {
self.warningRecordDate.alpha = 1
self.todayLabel.textColor = self.RED!
}
}

private func hideWarningRecordDate() {
UIView.animate(withDuration: 0.15) {
self.warningRecordDate.alpha = 0
self.todayLabel.textColor = .white
}
}
}

// MARK: - Rotation
Expand Down Expand Up @@ -373,6 +407,7 @@ extension StopwatchViewController: NewRecordCreatable {
func newRecord() {
self.configureColor()
self.viewModel?.newRecord()
self.hideWarningRecordDate()
}
}

Expand Down

0 comments on commit 0d5b902

Please sign in to comment.