Skip to content

Commit

Permalink
[#22] 로티 시간대별 조정
Browse files Browse the repository at this point in the history
  • Loading branch information
ezidayzi committed Aug 18, 2021
1 parent 28695fd commit 28e943a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Apple-Weather/Apple-Weather.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -74,6 +75,7 @@
DD81B2DC26C0E8EE00268F8A /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = "<group>"; };
DD873C3126B05A07003857A0 /* DailyWeatherCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyWeatherCollectionViewCell.swift; sourceTree = "<group>"; };
DD894AA326C8FC580057F7C7 /* WeatherService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherService.swift; sourceTree = "<group>"; };
DD8F39D826CCF9570094799A /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = "<group>"; };
DD8FAF3A26C246A300158C31 /* APIService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIService.swift; sourceTree = "<group>"; };
DD8FAF3C26C24B6800158C31 /* WeatherAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherAPI.swift; sourceTree = "<group>"; };
DD8FAF3E26C24D4300158C31 /* MoyaLoggingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggingPlugin.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -217,6 +219,7 @@
DD94BE8B26BEAEBB0042CA59 /* UILabel+Extension.swift */,
DD94BE9826BED1600042CA59 /* String+Extension.swift */,
DD81B2DC26C0E8EE00268F8A /* UIViewController+Extension.swift */,
DD8F39D826CCF9570094799A /* Date+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -83,6 +81,8 @@ class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
initMainTableView()

setLottieView()
setLayoutMainViewController()
setTargets()
setButton()
Expand All @@ -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 {
Expand Down

0 comments on commit 28e943a

Please sign in to comment.