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
d735d7db
Commit
d735d7db
authored
May 27, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Performance changes
parent
4656d2b3
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
212 additions
and
62 deletions
+212
-62
1Weather.xcodeproj/project.pbxproj
+1
-1
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather/Network/PushNotificationsManager.swift
+3
-2
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastDetailPeriodButton.swift
+5
-0
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastPeriodButton.swift
+5
-0
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastWindButton.swift
+5
-0
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
+40
-15
1Weather/UI/SharedCells/PrecipCell/PrecipitationCell.swift
+60
-14
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/TodayAirQualityCell.swift
+54
-16
1Weather/UI/View controllers/Today/Cells/TodayConditions/TodayConditionButton.swift
+5
-0
1Weather/UI/View controllers/Today/Cells/TodayDayTimesCell/TodayDayTimesCell.swift
+28
-13
1Weather/UI/View controllers/Today/Cells/TodayForecastCell.swift
+5
-0
No files found.
1Weather.xcodeproj/project.pbxproj
View file @
d735d7db
...
...
@@ -696,9 +696,9 @@
CD5D231B2615C6CA00B549DA
/* Buttons */
=
{
isa
=
PBXGroup
;
children
=
(
CD3F6E6B25FA5A90002DB99B
/* PeriodButtonProtocol.swift */
,
CDEE8AD625DA882200C289DE
/* ForecastPeriodButton.swift */
,
CD3F6E6825FA59D4002DB99B
/* ForecastDetailPeriodButton.swift */
,
CD3F6E6B25FA5A90002DB99B
/* PeriodButtonProtocol.swift */
,
CDE2BF242609D9140085C930
/* ForecastWindButton.swift */
,
);
path
=
Buttons
;
...
...
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
d735d7db
...
...
@@ -12,7 +12,7 @@
<
k
e
y
>
OneWeatherNotificationServiceExtension.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
49
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
51
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
...
...
1Weather/Network/PushNotificationsManager.swift
View file @
d735d7db
...
...
@@ -35,7 +35,6 @@ public class PushNotificationsManager: NSObject {
// TODO: forced re-register on timeout
public
func
registerForRemoteNotifications
()
{
UNUserNotificationCenter
.
current
()
.
requestAuthorization
(
options
:
[
.
alert
,
.
sound
,
.
badge
])
{
[
weak
self
]
(
granted
,
error
)
in
...
...
@@ -47,7 +46,9 @@ public class PushNotificationsManager: NSObject {
self
.
log
.
info
(
"Granted:
\(
granted
)
"
)
}
MoEngage
.
sharedInstance
()
.
registerForRemoteNotification
(
withCategories
:
nil
,
withUserNotificationCenterDelegate
:
self
)
onMain
{
MoEngage
.
sharedInstance
()
.
registerForRemoteNotification
(
withCategories
:
nil
,
withUserNotificationCenterDelegate
:
self
)
}
}
}
...
...
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastDetailPeriodButton.swift
View file @
d735d7db
...
...
@@ -57,6 +57,11 @@ class ForecastDetailPeriodButton: UIControl, PeriodButtonProtocol {
fatalError
(
"init(coder:) has not been implemented"
)
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
self
.
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
self
.
bounds
,
cornerRadius
:
12
)
.
cgPath
}
override
func
traitCollectionDidChange
(
_
previousTraitCollection
:
UITraitCollection
?)
{
super
.
traitCollectionDidChange
(
previousTraitCollection
)
updateUI
()
...
...
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastPeriodButton.swift
View file @
d735d7db
...
...
@@ -62,6 +62,11 @@ class ForecastPeriodButton: UIControl, PeriodButtonProtocol {
updateUI
()
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
self
.
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
self
.
bounds
,
cornerRadius
:
12
)
.
cgPath
}
override
var
isSelected
:
Bool
{
didSet
{
if
isSelected
{
...
...
1Weather/UI/Helpers/ForecastTimePeriod/Buttons/ForecastWindButton.swift
View file @
d735d7db
...
...
@@ -50,6 +50,11 @@ class ForecastWindButton: UIControl, PeriodButtonProtocol {
fatalError
(
"init(coder:) has not been implemented"
)
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
self
.
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
self
.
bounds
,
cornerRadius
:
12
)
.
cgPath
}
override
func
traitCollectionDidChange
(
_
previousTraitCollection
:
UITraitCollection
?)
{
super
.
traitCollectionDidChange
(
previousTraitCollection
)
updateUI
()
...
...
1Weather/UI/Helpers/ForecastTimePeriod/ForecastTimePeriodView.swift
View file @
d735d7db
...
...
@@ -107,8 +107,6 @@ class ForecastTimePeriodView: UIView {
}
private
func
rebuildButtons
(
buttonType
:
PeriodButtonProtocol
.
Type
)
{
stackView
.
removeAll
()
let
numberOfButtons
:
Int
switch
currentForecastType
{
case
.
daily
:
...
...
@@ -117,22 +115,49 @@ class ForecastTimePeriodView: UIView {
numberOfButtons
=
hourly
.
count
}
for
index
in
0
..<
numberOfButtons
{
let
forecastButton
=
buttonType
.
init
()
switch
currentForecastType
{
case
.
daily
:
forecastButton
.
configure
(
dailyWeather
:
daily
[
index
])
case
.
hourly
,
.
wind
:
forecastButton
.
configure
(
hourlyWeather
:
hourly
[
index
])
if
stackView
.
arrangedSubviews
.
count
==
numberOfButtons
{
for
(
index
,
arrangedSubview
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
guard
let
periodButton
=
arrangedSubview
as?
PeriodButtonProtocol
else
{
continue
}
switch
currentForecastType
{
case
.
daily
:
periodButton
.
configure
(
dailyWeather
:
daily
[
index
])
case
.
hourly
,
.
wind
:
periodButton
.
configure
(
hourlyWeather
:
hourly
[
index
])
}
}
}
else
{
let
diff
=
stackView
.
arrangedSubviews
.
count
-
numberOfButtons
for
_
in
0
..<
abs
(
diff
)
{
if
diff
>
0
{
//Remove present
stackView
.
arrangedSubviews
[
0
]
.
removeFromSuperview
()
}
else
{
//Add new
let
forecastButton
=
buttonType
.
init
()
forecastButton
.
addTarget
(
self
,
action
:
#selector(
handleForecastButton(button:)
)
,
for
:
.
touchUpInside
)
stackView
.
addArrangedSubview
(
forecastButton
)
forecastButton
.
snp
.
makeConstraints
{
(
make
)
in
make
.
height
.
equalToSuperview
()
}
}
}
forecastButton
.
index
=
index
forecastButton
.
addTarget
(
self
,
action
:
#selector(
handleForecastButton(button:)
)
,
for
:
.
touchUpInside
)
forecastButton
.
isSelected
=
index
==
0
stackView
.
addArrangedSubview
(
forecastButton
)
forecastButton
.
snp
.
makeConstraints
{
(
make
)
in
make
.
height
.
equalToSuperview
()
//Rebuild buttons index
for
(
index
,
subview
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
guard
let
forecastButton
=
subview
as?
PeriodButtonProtocol
else
{
continue
}
forecastButton
.
isSelected
=
index
==
0
forecastButton
.
index
=
index
}
self
.
rebuildButtons
(
buttonType
:
buttonType
)
}
stackView
.
layoutIfNeeded
()
...
...
1Weather/UI/SharedCells/PrecipCell/PrecipitationCell.swift
View file @
d735d7db
...
...
@@ -33,33 +33,79 @@ class PrecipitationCell: UITableViewCell {
}
public
func
configure
(
with
dayily
:[
DailyWeather
])
{
self
.
stackView
.
removeAll
()
//TODO: Hide button for now
headingButton
.
isHidden
=
true
for
index
in
0
..<
dayily
.
count
{
let
precipButton
=
PrecipButton
()
precipButton
.
isSelected
=
index
==
1
if
stackView
.
arrangedSubviews
.
count
!=
dayily
.
count
{
let
diff
=
stackView
.
arrangedSubviews
.
count
-
dayily
.
count
for
_
in
0
..<
abs
(
diff
)
{
if
diff
>
0
{
//Remove present
stackView
.
arrangedSubviews
[
0
]
.
removeFromSuperview
()
}
else
{
//Add new
let
precipButton
=
PrecipButton
()
precipButton
.
addTarget
(
self
,
action
:
#selector(
handlePrecipButton(button:)
)
,
for
:
.
touchUpInside
)
stackView
.
addArrangedSubview
(
precipButton
)
}
}
//Reset selected index
stackView
.
arrangedSubviews
.
enumerated
()
.
forEach
{
if
let
button
=
$1
as?
PrecipButton
{
button
.
isSelected
=
$0
==
1
}
}
stackView
.
layoutIfNeeded
()
}
for
(
index
,
button
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
guard
let
precipButton
=
button
as?
PrecipButton
else
{
continue
}
precipButton
.
configure
(
with
:
dayily
[
index
])
precipButton
.
addTarget
(
self
,
action
:
#selector(
handlePrecipButton(button:)
)
,
for
:
.
touchUpInside
)
stackView
.
addArrangedSubview
(
precipButton
)
}
stackView
.
layoutIfNeeded
()
}
public
func
configure
(
with
hourly
:[
HourlyWeather
])
{
self
.
stackView
.
removeAll
()
self
.
headingLabel
.
font
=
AppFont
.
SFPro
.
bold
(
size
:
18
)
self
.
headingButton
.
isHidden
=
true
self
.
headingLabel
.
text
=
"precipitation.title"
.
localized
()
.
capitalized
self
.
headingLabel
.
textColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
for
index
in
0
..<
hourly
.
count
{
let
precipButton
=
PrecipButton
()
precipButton
.
isSelected
=
index
==
0
if
stackView
.
arrangedSubviews
.
count
!=
hourly
.
count
{
let
diff
=
stackView
.
arrangedSubviews
.
count
-
hourly
.
count
for
_
in
0
..<
abs
(
diff
)
{
if
diff
>
0
{
//Remove present
stackView
.
arrangedSubviews
[
0
]
.
removeFromSuperview
()
}
else
{
//Add new
let
precipButton
=
PrecipButton
()
precipButton
.
addTarget
(
self
,
action
:
#selector(
handlePrecipButton(button:)
)
,
for
:
.
touchUpInside
)
stackView
.
addArrangedSubview
(
precipButton
)
}
}
//Reset selected index
stackView
.
arrangedSubviews
.
enumerated
()
.
forEach
{
if
let
button
=
$1
as?
PrecipButton
{
button
.
isSelected
=
$0
==
1
}
}
stackView
.
layoutIfNeeded
()
}
for
(
index
,
button
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
guard
let
precipButton
=
button
as?
PrecipButton
else
{
continue
}
precipButton
.
configure
(
with
:
hourly
[
index
])
precipButton
.
addTarget
(
self
,
action
:
#selector(
handlePrecipButton(button:)
)
,
for
:
.
touchUpInside
)
stackView
.
addArrangedSubview
(
precipButton
)
}
stackView
.
layoutIfNeeded
()
}
//Private
...
...
1Weather/UI/View controllers/Today/Cells/TodayAirQualityCell/TodayAirQualityCell.swift
View file @
d735d7db
...
...
@@ -65,22 +65,6 @@ class TodayAirQualityCell: UITableViewCell {
airDescLabel
.
text
=
health
?
.
airQuality
?
.
advice
//Fill pollutions
stackView
.
removeAll
()
if
let
pollutants
=
health
?
.
pollutants
.
values
,
let
maxPollutantProgress
:
CGFloat
=
pollutants
.
max
(
by
:
{
$0
.
progress
<
$1
.
progress
})?
.
progress
{
var
coefficient
:
CGFloat
=
1.0
let
desiredMinProgress
:
CGFloat
=
0.3
if
maxPollutantProgress
<
desiredMinProgress
{
coefficient
=
desiredMinProgress
/
maxPollutantProgress
}
for
pollutant
in
pollutants
{
let
pollutionView
=
PollutantView
()
pollutionView
.
configure
(
pollutant
:
pollutant
,
progressCoefficient
:
coefficient
)
stackView
.
addArrangedSubview
(
pollutionView
)
}
}
stackView
.
layoutIfNeeded
()
//Progress
guard
let
airQuality
=
health
?
.
airQuality
else
{
return
...
...
@@ -91,6 +75,60 @@ class TodayAirQualityCell: UITableViewCell {
value
:
Double
(
airQuality
.
progress
/
2
)),
AirQualityDataType
(
color
:
airQuality
.
status
.
gradientColorEnd
,
value
:
Double
(
airQuality
.
progress
/
2
))]
//Fill pollutions
guard
let
pollutants
=
health
?
.
pollutants
.
values
,
let
maxPollutantProgress
:
CGFloat
=
(
pollutants
.
max
{
$0
.
progress
<
$1
.
progress
})?
.
progress
else
{
return
}
if
stackView
.
arrangedSubviews
.
count
!=
pollutants
.
count
{
let
diff
=
stackView
.
arrangedSubviews
.
count
-
pollutants
.
count
for
_
in
0
..<
abs
(
diff
)
{
if
diff
>
0
{
//Remove present
stackView
.
arrangedSubviews
[
0
]
.
removeFromSuperview
()
}
else
{
//Add new
let
pollutionView
=
PollutantView
()
stackView
.
addArrangedSubview
(
pollutionView
)
}
}
stackView
.
layoutIfNeeded
()
}
var
coefficient
:
CGFloat
=
1.0
let
desiredMinProgress
:
CGFloat
=
0.3
if
maxPollutantProgress
<
desiredMinProgress
{
coefficient
=
desiredMinProgress
/
maxPollutantProgress
}
for
(
index
,
pollutant
)
in
pollutants
.
enumerated
()
{
guard
let
pollutantView
=
stackView
.
arrangedSubviews
[
index
]
as?
PollutantView
else
{
continue
}
pollutantView
.
configure
(
pollutant
:
pollutant
,
progressCoefficient
:
coefficient
)
}
// stackView.removeAll()
// if let pollutants = health?.pollutants.values,
// let maxPollutantProgress: CGFloat = pollutants.max(by: { $0.progress < $1.progress })?.progress {
// var coefficient: CGFloat = 1.0
// let desiredMinProgress: CGFloat = 0.3
// if maxPollutantProgress < desiredMinProgress {
// coefficient = desiredMinProgress / maxPollutantProgress
// }
// for pollutant in pollutants {
// let pollutionView = PollutantView()
// pollutionView.configure(pollutant: pollutant, progressCoefficient: coefficient)
// stackView.addArrangedSubview(pollutionView)
// }
// }
// stackView.layoutIfNeeded()
}
}
...
...
1Weather/UI/View controllers/Today/Cells/TodayConditions/TodayConditionButton.swift
View file @
d735d7db
...
...
@@ -28,6 +28,11 @@ class TodayConditionButton: UIControl {
prepareLabels
()
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
self
.
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
self
.
bounds
,
cornerRadius
:
12
)
.
cgPath
}
public
func
configure
(
with
location
:
Location
)
{
switch
conditionType
{
case
.
precipitation
:
...
...
1Weather/UI/View controllers/Today/Cells/TodayDayTimesCell/TodayDayTimesCell.swift
View file @
d735d7db
...
...
@@ -53,23 +53,38 @@ class TodayDayTimesCell: UITableViewCell {
//Public
public
func
configure
(
with
location
:
Location
)
{
stackView
.
removeAll
()
let
maxNumberOfItems
=
4
var
currentlyShowing
=
0
var
i
=
0
while
i
<
location
.
dayTimeForecast
.
count
&&
currentlyShowing
<
maxNumberOfItems
{
let
dayTimeWeather
=
location
.
dayTimeForecast
[
i
]
i
+=
1
if
dayTimeWeather
.
date
>=
Date
()
{
let
view
=
DayTimeView
(
dayTimeWeather
:
dayTimeWeather
,
withSeparator
:
currentlyShowing
!=
maxNumberOfItems
-
1
)
guard
!
location
.
dayTimeForecast
.
isEmpty
else
{
return
}
var
validDayTimeWeather
=
[
DayTimeWeather
]()
for
index
in
0
..<
location
.
dayTimeForecast
.
count
{
if
location
.
dayTimeForecast
[
index
]
.
date
>=
Date
()
{
validDayTimeWeather
.
append
(
location
.
dayTimeForecast
[
index
])
}
}
if
stackView
.
arrangedSubviews
.
isEmpty
{
for
index
in
0
..<
maxNumberOfItems
{
let
view
=
DayTimeView
(
dayTimeWeather
:
validDayTimeWeather
[
index
],
withSeparator
:
index
!=
maxNumberOfItems
-
1
)
stackView
.
addArrangedSubview
(
view
)
currentlyShowing
+=
1
}
stackView
.
layoutIfNeeded
()
return
}
if
stackView
.
arrangedSubviews
.
count
==
maxNumberOfItems
{
for
(
index
,
arrangedSubview
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
guard
let
dayTimeView
=
arrangedSubview
as?
DayTimeView
else
{
continue
}
dayTimeView
.
configure
(
with
:
validDayTimeWeather
[
index
])
}
}
stackView
.
layoutIfNeeded
()
}
}
...
...
1Weather/UI/View controllers/Today/Cells/TodayForecastCell.swift
View file @
d735d7db
...
...
@@ -41,6 +41,11 @@ class TodayForecastCell: UITableViewCell {
updateUI
()
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
container
.
layer
.
shadowPath
=
UIBezierPath
(
roundedRect
:
container
.
bounds
,
cornerRadius
:
12
)
.
cgPath
}
//Public
public
func
configure
(
with
location
:
Location
)
{
cityImageView
.
image
=
WeatherImageProvider
()
.
imageFor
(
location
:
location
)
...
...
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