Skip to content

Commit ed00454

Browse files
committed
Feat: Add SWColorPicker
body: SWColorPicker적용
1 parent 00986d4 commit ed00454

File tree

11 files changed

+129
-50
lines changed

11 files changed

+129
-50
lines changed

Podfile

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ target 'StopWatch' do
1010
pod 'Realm', '~>10'
1111
pod 'SnapKit', '~> 5.0.0'
1212
pod 'Then'
13+
pod 'SWColorPicker'
1314

1415

1516
end

Podfile.lock

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
PODS:
2-
- Realm (10.32.3):
3-
- Realm/Headers (= 10.32.3)
4-
- Realm/Headers (10.32.3)
5-
- RealmSwift (10.32.3):
6-
- Realm (= 10.32.3)
2+
- Realm (10.36.0):
3+
- Realm/Headers (= 10.36.0)
4+
- Realm/Headers (10.36.0)
5+
- RealmSwift (10.36.0):
6+
- Realm (= 10.36.0)
77
- SnapKit (5.0.1)
8+
- SWColorPicker (0.2.1)
89
- Then (3.0.0)
910

1011
DEPENDENCIES:
1112
- Realm (~> 10)
1213
- RealmSwift (~> 10)
1314
- SnapKit (~> 5.0.0)
15+
- SWColorPicker
1416
- Then
1517

1618
SPEC REPOS:
1719
trunk:
1820
- Realm
1921
- RealmSwift
2022
- SnapKit
23+
- SWColorPicker
2124
- Then
2225

2326
SPEC CHECKSUMS:
24-
Realm: fdf6732924dc5e69e30e0db2c11e869f92b53f3d
25-
RealmSwift: 7c181da8fa1c2fe613656a77c198d6a3dc3879a1
27+
Realm: 3fd136cb4c83a927482a7f1612496d37beed3cf5
28+
RealmSwift: 513d4dcbf5bfc4d573454088b592685fc48dd716
2629
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
30+
SWColorPicker: 1a4a4d1af47fe4f7b17920fe241eafb26e0a98e0
2731
Then: 844265ae87834bbe1147d91d5d41a404da2ec27d
2832

29-
PODFILE CHECKSUM: e11d3d0dab59434260704d9b3c3d22d602fd090d
33+
PODFILE CHECKSUM: 56b323a9a3fa37f4fbd1f8b46fb0580b052ae223
3034

3135
COCOAPODS: 1.11.3

StopWatch/Controllers/EditCategoryViewController.swift

+28-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import UIKit
88
import RealmSwift
99
import Then
1010
import SnapKit
11+
import SWColorPicker
1112

1213
final class EditCategoryViewController: UIViewController {
1314
//MARK: - Properties
@@ -75,6 +76,7 @@ final class EditCategoryViewController: UIViewController {
7576
self.setNavigationItem()
7677

7778
NotificationCenter.default.addObserver(self, selector: #selector(didRecieveCloseColorEditView(_:)), name: .closeColorEditView, object: nil)
79+
NotificationCenter.default.addObserver(self, selector: #selector(didClickColorWell), name: .presentColorPicker, object: nil)
7880

7981
self.saveDate = (UIApplication.shared.delegate as! AppDelegate).saveDate
8082
}
@@ -159,6 +161,18 @@ final class EditCategoryViewController: UIViewController {
159161
self.openEditColorView(.edit, palette: self.palette[row])
160162
}
161163

164+
@objc func didClickColorWell(_ notification: Notification) {
165+
if let color = notification.object as? UIColor {
166+
let vc = SWColorPickerViewController(color)
167+
vc.delegate = self
168+
self.present(vc, animated: true)
169+
} else {
170+
let vc = SWColorPickerViewController(.white)
171+
vc.delegate = self
172+
self.present(vc, animated: true)
173+
}
174+
}
175+
162176
//MARK: - EditColorViewMethod
163177
func openEditColorView(_ mode: ColorViewMode, palette: Palettes?) {
164178
guard self.editColorView == nil else { return } // 중복 뷰 방지
@@ -290,10 +304,22 @@ extension EditCategoryViewController: UICollectionViewDelegateFlowLayout {
290304
}
291305

292306
//MARK:- UITextFieldDelegate
293-
extension CategoryViewController: UITextFieldDelegate {
294-
307+
extension EditCategoryViewController: UITextFieldDelegate {
295308
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
296309
textField.resignFirstResponder()
297310
return true
298311
}
299312
}
313+
314+
extension EditCategoryViewController: SWColorPickerViewDelegate {
315+
func didSelectColor(_ color: UIColor) {
316+
var (r,g,b): (CGFloat,CGFloat,CGFloat) = (0,0,0)
317+
color.getRed(&r, green: &g, blue: &b, alpha: nil)
318+
let red = String(Int(r * 255), radix: 16).padding(toLength: 2, withPad: "0", startingAt: 0).uppercased()
319+
let green = String(Int(g * 255), radix: 16).padding(toLength: 2, withPad: "0", startingAt: 0).uppercased()
320+
let blue = String(Int(b * 255), radix: 16).padding(toLength: 2, withPad: "0", startingAt: 0).uppercased()
321+
let hexCode = red + green + blue
322+
323+
editColorView?.selectedColor(hexCode)
324+
}
325+
}

StopWatch/Controllers/StopWatchViewController.swift

+17-20
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ final class StopWatchViewController: UIViewController {
2727

2828
weak var delegate: StopWatchVCDelegate?
2929

30-
var saveDate: String = ""
31-
3230
private let guideLabelView = GuideLabelView()
3331
private let calendarView = CalendarView()
3432
private let goalTimeView = GoalTimeView()
@@ -92,13 +90,12 @@ final class StopWatchViewController: UIViewController {
9290
// gesture
9391
self.hideKeyboardWhenTapped()
9492

95-
// print("path = \(Realm.Configuration.defaultConfiguration.fileURL!)")
93+
// print("path = \(Realm.Configuration.defaultConfiguration.fileURL!)")
9694
}
9795

9896
override func viewWillAppear(_ animated: Bool) {
9997
super.viewWillAppear(animated)
10098
// 프로퍼티 값 갱신
101-
self.saveDate = (UIApplication.shared.delegate as! AppDelegate).resetDate //오늘 날짜!
10299

103100
self.setDeviceMotion() // coremotion 시작
104101
self.reloadProgressBar() // 진행바 재로딩
@@ -122,7 +119,7 @@ final class StopWatchViewController: UIViewController {
122119

123120
//MARK: - Method
124121
private func autoScrollCurrentDate(){ // 현재 날짜로 달력 스크롤
125-
let itemIndex = CalendarMethod().returnIndexOfDay(date: self.saveDate)
122+
let itemIndex = CalendarMethod().returnIndexOfDay(date: self.calendarView.selectDateComponent.stringFormat)
126123
self.calendarView.calendarView.scrollToItem(at: IndexPath(item: itemIndex - 1, section: 0), at: .left, animated: true)
127124
}
128125

@@ -171,9 +168,9 @@ final class StopWatchViewController: UIViewController {
171168
UIView.animate(withDuration: 0.3){
172169
self.editGoalTimeView!.transform = .identity
173170
}
174-
StopWatchDAO().create(date: self.saveDate) // 오늘 데이터가 없으면 데이터 생성
171+
StopWatchDAO().create(date: self.calendarView.selectDateComponent.stringFormat) // 오늘 데이터가 없으면 데이터 생성
175172

176-
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)!
173+
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)!
177174
let goal = dailyData.totalGoalTime
178175
let hourIndex = Int(goal / 3600) % 24 // 3600초 (1시간)으로 나눈 몫을 24로 나누면 시간 인덱스와 같다.
179176
let miniuteIndex = ((Int(goal) % 3600 ) / 60) / 5 // 남은 분을 5로 나누면 5분간격의 분 인덱스와 같다.
@@ -190,7 +187,7 @@ final class StopWatchViewController: UIViewController {
190187
UIView.animate(withDuration: 0.5,animations: {
191188
_editGoalTimeView.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height)
192189
}){_ in
193-
StopWatchDAO().deleteDailyData(date: self.saveDate)
190+
StopWatchDAO().deleteDailyData(date: self.calendarView.selectDateComponent.stringFormat)
194191
_editGoalTimeView.removeFromSuperview()
195192
self.editGoalTimeView = nil
196193
self.removeTapGesture()
@@ -225,7 +222,7 @@ final class StopWatchViewController: UIViewController {
225222
if self.chartView != nil { return }
226223

227224
self.chartView = ChartView().then {
228-
$0.saveDate = self.saveDate
225+
$0.saveDate = self.calendarView.selectDateComponent.stringFormat
229226

230227
self.frameView.addSubview($0)
231228
$0.snp.makeConstraints { make in
@@ -338,15 +335,14 @@ final class StopWatchViewController: UIViewController {
338335

339336
@objc func didChangeSaveDate(_ notification: Notification) {
340337
if let saveDate = notification.userInfo?["selectedDate"] as? String {
341-
self.saveDate = saveDate
338+
self.chartView?.saveDate = saveDate
342339
}
343340

344341
self.setGoalTime() // 목표시간 Label 재설정
345342
self.reloadProgressBar() // 진행바 재로딩
346343
self.setTimeLabel() // 현재시간 Label 재설정
347344
self.toDoTableView.reloadData()
348345
self.calendarView.calendarView.reloadData()
349-
self.chartView?.saveDate = self.saveDate
350346
self.chartView?.setNeedsDisplay() // 차트 다시 그리기
351347
}
352348

@@ -361,7 +357,7 @@ final class StopWatchViewController: UIViewController {
361357
// 목표 시간 설정 뷰 닫기
362358
@objc func didFinishEditingGoalTime(_ sender: UIButton){
363359
if sender.tag == 1 { // 확인버튼
364-
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)
360+
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)
365361
try! self.realm.write{
366362
dailyData!.totalGoalTime =
367363
self.editGoalTimeView!.selectedHour + self.editGoalTimeView!.selectedMinute
@@ -391,9 +387,9 @@ final class StopWatchViewController: UIViewController {
391387

392388
//세션(과목명)을 눌렀을때 호출되는 메소드
393389
@objc func didClickSection(_ sender: UIButton){
394-
StopWatchDAO().create(date: self.saveDate) // 오늘 데이터가 없으면 데이터 생성
390+
StopWatchDAO().create(date: self.calendarView.selectDateComponent.stringFormat) // 오늘 데이터가 없으면 데이터 생성
395391

396-
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)!
392+
let dailyData = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)!
397393

398394
let segments = dailyData.dailySegment // 오늘 과목들
399395
let section = sender.tag
@@ -622,9 +618,9 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
622618
}
623619

624620
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
625-
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)
621+
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)
626622
let segment = filter?.dailySegment
627-
StopWatchDAO().checkSegmentData(date: self.saveDate)
623+
StopWatchDAO().checkSegmentData(date: self.calendarView.selectDateComponent.stringFormat)
628624
return segment?[section].toDoList.count ?? 0 // 오늘의 리스트가 없으면 0개
629625
}
630626

@@ -706,7 +702,7 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
706702
// 마지막 섹션에 문구 출력
707703
if section == (categoryCount - 1) {
708704
// 오늘의 데이터가 nil일때
709-
guard let category = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate) else { return guideText }
705+
guard let category = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat) else { return guideText }
710706

711707
var sum = 0 // todolist 합
712708

@@ -726,7 +722,7 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
726722
extension StopWatchViewController: UITextFieldDelegate {
727723
//입력이 끝나면 호출되는 델리게이트메소드
728724
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) {
729-
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)
725+
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)
730726
let segment = filter!.dailySegment
731727

732728
let row = segment[textField.tag].toDoList.count - 1
@@ -736,7 +732,7 @@ extension StopWatchViewController: UITextFieldDelegate {
736732
segment[textField.tag].toDoList.remove(at: row)
737733
segment[textField.tag].listCheckImageIndex.remove(at: row)
738734
}
739-
StopWatchDAO().deleteDailyData(date: self.saveDate)
735+
StopWatchDAO().deleteDailyData(date: self.calendarView.selectDateComponent.stringFormat)
740736

741737
}else {
742738
try! self.realm.write{
@@ -754,7 +750,7 @@ extension StopWatchViewController: UITextFieldDelegate {
754750
}
755751

756752
func textFieldDidChangeSelection(_ textField: UITextField) {
757-
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.saveDate)
753+
let filter = self.realm.object(ofType: DailyData.self, forPrimaryKey: self.calendarView.selectDateComponent.stringFormat)
758754
let segment = filter!.dailySegment
759755

760756
let row = segment[textField.tag].toDoList.count - 1
@@ -821,3 +817,4 @@ extension StopWatchViewController {
821817
}
822818
}
823819
}
820+
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "[email protected]",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "[email protected]",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"filename" : "[email protected]",
15+
"idiom" : "universal",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"author" : "xcode",
21+
"version" : 1
22+
}
23+
}

StopWatch/Utils/extension/NotificationName+.swift

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ extension Notification.Name {
1212
static let presentAlert = Notification.Name("presentAlert")
1313
static let changeSaveDate = Notification.Name("changeSaveDate")
1414
static let closeColorEditView = Notification.Name("closeColorEditView")
15+
static let presentColorPicker = Notification.Name("presentColorPicker")
1516
}

StopWatch/Views/CalendarView/CalendarView.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ final class CalendarView: UIView,UICollectionViewDelegate, UICollectionViewDataS
8080
$0.showsHorizontalScrollIndicator = false
8181
$0.isPagingEnabled = true // 페이징 스크롤 처리
8282
$0.tag = 1
83+
$0.clipsToBounds = false
8384
}
8485

8586
return view
@@ -264,7 +265,7 @@ final class CalendarView: UIView,UICollectionViewDelegate, UICollectionViewDataS
264265
} else { // 기본 캘린더일 경우
265266
NotificationCenter.default.post(name: .changeSaveDate,
266267
object: nil,
267-
userInfo: ["selectedDate" : calendarMethod.componentToDateString(self.selectDateComponent)])
268+
userInfo: ["selectedDate" : self.selectDateComponent.stringFormat])
268269
}
269270
}
270271
}

0 commit comments

Comments
 (0)