From 28e943a503b9fdcd5c4df2688515f54fe27365c1 Mon Sep 17 00:00:00 2001 From: Yoonseo Kim Date: Wed, 18 Aug 2021 18:33:17 +0900 Subject: [PATCH] =?UTF-8?q?[#22]=20=E1=84=85=E1=85=A9=E1=84=90=E1=85=B5=20?= =?UTF-8?q?=E1=84=89=E1=85=B5=E1=84=80=E1=85=A1=E1=86=AB=E1=84=83=E1=85=A2?= =?UTF-8?q?=E1=84=87=E1=85=A7=E1=86=AF=20=E1=84=8C=E1=85=A9=E1=84=8C?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Apple-Weather.xcodeproj/project.pbxproj | 4 ++ .../Sources/Extensions/Date+Extension.swift | 55 +++++++++++++++++++ .../UIViewController+Extension.swift | 17 ++++++ .../MainPageViewController.swift | 2 +- .../ViewControllers/MainViewController.swift | 14 +++-- 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 Apple-Weather/Apple-Weather/Sources/Extensions/Date+Extension.swift diff --git a/Apple-Weather/Apple-Weather.xcodeproj/project.pbxproj b/Apple-Weather/Apple-Weather.xcodeproj/project.pbxproj index c485676..9cb83c3 100644 --- a/Apple-Weather/Apple-Weather.xcodeproj/project.pbxproj +++ b/Apple-Weather/Apple-Weather.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ DD81B2DD26C0E8EE00268F8A /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD81B2DC26C0E8EE00268F8A /* UIViewController+Extension.swift */; }; DD873C3226B05A07003857A0 /* DailyWeatherCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD873C3126B05A07003857A0 /* DailyWeatherCollectionViewCell.swift */; }; DD894AA426C8FC580057F7C7 /* WeatherService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD894AA326C8FC580057F7C7 /* WeatherService.swift */; }; + DD8F39D926CCF9570094799A /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8F39D826CCF9570094799A /* Date+Extension.swift */; }; DD8FAF3B26C246A300158C31 /* APIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8FAF3A26C246A300158C31 /* APIService.swift */; }; DD8FAF3D26C24B6800158C31 /* WeatherAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8FAF3C26C24B6800158C31 /* WeatherAPI.swift */; }; DD8FAF3F26C24D4300158C31 /* MoyaLoggingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8FAF3E26C24D4300158C31 /* MoyaLoggingPlugin.swift */; }; @@ -74,6 +75,7 @@ DD81B2DC26C0E8EE00268F8A /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = ""; }; DD873C3126B05A07003857A0 /* DailyWeatherCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyWeatherCollectionViewCell.swift; sourceTree = ""; }; DD894AA326C8FC580057F7C7 /* WeatherService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherService.swift; sourceTree = ""; }; + DD8F39D826CCF9570094799A /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = ""; }; DD8FAF3A26C246A300158C31 /* APIService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIService.swift; sourceTree = ""; }; DD8FAF3C26C24B6800158C31 /* WeatherAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherAPI.swift; sourceTree = ""; }; DD8FAF3E26C24D4300158C31 /* MoyaLoggingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggingPlugin.swift; sourceTree = ""; }; @@ -217,6 +219,7 @@ DD94BE8B26BEAEBB0042CA59 /* UILabel+Extension.swift */, DD94BE9826BED1600042CA59 /* String+Extension.swift */, DD81B2DC26C0E8EE00268F8A /* UIViewController+Extension.swift */, + DD8F39D826CCF9570094799A /* Date+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -468,6 +471,7 @@ DD6C72D826BD582400EE278A /* LocationTableViewCell.swift in Sources */, DD94BE8F26BEB01D0042CA59 /* MainWeatherModel.swift in Sources */, DD81B2DD26C0E8EE00268F8A /* UIViewController+Extension.swift in Sources */, + DD8F39D926CCF9570094799A /* Date+Extension.swift in Sources */, DDD3F2F326AC3C2400FD547A /* MainPageViewController.swift in Sources */, DD65D01E26B12223008BEF79 /* WeekWeatherTableviewCell.swift in Sources */, DD8FD3A626AF0F8D0005D84D /* Constant.swift in Sources */, diff --git a/Apple-Weather/Apple-Weather/Sources/Extensions/Date+Extension.swift b/Apple-Weather/Apple-Weather/Sources/Extensions/Date+Extension.swift new file mode 100644 index 0000000..2796f2a --- /dev/null +++ b/Apple-Weather/Apple-Weather/Sources/Extensions/Date+Extension.swift @@ -0,0 +1,55 @@ +// +// Date+Extension.swift +// Apple-Weather +// +// Created by 김윤서 on 2021/08/18. +// + +import Foundation + +extension Date { + func setLottieImage(_ timezone: Int) -> String { + let date = DateFormatter() + date.locale = Locale(identifier: "ko_kr") + date.timeZone = TimeZone(secondsFromGMT: timezone) + date.dateFormat = "HH" + + let hour = Int(date.string(from: self))! + + switch hour { + case 6..<17 : + return "4800-weather-partly-cloudy" + case 17..<22 : + return "4796-weather-cloudynight" + default: + return "4796-weather-cloudynight" + } + } + + func isNight(_ timezone: Int) -> Bool { + + let date = DateFormatter() + date.locale = Locale(identifier: "ko_kr") + date.timeZone = TimeZone(secondsFromGMT: timezone) + + let hour = Calendar.current.component(.hour, from: date.date(from: date.string(from: self)) ?? Date()) + + switch hour { + case 6..<17 : + return false + case 17..<22 : + return true + default: + return true + } + } + + func getCurrentTime(_ timezone: Int) -> String { + let date = DateFormatter() + date.locale = Locale(identifier: "ko_kr") + date.timeZone = TimeZone(secondsFromGMT: timezone) + date.dateFormat = "HH:mm" + + return date.string(from: self) + } +} diff --git a/Apple-Weather/Apple-Weather/Sources/Extensions/UIViewController+Extension.swift b/Apple-Weather/Apple-Weather/Sources/Extensions/UIViewController+Extension.swift index d0928fe..3e17f0e 100644 --- a/Apple-Weather/Apple-Weather/Sources/Extensions/UIViewController+Extension.swift +++ b/Apple-Weather/Apple-Weather/Sources/Extensions/UIViewController+Extension.swift @@ -12,4 +12,21 @@ extension UIViewController { let presentingIsModal = presentingViewController != nil return presentingIsModal } + + func setLottieImage(_ timezone: Int) -> String { + let date = DateFormatter() + date.locale = Locale(identifier: "ko_kr") + date.timeZone = TimeZone(secondsFromGMT: timezone) + date.dateFormat = "HH" + + let hour = Int(date.string(from: Date()))! + + if hour >= 18 || hour <= 5 { + return "4796-weather-cloudynight" + } else { + return "4800-weather-partly-cloudy" + } + + } + } diff --git a/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainPageViewController.swift b/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainPageViewController.swift index 431bb79..63963e1 100644 --- a/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainPageViewController.swift +++ b/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainPageViewController.swift @@ -51,7 +51,7 @@ class MainPageViewController: UIViewController { } private func setLayoutPageViewController() { - view.backgroundColor = UIColor(red: 0 / 255, green: 0 / 255, blue: 45 / 255, alpha: 1) + view.backgroundColor = .black pageViewController.dataSource = self pageViewController.delegate = self diff --git a/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainViewController.swift b/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainViewController.swift index 593efe4..5887619 100644 --- a/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainViewController.swift +++ b/Apple-Weather/Apple-Weather/Sources/ViewControllers/MainViewController.swift @@ -61,9 +61,7 @@ class MainViewController: UIViewController { $0.spacing = 10 } - private let lottieView = AnimationView(name: "4796-weather-cloudynight").then { animationView in - animationView.play() - } + private var lottieView = AnimationView(name: "4796-weather-cloudynight") private let dismissButton = UIButton().then { $0.setTitle("취소", for: .normal) @@ -83,6 +81,8 @@ class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() initMainTableView() + + setLottieView() setLayoutMainViewController() setTargets() setButton() @@ -96,13 +96,19 @@ class MainViewController: UIViewController { dismissButton.isHidden = !isModal } + private func setLottieView() { + lottieView = .init(name: self.setLottieImage(weather?.timezonwOffset ?? 0)) + } + private func setTargets() { dismissButton.addTarget(self, action: #selector(tapButton(_:)), for: .touchUpInside) addButton.addTarget(self, action: #selector(tapButton(_:)), for: .touchUpInside) } private func setLayoutMainViewController() { - view.backgroundColor = UIColor(red: 0 / 255, green: 0 / 255, blue: 45 / 255, alpha: 1) + + view.backgroundColor = .black + view.addSubviews(lottieView, locationStackView, mainTableView, dismissButton, addButton) lottieView.snp.makeConstraints {