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
41e13440
Commit
41e13440
authored
Mar 15, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Plain Diff
- Finished ForecastDetailsButton
- Changed YYYY to yyyy in date formatters
parents
b843a0d1
073eda93
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
224 additions
and
56 deletions
+224
-56
1Weather.xcodeproj/project.pbxproj
+0
-4
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/Model/ModelObjects/ForecastTimePeriod.swift
+0
-13
1Weather/Network/Model/HelperObjects/WdtDailySummariesArray.swift
+1
-1
1Weather/Network/Model/HelperObjects/WdtHourlySummariesArray.swift
+1
-1
1Weather/Network/Model/WdtDailySummary.swift
+2
-2
1Weather/Network/Model/WdtHourlySummary.swift
+1
-1
1Weather/Network/Model/WdtSurfaceObservation.swift
+2
-2
1Weather/Resources/en.lproj/Localizable.strings
+1
-1
1Weather/UI/Helpers/ForecastTimePeriod/ForecastDetailPeriodButton.swift
+163
-2
1Weather/UI/Helpers/ForecastTimePeriod/ForecastPeriodButton.swift
+9
-4
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
+23
-19
1Weather/UI/Helpers/ForecastTimePeriod/PeriodButtonProtocol.swift
+2
-0
1Weather/UI/View controllers/Forecast/Cells/ForecastTimePeriodCell.swift
+16
-2
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriodCell.swift
+1
-2
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
No files found.
1Weather.xcodeproj/project.pbxproj
View file @
41e13440
...
...
@@ -30,7 +30,6 @@
CD6B303E25726960004B34B3
/* ThemeProtocol.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD6B303D25726960004B34B3
/* ThemeProtocol.swift */
;
};
CD6B304325726AD1004B34B3
/* DefaultTheme.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD6B304225726AD1004B34B3
/* DefaultTheme.swift */
;
};
CD71709025FA317700A63C27
/* ForecastTimePeriodView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD71708F25FA317700A63C27
/* ForecastTimePeriodView.swift */
;
};
CD71709325FA31C200A63C27
/* ForecastTimePeriod.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD71709225FA31C200A63C27
/* ForecastTimePeriod.swift */
;
};
CD80917B2578E4A8003541A4
/* UIViewController+Alert.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD80917A2578E4A8003541A4
/* UIViewController+Alert.swift */
;
};
CD822FF525D6817000A05501
/* CityForecastCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD822FF425D6817000A05501
/* CityForecastCell.swift */
;
};
CD822FFA25D6890900A05501
/* OneWeatherColorsAsset.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CD822FF925D6890900A05501
/* OneWeatherColorsAsset.xcassets */
;
};
...
...
@@ -120,7 +119,6 @@
CD6B303D25726960004B34B3
/* ThemeProtocol.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ThemeProtocol.swift
;
sourceTree
=
"<group>"
;
};
CD6B304225726AD1004B34B3
/* DefaultTheme.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DefaultTheme.swift
;
sourceTree
=
"<group>"
;
};
CD71708F25FA317700A63C27
/* ForecastTimePeriodView.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ForecastTimePeriodView.swift
;
sourceTree
=
"<group>"
;
};
CD71709225FA31C200A63C27
/* ForecastTimePeriod.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ForecastTimePeriod.swift
;
sourceTree
=
"<group>"
;
};
CD80917A2578E4A8003541A4
/* UIViewController+Alert.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
"UIViewController+Alert.swift"
;
sourceTree
=
"<group>"
;
};
CD822FF425D6817000A05501
/* CityForecastCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CityForecastCell.swift
;
sourceTree
=
"<group>"
;
};
CD822FF925D6890900A05501
/* OneWeatherColorsAsset.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
OneWeatherColorsAsset.xcassets
;
sourceTree
=
"<group>"
;
};
...
...
@@ -519,7 +517,6 @@
CEAFF08B25DFC6BC00DF4EBF
/* DailyWeather.swift */
,
CEAFF08E25DFC6ED00DF4EBF
/* HourlyWeather.swift */
,
CE578FD225F7E89400E8B85D
/* DayTimeWeather.swift */
,
CD71709225FA31C200A63C27
/* ForecastTimePeriod.swift */
,
);
path
=
ModelObjects
;
sourceTree
=
"<group>"
;
...
...
@@ -705,7 +702,6 @@
CDEE8AD725DA882200C289DE
/* ForecastPeriodButton.swift in Sources */
,
CDE18DD125D166F900C80ED9
/* ForecastViewController.swift in Sources */
,
CD39F2F525DE9571009FE398
/* ArrowButton.swift in Sources */
,
CD71709325FA31C200A63C27
/* ForecastTimePeriod.swift in Sources */
,
CEDE4E8325EEFD56007457E9
/* WdtLocationResponse.swift in Sources */
,
CD8E041625F8F91B001785B6
/* ForecastCellFactory.swift in Sources */
,
CDC6125325E79C8F00188DA7
/* DayTimeView.swift in Sources */
,
...
...
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
41e13440
...
...
@@ -7,7 +7,7 @@
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
...
...
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
41e13440
No preview for this file type
1Weather/Model/ModelObjects/ForecastTimePeriod.swift
deleted
100644 → 0
View file @
b843a0d1
//
// ForecastTimePeriod.swift
// 1Weather
//
// Created by Dmitry Stepanets on 11.03.2021.
//
import
UIKit
struct
ForecastTimePeriod
{
let
daily
:[
DailyWeather
]
let
hourly
:[
HourlyWeather
]
}
1Weather/Network/Model/HelperObjects/WdtDailySummariesArray.swift
View file @
41e13440
...
...
@@ -14,7 +14,7 @@ struct WdtDailySummariesArray: Codable {
private
static
let
dateFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
timeZone
=
TimeZone
(
abbreviation
:
"PST"
)
fmt
.
dateFormat
=
"MM/dd/
YYYY
"
fmt
.
dateFormat
=
"MM/dd/
yyyy
"
return
fmt
}()
...
...
1Weather/Network/Model/HelperObjects/WdtHourlySummariesArray.swift
View file @
41e13440
...
...
@@ -13,7 +13,7 @@ struct WdtHourlySummariesArray: Codable {
private
static
let
dateFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
timeZone
=
TimeZone
(
abbreviation
:
"PST"
)
fmt
.
dateFormat
=
"
YYYY
-MM-dd HH:mm:ss"
fmt
.
dateFormat
=
"
yyyy
-MM-dd HH:mm:ss"
return
fmt
}()
...
...
1Weather/Network/Model/WdtDailySummary.swift
View file @
41e13440
...
...
@@ -46,7 +46,7 @@ struct WdtDailySummary: Codable {
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
DailyWeather
?
{
let
log
=
WdtDailySummary
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"MM/dd/
YYYY
"
dateFormatter
.
dateFormat
=
"MM/dd/
yyyy
"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
dateLocal
)
else
{
log
.
error
(
"Failed to parse date from:
\(
dateLocal
)
"
)
...
...
@@ -80,7 +80,7 @@ struct WdtDailySummary: Codable {
let
sunMoonDateFormatter
=
DateFormatter
()
sunMoonDateFormatter
.
timeZone
=
TimeZone
(
identifier
:
"UTC"
)
sunMoonDateFormatter
.
dateFormat
=
"
YYYY
-MM-dd HH:mm:ss"
sunMoonDateFormatter
.
dateFormat
=
"
yyyy
-MM-dd HH:mm:ss"
if
let
sunriseUtc
=
sunriseUtc
{
result
.
sunrise
=
sunMoonDateFormatter
.
date
(
from
:
sunriseUtc
)
}
...
...
1Weather/Network/Model/WdtHourlySummary.swift
View file @
41e13440
...
...
@@ -39,7 +39,7 @@ struct WdtHourlySummary: Codable {
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
HourlyWeather
?
{
let
log
=
WdtHourlySummary
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"
YYYY
-MM-dd HH:mm:ss"
dateFormatter
.
dateFormat
=
"
yyyy
-MM-dd HH:mm:ss"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
dateTimeLocal
)
else
{
...
...
1Weather/Network/Model/WdtSurfaceObservation.swift
View file @
41e13440
...
...
@@ -45,7 +45,7 @@ struct WdtSurfaceObservation: Codable {
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
CurrentWeather
?
{
let
log
=
WdtSurfaceObservation
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"
YYYY
-MM-dd HH:mm:ss"
dateFormatter
.
dateFormat
=
"
yyyy
-MM-dd HH:mm:ss"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
self
.
dateTimeLocal
)
else
{
...
...
@@ -88,7 +88,7 @@ struct WdtSurfaceObservation: Codable {
let
sunDateFormatter
=
DateFormatter
()
sunDateFormatter
.
timeZone
=
timeZone
sunDateFormatter
.
dateFormat
=
"
YYYY
-MM-dd hh:mm a"
sunDateFormatter
.
dateFormat
=
"
yyyy
-MM-dd hh:mm a"
result
.
sunrise
=
sunDateFormatter
.
date
(
from
:
sunriseLocalDateTime
)
result
.
sunset
=
sunDateFormatter
.
date
(
from
:
sunsetLocalDateTime
)
}
...
...
1Weather/Resources/en.lproj/Localizable.strings
View file @
41e13440
...
...
@@ -7,11 +7,11 @@
//Forecast
"forecast.sunny" = "Sunny";
"forecast.clear" = "Clear";
"forecast.cloudy" = "Cloudy";
"forecast.partlyCloudyDay" = "Partly Cloudy";
"forecast.snowyDay" = "Snowy Day";
"forecast.snowyNight" = "Snowy Night";
"forecast.clearDay" = "Clear Day";
"forecast.clearNight" = "Clear Night";
"forecast.partlyCloudyNight" = "Partly Cloudy Night";
"forecast.thunderstorm" = "Thunderstorm";
...
...
1Weather/UI/Helpers/ForecastTimePeriod/ForecastDetailPeriodButton.swift
View file @
41e13440
...
...
@@ -6,8 +6,11 @@
//
import
UIKit
import
SnapKit
class
ForecastDetailPeriodButton
:
UIControl
,
PeriodButtonProtocol
{
private
let
kGraphInset
:
CGFloat
=
10
private
let
kPrecipImageWidth
:
CGFloat
=
20
private
let
dateLabel
=
UILabel
()
private
let
weatherImageView
=
UIImageView
()
private
let
weatherTypeLabel
=
UILabel
()
...
...
@@ -15,23 +18,91 @@ class ForecastDetailPeriodButton: UIControl, PeriodButtonProtocol {
private
let
minTempLabel
=
UILabel
()
private
let
precipLabel
=
UILabel
()
private
let
precipImageView
=
UIImageView
()
private
var
precipImageWidth
:
Constraint
?
private
static
var
formatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
dateFormat
=
"d, E"
return
fmt
}()
//Public
public
var
tinted
:
Bool
{
return
false
}
public
var
index
=
-
1
var
graphRect
:
CGRect
{
let
topInset
=
self
.
maxTempLabel
.
frame
.
origin
.
y
+
self
.
maxTempLabel
.
frame
.
size
.
height
+
kGraphInset
return
.
init
(
x
:
0
,
y
:
topInset
,
width
:
self
.
bounds
.
width
,
height
:
self
.
minTempLabel
.
frame
.
origin
.
y
-
topInset
-
kGraphInset
)
}
required
init
()
{
super
.
init
(
frame
:
.
zero
)
prepareButton
()
prepareDateLabel
()
prepareWeatherInfo
()
preparePreicpitaitonView
()
prepareTempLabels
()
}
required
init
?(
coder
:
NSCoder
)
{
fatalError
(
"init(coder:) has not been implemented"
)
}
override
var
isSelected
:
Bool
{
didSet
{
if
isSelected
{
self
.
backgroundColor
=
UIColor
(
hex
:
0x1f67f3
)
self
.
dateLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
16
)
self
.
dateLabel
.
textColor
=
.
white
self
.
weatherTypeLabel
.
textColor
=
.
white
self
.
maxTempLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
16
)
self
.
maxTempLabel
.
textColor
=
.
white
self
.
minTempLabel
.
textColor
=
.
white
self
.
precipLabel
.
textColor
=
.
white
self
.
precipImageView
.
tintColor
=
.
white
}
else
{
self
.
backgroundColor
=
UIColor
(
hex
:
0xeceef6
)
self
.
dateLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
self
.
dateLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
self
.
weatherTypeLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
self
.
maxTempLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
self
.
maxTempLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
self
.
minTempLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
self
.
precipLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
self
.
precipImageView
.
tintColor
=
UIColor
(
hex
:
0x1f67f3
)
}
}
}
func
configure
(
dailyWeather
:
DailyWeather
)
{
//
if
Calendar
.
current
.
isDateInToday
(
dailyWeather
.
date
)
{
dateLabel
.
text
=
"day.today"
.
localized
()
}
else
{
dateLabel
.
text
=
ForecastDetailPeriodButton
.
formatter
.
string
(
from
:
dailyWeather
.
date
)
}
weatherImageView
.
image
=
dailyWeather
.
type
.
image
(
isDay
:
true
)
weatherTypeLabel
.
text
=
dailyWeather
.
type
.
localized
(
isDay
:
true
)
maxTempLabel
.
text
=
dailyWeather
.
maxTemp
?
.
shortString
minTempLabel
.
text
=
dailyWeather
.
minTemp
?
.
shortString
let
percent
=
dailyWeather
.
precipitationProbability
??
0
precipLabel
.
text
=
"
\(
percent
)
%"
precipImageView
.
isHidden
=
percent
==
0
precipImageWidth
?
.
layoutConstraints
.
first
?
.
constant
=
percent
==
0
?
0
:
kPrecipImageWidth
}
func
configure
(
hourlyWeather
:
HourlyWeather
)
{
//
assertionFailure
(
"Not implemented for this weather type"
)
}
}
...
...
@@ -45,6 +116,96 @@ private extension ForecastDetailPeriodButton {
}
func
prepareDateLabel
()
{
dateLabel
.
isUserInteractionEnabled
=
false
dateLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
dateLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
14
)
addSubview
(
dateLabel
)
dateLabel
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
equalToSuperview
()
.
inset
(
16
)
make
.
centerX
.
equalToSuperview
()
}
}
func
prepareWeatherInfo
()
{
weatherImageView
.
isUserInteractionEnabled
=
false
weatherImageView
.
contentMode
=
.
scaleAspectFit
addSubview
(
weatherImageView
)
weatherImageView
.
snp
.
makeConstraints
{
(
make
)
in
make
.
width
.
height
.
equalTo
(
28
)
make
.
top
.
equalTo
(
dateLabel
.
snp
.
bottom
)
.
offset
(
8
)
make
.
centerX
.
equalToSuperview
()
make
.
left
.
right
.
equalToSuperview
()
.
inset
(
20
)
}
weatherTypeLabel
.
isUserInteractionEnabled
=
false
weatherTypeLabel
.
textAlignment
=
.
center
weatherTypeLabel
.
numberOfLines
=
2
weatherTypeLabel
.
lineBreakMode
=
.
byWordWrapping
weatherTypeLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
12
)
weatherTypeLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
addSubview
(
weatherTypeLabel
)
weatherTypeLabel
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
equalTo
(
weatherImageView
.
snp
.
bottom
)
.
offset
(
2
)
make
.
centerX
.
equalToSuperview
()
make
.
left
.
right
.
equalToSuperview
()
.
inset
(
4
)
}
}
func
prepareTempLabels
()
{
maxTempLabel
.
isUserInteractionEnabled
=
false
maxTempLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
maxTempLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
addSubview
(
maxTempLabel
)
maxTempLabel
.
snp
.
makeConstraints
{
(
make
)
in
make
.
top
.
equalTo
(
weatherImageView
.
snp
.
bottom
)
.
offset
(
34
)
make
.
centerX
.
equalToSuperview
()
}
minTempLabel
.
isUserInteractionEnabled
=
false
minTempLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
12
)
minTempLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
addSubview
(
minTempLabel
)
minTempLabel
.
snp
.
makeConstraints
{
(
make
)
in
make
.
bottom
.
equalTo
(
precipImageView
.
snp
.
top
)
.
offset
(
-
28
)
make
.
centerX
.
equalToSuperview
()
}
}
func
preparePreicpitaitonView
()
{
let
container
=
UIView
()
precipImageView
.
isUserInteractionEnabled
=
false
precipImageView
.
image
=
UIImage
(
named
:
"humidity"
)?
.
withRenderingMode
(
.
alwaysTemplate
)
precipImageView
.
tintColor
=
UIColor
(
hex
:
0x1f67f3
)
precipImageView
.
contentMode
=
.
scaleAspectFit
container
.
addSubview
(
precipImageView
)
precipImageView
.
snp
.
makeConstraints
{
(
make
)
in
self
.
precipImageWidth
=
make
.
width
.
equalTo
(
kPrecipImageWidth
)
.
constraint
make
.
height
.
equalTo
(
12
)
make
.
top
.
left
.
bottom
.
equalToSuperview
()
}
precipLabel
.
isUserInteractionEnabled
=
false
precipLabel
.
textAlignment
=
.
left
precipLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
12
)
precipLabel
.
textColor
=
ThemeManager
.
currentTheme
.
secondaryTextColor
container
.
addSubview
(
precipLabel
)
precipLabel
.
snp
.
makeConstraints
{
(
make
)
in
make
.
left
.
equalTo
(
precipImageView
.
snp
.
right
)
.
inset
(
2
)
make
.
right
.
equalToSuperview
()
}
addSubview
(
container
)
container
.
snp
.
makeConstraints
{
(
make
)
in
make
.
centerX
.
equalToSuperview
()
make
.
bottom
.
equalToSuperview
()
.
inset
(
20
)
}
}
}
1Weather/UI/Helpers/ForecastTimePeriod/ForecastPeriodButton.swift
View file @
41e13440
...
...
@@ -9,12 +9,12 @@ import UIKit
class
ForecastPeriodButton
:
UIControl
,
PeriodButtonProtocol
{
//Private
private
let
hourlyFormatter
:
DateFormatter
=
{
private
static
var
hourlyFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
dateFormat
=
"h a"
return
fmt
}()
private
let
dailyFormatter
:
DateFormatter
=
{
private
static
var
dailyFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
dateFormat
=
"d, E"
return
fmt
...
...
@@ -28,6 +28,9 @@ class ForecastPeriodButton: UIControl, PeriodButtonProtocol {
//Public
public
var
tinted
:
Bool
{
return
true
}
public
var
index
=
-
1
var
graphRect
:
CGRect
{
let
topInset
=
self
.
tempLabel
.
frame
.
origin
.
y
+
self
.
tempLabel
.
frame
.
size
.
height
+
kGraphInset
...
...
@@ -90,7 +93,8 @@ class ForecastPeriodButton: UIControl, PeriodButtonProtocol {
self
.
timeLabel
.
text
=
"day.today"
.
localized
()
}
else
{
self
.
timeLabel
.
text
=
dailyFormatter
.
string
(
from
:
dailyWeather
.
date
)
ForecastPeriodButton
.
dailyFormatter
.
timeZone
=
dailyWeather
.
timeZone
self
.
timeLabel
.
text
=
ForecastPeriodButton
.
dailyFormatter
.
string
(
from
:
dailyWeather
.
date
)
}
}
...
...
@@ -98,7 +102,8 @@ class ForecastPeriodButton: UIControl, PeriodButtonProtocol {
self
.
tempLabel
.
text
=
hourlyWeather
.
temp
?
.
shortString
self
.
minTempLabel
.
text
=
nil
self
.
indicatorImageView
.
image
=
nil
self
.
timeLabel
.
text
=
hourlyFormatter
.
string
(
from
:
hourlyWeather
.
date
)
ForecastPeriodButton
.
hourlyFormatter
.
timeZone
=
hourlyWeather
.
timeZone
self
.
timeLabel
.
text
=
ForecastPeriodButton
.
hourlyFormatter
.
string
(
from
:
hourlyWeather
.
date
)
}
}
...
...
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
View file @
41e13440
...
...
@@ -25,7 +25,8 @@ class ForecastTimePeriodView: UIView {
private
var
currentTimePeriod
=
TimePeriod
.
daily
private
var
dailyGraphPoints
=
DailyGraphPoints
(
maxTempPoints
:
[
CGPoint
](),
minTempPoints
:
[
CGPoint
]())
private
var
hourlyGraphPoints
=
HourlyGraphPoints
(
points
:
[
CGPoint
]())
private
var
forecastTimePeriod
:
ForecastTimePeriod
=
ForecastTimePeriod
(
daily
:
[
DailyWeather
](),
hourly
:
[
HourlyWeather
]())
private
var
daily
=
[
DailyWeather
]()
private
var
hourly
=
[
HourlyWeather
]()
//MARK:- View life cycle
init
()
{
...
...
@@ -42,8 +43,9 @@ class ForecastTimePeriodView: UIView {
}
//Public
public
func
set
(
forecastTimePeriod
:
ForecastTimePeriod
)
{
self
.
forecastTimePeriod
=
forecastTimePeriod
public
func
set
(
location
:
Location
)
{
self
.
daily
=
location
.
daily
self
.
hourly
=
location
.
hourly
}
public
func
set
(
timePeriod
:
TimePeriod
,
buttonType
:
PeriodButtonProtocol
.
Type
)
{
...
...
@@ -61,18 +63,18 @@ class ForecastTimePeriodView: UIView {
let
numberOfButtons
:
Int
switch
currentTimePeriod
{
case
.
daily
:
numberOfButtons
=
forecastTimePeriod
.
daily
.
count
numberOfButtons
=
daily
.
count
case
.
hourly
:
numberOfButtons
=
forecastTimePeriod
.
hourly
.
count
numberOfButtons
=
hourly
.
count
}
for
index
in
0
..<
numberOfButtons
{
let
forecastButton
=
buttonType
.
init
()
switch
currentTimePeriod
{
case
.
daily
:
forecastButton
.
configure
(
dailyWeather
:
forecastTimePeriod
.
daily
[
index
])
forecastButton
.
configure
(
dailyWeather
:
daily
[
index
])
case
.
hourly
:
forecastButton
.
configure
(
hourlyWeather
:
forecastTimePeriod
.
hourly
[
index
])
forecastButton
.
configure
(
hourlyWeather
:
hourly
[
index
])
}
forecastButton
.
index
=
index
forecastButton
.
addTarget
(
self
,
action
:
#selector(
handleForecastButton(button:)
)
,
for
:
.
touchUpInside
)
...
...
@@ -90,7 +92,7 @@ class ForecastTimePeriodView: UIView {
private
func
updateGraphLayout
()
{
print
(
"[ForecastTimePeriod] Update graph layout"
)
graphRect
=
(
stackView
.
arrangedSubviews
.
first
as?
ForecastPeriodButton
)?
.
graphRect
??
.
zero
graphRect
=
(
stackView
.
arrangedSubviews
.
first
as?
PeriodButtonProtocol
)?
.
graphRect
??
.
zero
graphView
.
frame
=
.
init
(
x
:
0
,
y
:
graphRect
.
origin
.
y
,
width
:
stackView
.
frame
.
width
,
...
...
@@ -110,16 +112,16 @@ class ForecastTimePeriodView: UIView {
}
private
func
updateDailyGraphPoints
()
{
let
daysCount
=
forecastTimePeriod
.
daily
.
count
let
maxTemps
=
(
forecastTimePeriod
.
daily
.
map
{
CGFloat
(
$0
.
maxTemp
?
.
localeValue
??
0
)
})
let
daysCount
=
daily
.
count
let
maxTemps
=
(
daily
.
map
{
CGFloat
(
$0
.
maxTemp
?
.
localeValue
??
0
)
})
let
topMaxTemp
=
maxTemps
.
max
()
??
0
let
minTemps
=
(
forecastTimePeriod
.
daily
.
map
{
CGFloat
(
$0
.
minTemp
?
.
localeValue
??
0
)
})
let
minTemps
=
(
daily
.
map
{
CGFloat
(
$0
.
minTemp
?
.
localeValue
??
0
)
})
let
topMinTemp
=
minTemps
.
max
()
??
0
var
maxPoints
=
[
CGPoint
]()
var
minPoints
=
[
CGPoint
]()
for
index
in
0
..<
daysCount
{
guard
let
stackButton
=
stackView
.
arrangedSubviews
[
index
]
as?
ForecastPeriodButton
else
{
continue
}
guard
let
stackButton
=
stackView
.
arrangedSubviews
[
index
]
as?
PeriodButtonProtocol
else
{
continue
}
let
buttonRightSide
=
stackButton
.
frame
.
origin
.
x
+
stackButton
.
bounds
.
width
let
buttonCenterX
=
(
buttonRightSide
+
stackButton
.
frame
.
origin
.
x
)
/
2
...
...
@@ -148,14 +150,14 @@ class ForecastTimePeriodView: UIView {
}
private
func
updateHourlyGraphPoints
()
{
let
hoursCount
=
forecastTimePeriod
.
hourly
.
count
let
temps
=
(
forecastTimePeriod
.
hourly
.
map
{
CGFloat
(
$0
.
temp
?
.
localeValue
??
0
)
})
let
hoursCount
=
hourly
.
count
let
temps
=
(
hourly
.
map
{
CGFloat
(
$0
.
temp
?
.
localeValue
??
0
)
})
let
maxTemp
=
temps
.
max
()
??
0
var
points
=
[
CGPoint
]()
for
index
in
0
..<
hoursCount
{
guard
let
stackButton
=
stackView
.
arrangedSubviews
[
index
]
as?
ForecastPeriodButton
else
{
continue
}
guard
let
stackButton
=
stackView
.
arrangedSubviews
[
index
]
as?
PeriodButtonProtocol
else
{
continue
}
let
buttonRightSide
=
stackButton
.
frame
.
origin
.
x
+
stackButton
.
bounds
.
width
let
buttonCenterX
=
(
buttonRightSide
+
stackButton
.
frame
.
origin
.
x
)
/
2
...
...
@@ -176,7 +178,7 @@ class ForecastTimePeriodView: UIView {
private
func
drawGraph
()
{
guard
let
periodButtons
=
stackView
.
arrangedSubviews
as?
[
ForecastPeriodButton
],
let
periodButtons
=
stackView
.
arrangedSubviews
as?
[
PeriodButtonProtocol
],
let
selectedButton
=
(
periodButtons
.
first
{
$0
.
isSelected
})
else
{
return
...
...
@@ -196,7 +198,9 @@ class ForecastTimePeriodView: UIView {
print
(
"[ForecastTimePeriod] Draw graph"
)
}
private
func
tintGraphAt
(
button
:
ForecastPeriodButton
)
{
private
func
tintGraphAt
(
button
:
PeriodButtonProtocol
)
{
guard
button
.
tinted
else
{
return
}
switch
currentTimePeriod
{
case
.
daily
:
self
.
graphView
.
tintGraphFrom
(
startPointX
:
button
.
frame
.
origin
.
x
,
...
...
@@ -210,9 +214,9 @@ class ForecastTimePeriodView: UIView {
}
}
@objc
private
func
handleForecastButton
(
button
:
ForecastPeriodButton
)
{
@objc
private
func
handleForecastButton
(
button
:
UIControl
)
{
stackView
.
arrangedSubviews
.
forEach
{
if
let
periodButton
=
$0
as?
ForecastPeriodButton
{
if
let
periodButton
=
$0
as?
PeriodButtonProtocol
{
periodButton
.
isSelected
=
periodButton
===
button
if
periodButton
.
isSelected
{
...
...
1Weather/UI/Helpers/ForecastTimePeriod/PeriodButtonProtocol.swift
View file @
41e13440
...
...
@@ -12,4 +12,6 @@ public protocol PeriodButtonProtocol: UIControl {
func
configure
(
dailyWeather
:
DailyWeather
)
func
configure
(
hourlyWeather
:
HourlyWeather
)
var
index
:
Int
{
get
set
}
var
graphRect
:
CGRect
{
get
}
var
tinted
:
Bool
{
get
}
}
1Weather/UI/View controllers/Forecast/Cells/ForecastTimePeriodCell.swift
View file @
41e13440
...
...
@@ -16,6 +16,7 @@ class ForecastTimePeriodCell: UITableViewCell {
private
let
gradientView
=
GradientView
(
startColor
:
UIColor
(
hex
:
0xffffff
)
.
withAlphaComponent
(
0
),
endColor
:
UIColor
(
hex
:
0xdaddec
),
opacity
:
0.5
)
private
var
graphIsDrawn
=
false
override
init
(
style
:
UITableViewCell
.
CellStyle
,
reuseIdentifier
:
String
?)
{
super
.
init
(
style
:
style
,
reuseIdentifier
:
reuseIdentifier
)
...
...
@@ -32,12 +33,25 @@ class ForecastTimePeriodCell: UITableViewCell {
//Public
public
func
configure
(
with
location
:
Location
)
{
let
forecastTimePeriod
=
ForecastTimePeriod
(
daily
:
location
.
daily
,
hourly
:
location
.
hourly
)
self
.
forecastTimePeriodView
.
set
(
forecastTimePeriod
:
forecastTimePeriod
)
self
.
forecastTimePeriodView
.
set
(
location
:
location
)
if
graphIsDrawn
==
false
{
self
.
handleSegmentDidChange
()
self
.
graphIsDrawn
=
true
}
}
@objc
private
func
handleSegmentDidChange
()
{
guard
let
timePeriod
=
TimePeriod
(
rawValue
:
self
.
periodSegmentedControl
.
selectedSegmentIndex
)
else
{
return
}
switch
timePeriod
{
case
.
daily
:
self
.
forecastTimePeriodView
.
set
(
timePeriod
:
timePeriod
,
buttonType
:
ForecastDetailPeriodButton
.
self
)
case
.
hourly
:
self
.
forecastTimePeriodView
.
set
(
timePeriod
:
timePeriod
,
buttonType
:
ForecastPeriodButton
.
self
)
}
}
}
...
...
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriodCell.swift
View file @
41e13440
...
...
@@ -33,8 +33,7 @@ class CityForecastTimePeriodCell: UITableViewCell {
//Public
public
func
configure
(
with
location
:
Location
)
{
let
forecastTimePeriod
=
ForecastTimePeriod
(
daily
:
location
.
daily
,
hourly
:
location
.
hourly
)
self
.
forecastTimePeriodView
.
set
(
forecastTimePeriod
:
forecastTimePeriod
)
self
.
forecastTimePeriodView
.
set
(
location
:
location
)
if
graphIsDrawn
==
false
{
self
.
handleSegmentDidChange
()
...
...
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
41e13440
...
...
@@ -52,7 +52,7 @@
<
k
e
y
>
XMLCoder.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
6
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
...
...
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