Commit 4e9f7a95 by Demid Merzlyakov

Today image based on weather conditions.

parent f727e544
......@@ -211,6 +211,7 @@
CE849DB82638C33600DEFFBD /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE849DB72638C33600DEFFBD /* NotificationService.swift */; };
CE849DBC2638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
CE849E382638CE8000DEFFBD /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE849E372638CE8000DEFFBD /* UserNotifications.framework */; };
CE895F0F26393FD800214175 /* WeatherImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE895F0E26393FD800214175 /* WeatherImageProvider.swift */; };
CE89628C26175D8D00CA274A /* regenerate_objects.sh in Resources */ = {isa = PBXBuildFile; fileRef = CE89628B26175D8D00CA274A /* regenerate_objects.sh */; };
CE8962A226175DF500CA274A /* _CoreAirQuality.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE89629126175DF400CA274A /* _CoreAirQuality.swift */; };
CE8962A426175DF500CA274A /* _CorePollutant.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE89629326175DF400CA274A /* _CorePollutant.swift */; };
......@@ -529,6 +530,7 @@
CE849DB92638C33600DEFFBD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CE849DE82638C59800DEFFBD /* OneWeatherNotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OneWeatherNotificationServiceExtension.entitlements; sourceTree = "<group>"; };
CE849E372638CE8000DEFFBD /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
CE895F0E26393FD800214175 /* WeatherImageProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherImageProvider.swift; sourceTree = "<group>"; };
CE89628B26175D8D00CA274A /* regenerate_objects.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = regenerate_objects.sh; sourceTree = "<group>"; };
CE89629126175DF400CA274A /* _CoreAirQuality.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CoreAirQuality.swift; sourceTree = "<group>"; };
CE89629326175DF400CA274A /* _CorePollutant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CorePollutant.swift; sourceTree = "<group>"; };
......@@ -1449,6 +1451,7 @@
CEF959A526035A2600975FAA /* DeviceLocationMonitor.swift */,
CD37D3EA260DD30F002669D6 /* Settings.swift */,
CE6BE4932634170800626822 /* USStateCode.swift */,
CE895F0E26393FD800214175 /* WeatherImageProvider.swift */,
);
path = Model;
sourceTree = "<group>";
......@@ -2043,6 +2046,7 @@
CD8B60AC263819400055CB3F /* NWSForecastOfficeTableViewCell.swift in Sources */,
CE9F01B8261B2DB6009BA500 /* _CoreAppData.swift in Sources */,
CDE18DCD25D1666700C80ED9 /* ForecastCoordinator.swift in Sources */,
CE895F0F26393FD800214175 /* WeatherImageProvider.swift in Sources */,
CDC6126625E9085600188DA7 /* GraphLine.swift in Sources */,
CE13B98726273236007CBD4D /* NWSAlert.swift in Sources */,
CE13B819262480B3007CBD4D /* A9Cache.swift in Sources */,
......
//
// WeatherImageProvider.swift
// 1Weather
//
// Created by Demid Merzlyakov on 28.04.2021.
//
import UIKit
class WeatherImageProvider {
private enum DefaultImage: String {
case partlyCloudyNight = "default_weather_partly_cloudy_night"
case cloudyNight = "default_weather_cloudy_night"
case rain = "default_weather_rain"
case fogDay = "default_weather_fog_day"
case smoky = "default_weather_smoky"
case fogNight = "default_weather_fog_night"
case snowDay = "default_weather_snow_day"
case haze = "default_weather_haze"
case snowNight = "default_weather_snow_night"
case mostlyCloudyDay = "default_weather_mostly_cloudy_day"
case sunnyDay = "default_weather_sunny_day"
case partlyCloudyDay = "default_weather_partly_cloudy_day"
case thunderstorm = "default_weather_thunderstorm"
var image: UIImage {
guard let result = UIImage(named: self.rawValue) else {
fatalError("Should never happen. Please check all the image names and that they are loaded in assets correctly")
#if !DEBUG
return UIImage()
#endif
}
return result
}
}
public func imageFor(location: Location) -> UIImage {
let isDay = location.today?.isDay ?? true
var image: DefaultImage
let weatherType = location.today?.type ?? .unknown
switch weatherType {
case .clear:
image = .sunnyDay
case .partlyCloudy:
image = isDay ? .partlyCloudyDay : .partlyCloudyNight
case .snowy:
image = isDay ? .snowDay : .snowNight
case .mostlyCloudy:
image = .mostlyCloudyDay
case .thunderstorm:
image = .thunderstorm
case .heavySnow:
image = isDay ? .snowDay : .snowNight
case .lightSnow:
image = isDay ? .snowDay : .snowNight
case .freezingRain:
image = .rain
case .freezingFog:
image = isDay ? .fogDay : .fogNight
case .lightHail:
image = .rain
case .blowingDust:
image = .haze
case .haze:
image = .haze
case .lightFog:
image = isDay ? .fogDay : .fogNight
case .lightDrizzle:
image = .rain
case .heavyRain:
image = .rain
case .smoke:
image = .smoky
case .unknown:
image = .sunnyDay
}
return image.image
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "paoloChiabrando7UgugPemmhyUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "paoloChiabrando7UgugPemmhyUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "paoloChiabrando7UgugPemmhyUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "default_weather_fog_day.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "default_weather_fog_day@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "default_weather_fog_day@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "johnyGoerendCOhQq5BzAcYUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "johnyGoerendCOhQq5BzAcYUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "johnyGoerendCOhQq5BzAcYUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "jaleelAkbashSlh0Tx1MrnaUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "jaleelAkbashSlh0Tx1MrnaUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "jaleelAkbashSlh0Tx1MrnaUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "cassieBocaEiGCgdLdC8UnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "cassieBocaEiGCgdLdC8UnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "cassieBocaEiGCgdLdC8UnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "kyawTunEcuErgxbAy0UnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "kyawTunEcuErgxbAy0UnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "kyawTunEcuErgxbAy0UnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "aralTasherNjMi2OFoQqQUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "aralTasherNjMi2OFoQqQUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "aralTasherNjMi2OFoQqQUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "tristanGevauxKRllFkZpTmmUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "tristanGevauxKRllFkZpTmmUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "tristanGevauxKRllFkZpTmmUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "staffanKjellvestadY1QOt82Fd8KUnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "staffanKjellvestadY1QOt82Fd8KUnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "staffanKjellvestadY1QOt82Fd8KUnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "default_weather_snow_day.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "default_weather_snow_day@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "default_weather_snow_day@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "default_weather_snow_night.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "default_weather_snow_night@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "default_weather_snow_night@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "default_weather_sunny_day.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "default_weather_sunny_day@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "default_weather_sunny_day@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "noaaP9Brx1MBfe4UnsplashCopy.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "noaaP9Brx1MBfe4UnsplashCopy@2x.jpg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "noaaP9Brx1MBfe4UnsplashCopy@3x.jpg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -41,7 +41,7 @@ class TodayForecastCell: UITableViewCell {
//Public
public func configure(with location:Location) {
cityImageView.image = UIImage(named: location.imageName ?? "")
cityImageView.image = WeatherImageProvider().imageFor(location: location)
temperatureLabel.text = location.today?.temp?.settingsConverted.shortString
let maxTemp = location.today?.maxTemp?.settingsConverted.shortString ?? "--"
let minTemp = location.today?.minTemp?.settingsConverted.shortString ?? "--"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment