Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
c4d1d047
Commit
c4d1d047
authored
Mar 10, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Day / Night support for weather type.
parent
76f74ba9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
69 deletions
+33
-69
1Weather/Model/HelperTypes.swift
+24
-52
1Weather/Network/Model/HelperObjects/WdtWeatherCode.swift
+5
-13
1Weather/UI/View controllers/Today/Cells/CityDayTimesCell/DayTimeView.swift
+1
-1
1Weather/UI/View controllers/Today/Cells/CityForecastCell.swift
+2
-2
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/PeriodForecastButton.swift
+1
-1
No files found.
1Weather/Model/HelperTypes.swift
View file @
c4d1d047
...
...
@@ -6,14 +6,13 @@
//
import
Foundation
import
UIKit
public
enum
WeatherType
:
String
,
CaseIterable
{
case
clearDay
=
"clearDay"
case
partlyCloudyDay
=
"partlyCloudyDay"
case
snowyDay
=
"snowyDay"
case
snowyNight
=
"snowyNight"
case
clearNight
=
"clearNight"
case
partlyCloudyNight
=
"partlyCloudyNight"
case
clear
=
"clear"
case
partlyCloudy
=
"partlyCloudy"
case
snowy
=
"snowy"
case
mostlyCloudy
=
"mostlyCloudy"
case
thunderstorm
=
"thunderstorm"
case
heavySnow
=
"heavySnow"
case
lightSnow
=
"lightSnow"
...
...
@@ -23,58 +22,31 @@ public enum WeatherType: String, CaseIterable {
case
blowingDust
=
"blowingDust"
case
haze
=
"haze"
case
lightFog
=
"lightFog"
case
mostlyCloudyDay
=
"mostlyCloudyDay"
case
mostlyCloudyNight
=
"mostlyCloudyNight"
case
lightDrizzle
=
"lightDrizzle"
case
heavyRain
=
"heavyRain"
case
smoke
=
"smoke"
case
unknown
=
"unknown"
var
localized
:
String
{
switch
self
{
case
.
clearDay
:
return
"forecast.clear"
.
localized
()
case
.
partlyCloudyDay
:
return
"forecast.cloudy"
.
localized
()
case
.
snowyDay
:
return
"forecast.snowyDay"
.
localized
()
case
.
snowyNight
:
return
"forecast.snowyNight"
.
localized
()
case
.
clearNight
:
return
"forecast.clearNight"
.
localized
()
case
.
partlyCloudyNight
:
return
"forecast.partlyCloudyNight"
.
localized
()
case
.
thunderstorm
:
return
"forecast.thunderstorm"
.
localized
()
case
.
heavySnow
:
return
"forecast.heavySnow"
.
localized
()
case
.
lightSnow
:
return
"forecast.lightSnow"
.
localized
()
case
.
freezingRain
:
return
"forecast.freezingRain"
.
localized
()
case
.
freezingFog
:
return
"forecast.freezingFog"
.
localized
()
case
.
lightHail
:
return
"forecast.lightHail"
.
localized
()
case
.
blowingDust
:
return
"forecast.blowingDust"
.
localized
()
case
.
haze
:
return
"forecast.haze"
.
localized
()
case
.
lightFog
:
return
"forecast.lightFog"
.
localized
()
case
.
mostlyCloudyDay
:
return
"forecast.mostlyCloudyDay"
.
localized
()
case
.
mostlyCloudyNight
:
return
"forecast.mostlyCloudyNight"
.
localized
()
case
.
lightDrizzle
:
return
"forecast.lightDrizzle"
.
localized
()
case
.
heavyRain
:
return
"forecast.heavyRain"
.
localized
()
case
.
smoke
:
return
"forecast.smoke"
.
localized
()
case
.
unknown
:
return
"forecast.unknown"
.
localized
()
public
func
localized
(
isDay
:
Bool
)
->
String
{
return
"forecast.
\(
self
.
stringId
(
isDay
:
isDay
)
.
localized
()
)
"
}
public
func
image
(
isDay
:
Bool
)
->
UIImage
{
guard
let
result
=
UIImage
(
named
:
self
.
stringId
(
isDay
:
isDay
))
else
{
assertionFailure
(
"Image is missing for WeatherType
\(
self
)
"
)
return
UIImage
()
}
return
result
}
private
static
let
dayNightCustomizable
:
Set
<
WeatherType
>
=
Set
<
WeatherType
>
(
arrayLiteral
:
.
clear
,
.
partlyCloudy
,
.
snowy
,
.
mostlyCloudy
)
private
func
stringId
(
isDay
:
Bool
)
->
String
{
var
stringId
=
self
.
rawValue
if
WeatherType
.
dayNightCustomizable
.
contains
(
self
)
{
stringId
+=
isDay
?
"Day"
:
"Night"
}
return
stringId
}
}
...
...
1Weather/Network/Model/HelperObjects/WdtWeatherCode.swift
View file @
c4d1d047
...
...
@@ -81,8 +81,7 @@ enum WdtWeatherCode: String, Codable {
case
.
lightFog
,
.
patchyFog
,
.
fog
:
return
.
lightFog
case
.
squall
,
.
driftingSnow
,
.
blowingSnow
:
return
.
snowyDay
//TODO: handle snowyNight
return
.
snowy
case
.
freezingFog
:
return
.
freezingFog
case
.
lightDrizzle
,
.
drizzle
,
.
heavyDrizzle
,
.
lightRain
,
.
lightRainShower
:
...
...
@@ -97,26 +96,19 @@ enum WdtWeatherCode: String, Codable {
case
.
lightSnow
,
.
lightSnowShower
:
return
.
lightSnow
case
.
snow
,
.
snowShower
:
//TODO: handle snowyNight
return
.
snowyDay
return
.
snowy
case
.
heavySnow
:
return
.
heavySnow
case
.
lightHail
,
.
hail
:
return
.
lightHail
case
.
thunderstorm
,
.
heavyThunderstorm
:
return
.
thunderstorm
// isDay ? "ic_static_sunny" : "ic_static_clear_night"
case
.
clear
:
//TODO: handle clear night
return
.
clearDay
// isDay ? "ic_static_partly_cloudy" : "ic_static_partly_cloudy_night"
return
.
clear
case
.
mostlyClear
,
.
partlyCloudy
:
// TODO: handle partly cloudy night
return
.
partlyCloudyDay
// isDay ? "ic_static_heavy_cloudy" : "ic_static_heavy_cloudy_night"
return
.
partlyCloudy
case
.
mostlyCloudy
,
.
overcast
:
//TODO: handle mostly cloudy night
return
.
mostlyCloudyDay
return
.
mostlyCloudy
}
}
}
1Weather/UI/View controllers/Today/Cells/CityDayTimesCell/DayTimeView.swift
View file @
c4d1d047
...
...
@@ -30,7 +30,7 @@ class DayTimeView: UIView {
public
func
configure
(
with
dayTimeWeather
:
DayTimeWeather
)
{
dayTimeLabel
.
text
=
dayTimeWeather
.
dayTime
.
localized
forecastImageView
.
image
=
UIImage
(
named
:
dayTimeWeather
.
type
.
rawValue
)
forecastImageView
.
image
=
dayTimeWeather
.
type
.
image
(
isDay
:
dayTimeWeather
.
isDay
)
tempLabel
.
text
=
dayTimeWeather
.
temp
?
.
shortString
??
"--"
}
}
...
...
1Weather/UI/View controllers/Today/Cells/CityForecastCell.swift
View file @
c4d1d047
...
...
@@ -39,9 +39,9 @@ class CityForecastCell: UITableViewCell {
let
maxTemp
=
location
.
today
?
.
maxTemp
?
.
shortString
??
"--"
let
minTemp
=
location
.
today
?
.
minTemp
?
.
shortString
??
"--"
let
feelstemp
=
location
.
today
?
.
apparentTemp
?
.
shortString
??
"--"
forecastDescriptionLabel
.
text
=
"
\(
location
.
today
?
.
type
.
localized
??
""
)
|
\(
maxTemp
)
/
\(
minTemp
)
"
forecastDescriptionLabel
.
text
=
"
\(
location
.
today
?
.
type
.
localized
(
isDay
:
location
.
today
?
.
isDay
??
true
)
??
""
)
|
\(
maxTemp
)
/
\(
minTemp
)
"
feelsLikeLabel
.
text
=
"Feels like
\(
feelstemp
)
- Due to high humidity"
forecastImageView
.
image
=
UIImage
(
named
:
location
.
today
?
.
type
.
rawValue
??
""
)
forecastImageView
.
image
=
location
.
today
?
.
type
.
image
(
isDay
:
location
.
today
?
.
isDay
??
true
)
}
}
...
...
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/PeriodForecastButton.swift
View file @
c4d1d047
...
...
@@ -84,7 +84,7 @@ class PeriodForecastButton: UIControl {
self
.
tempLabel
.
text
=
dailyWeather
.
maxTemp
?
.
shortString
self
.
minTempLabel
.
text
=
dailyWeather
.
minTemp
?
.
shortString
self
.
indicatorImageView
.
image
=
nil
self
.
forecastImageView
.
image
=
UIImage
(
named
:
dailyWeather
.
type
.
rawVal
ue
)
self
.
forecastImageView
.
image
=
dailyWeather
.
type
.
image
(
isDay
:
tr
ue
)
if
Calendar
.
current
.
isDateInToday
(
dailyWeather
.
date
)
{
self
.
timeLabel
.
text
=
"day.today"
.
localized
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment