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
b24d371c
Commit
b24d371c
authored
Apr 21, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alert on Today is filled with data.
parent
dd049516
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
6 deletions
+79
-6
1Weather/Network/Notifications/Model/NWSAlert.swift
+23
-2
1Weather/Resources/en.lproj/Localizable.strings
+6
-0
1Weather/UI/View controllers/Today/Cells/TodayAlertCell.swift
+46
-2
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
+4
-2
No files found.
1Weather/Network/Notifications/Model/NWSAlert.swift
View file @
b24d371c
...
@@ -7,13 +7,34 @@
...
@@ -7,13 +7,34 @@
import
Foundation
import
Foundation
public
enum
NWSSeverityLevel
:
String
,
Codable
{
public
enum
NWSSeverityLevel
:
String
,
Codable
,
Comparable
{
case
warning
=
"1"
case
warning
=
"1"
case
watch
=
"2"
case
watch
=
"2"
case
advisory
=
"3"
case
advisory
=
"3"
public
static
func
<
(
lhs
:
Self
,
rhs
:
Self
)
->
Bool
{
lhs
!=
rhs
&&
(
(
lhs
==
.
warning
)
||
(
lhs
==
.
watch
&&
rhs
==
.
advisory
)
)
}
public
static
func
<=
(
lhs
:
Self
,
rhs
:
Self
)
->
Bool
{
lhs
==
rhs
||
lhs
<
rhs
}
public
static
func
>=
(
lhs
:
Self
,
rhs
:
Self
)
->
Bool
{
lhs
==
rhs
||
lhs
>
rhs
}
public
static
func
>
(
lhs
:
Self
,
rhs
:
Self
)
->
Bool
{
lhs
!=
rhs
&&
!
(
lhs
<
rhs
)
}
}
}
public
struct
NWSAlert
:
Codable
,
Equatable
,
Hashable
{
public
struct
NWSAlert
:
Codable
,
Equatable
,
Hashable
{
public
var
issueDate
:
Date
?
public
let
weatherID
:
String
public
let
weatherID
:
String
public
let
messageID
:
String
public
let
messageID
:
String
public
let
messageURL
:
String
public
let
messageURL
:
String
...
@@ -37,7 +58,7 @@ public struct NWSAlert: Codable, Equatable, Hashable {
...
@@ -37,7 +58,7 @@ public struct NWSAlert: Codable, Equatable, Hashable {
}
}
public
var
expired
:
Bool
{
public
var
expired
:
Bool
{
return
Date
()
<
expires
return
Date
()
>
expires
}
}
// MARK: Equatable implementation
// MARK: Equatable implementation
...
...
1Weather/Resources/en.lproj/Localizable.strings
View file @
b24d371c
...
@@ -11,6 +11,12 @@
...
@@ -11,6 +11,12 @@
"general.more" = "more";
"general.more" = "more";
"general.search" = "search";
"general.search" = "search";
//Alert
"today.alert.infoTemplate.oneAlert" = "#ALERT_DESCRIPTION";
"today.alert.infoTemplate.twoAlerts" = "#ALERT_DESCRIPTION and 1 more alert";
"today.alert.infoTemplate.overTwoAlerts" = "#ALERT_DESCRIPTION and #REMAINING_ALERTS_COUNT more alerts";
"today.alert.timeAgoTemplate" = "#TIME_AGO ago";
//Forecast
//Forecast
"forecast.sunny" = "Sunny";
"forecast.sunny" = "Sunny";
"forecast.cloudy" = "Cloudy";
"forecast.cloudy" = "Cloudy";
...
...
1Weather/UI/View controllers/Today/Cells/TodayAlertCell.swift
View file @
b24d371c
...
@@ -55,6 +55,50 @@ class TodayAlertCell: UITableViewCell {
...
@@ -55,6 +55,50 @@ class TodayAlertCell: UITableViewCell {
container
.
layer
.
shadowOpacity
=
1.0
container
.
layer
.
shadowOpacity
=
1.0
}
}
}
}
public
func
configure
(
location
:
Location
)
{
infoLabel
.
text
=
""
timeAgoLabel
.
text
=
""
if
let
alerts
=
location
.
notifications
?
.
nwsAlers
.
filter
(
{
!
$0
.
expired
})
{
if
let
firstAlert
=
alerts
.
first
{
var
mostSevereAlert
=
firstAlert
for
alert
in
alerts
{
if
alert
.
severityLevel
>
mostSevereAlert
.
severityLevel
{
mostSevereAlert
=
alert
}
}
let
infoTemplateAlertDescriptionKey
=
"#ALERT_DESCRIPTION"
let
infoTemplateRemainingAlertsCountKey
=
"#REMAINING_ALERTS_COUNT"
var
infoTemplate
=
"today.alert.infoTemplate.overTwoAlerts"
.
localized
()
if
alerts
.
count
==
1
{
infoTemplate
=
"today.alert.infoTemplate.oneAlert"
.
localized
()
}
else
if
alerts
.
count
==
2
{
infoTemplate
=
"today.alert.infoTemplate.twoAlerts"
.
localized
()
}
infoTemplate
=
infoTemplate
.
replacingOccurrences
(
of
:
infoTemplateAlertDescriptionKey
,
with
:
mostSevereAlert
.
description
)
infoTemplate
=
infoTemplate
.
replacingOccurrences
(
of
:
infoTemplateRemainingAlertsCountKey
,
with
:
"
\(
alerts
.
count
-
1
)
"
)
infoLabel
.
text
=
infoTemplate
if
let
issueDate
=
mostSevereAlert
.
issueDate
{
let
secondsAgo
=
Date
()
.
timeIntervalSince
(
issueDate
)
let
formatter
=
DateComponentsFormatter
()
formatter
.
allowedUnits
=
[
.
day
,
.
hour
,
.
minute
,
.
second
]
formatter
.
unitsStyle
=
.
short
formatter
.
maximumUnitCount
=
1
let
timeAgoTemplateTimeAgoKey
=
"#TIME_AGO"
if
let
formattedTime
=
formatter
.
string
(
from
:
secondsAgo
)
{
timeAgoLabel
.
text
=
"today.alert.timeAgoTemplate"
.
localized
()
.
replacingOccurrences
(
of
:
timeAgoTemplateTimeAgoKey
,
with
:
formattedTime
)
}
}
}
}
}
}
}
//MARK:- Prepare
//MARK:- Prepare
...
@@ -88,11 +132,11 @@ private extension TodayAlertCell {
...
@@ -88,11 +132,11 @@ private extension TodayAlertCell {
infoLabel
.
numberOfLines
=
2
infoLabel
.
numberOfLines
=
2
infoLabel
.
lineBreakMode
=
.
byWordWrapping
infoLabel
.
lineBreakMode
=
.
byWordWrapping
infoLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
infoLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
16
)
infoLabel
.
text
=
"Frost Advisory and 2 more alerts"
infoLabel
.
text
=
"
"
// E.g. "
Frost Advisory and 2 more alerts"
container
.
addSubview
(
infoLabel
)
container
.
addSubview
(
infoLabel
)
timeAgoLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
14
)
timeAgoLabel
.
font
=
AppFont
.
SFPro
.
regular
(
size
:
14
)
timeAgoLabel
.
text
=
"5 mins ago"
timeAgoLabel
.
text
=
"
"
// E.g. "
5 mins ago"
timeAgoLabel
.
textAlignment
=
.
right
timeAgoLabel
.
textAlignment
=
.
right
container
.
addSubview
(
timeAgoLabel
)
container
.
addSubview
(
timeAgoLabel
)
...
...
1Weather/UI/View controllers/Today/Cells/TodayCellFactory.swift
View file @
b24d371c
...
@@ -104,7 +104,9 @@ class TodayCellFactory: CellFactoryProtocol {
...
@@ -104,7 +104,9 @@ class TodayCellFactory: CellFactoryProtocol {
switch
cellType
{
switch
cellType
{
case
.
alert
:
case
.
alert
:
return
dequeueReusableCell
(
type
:
TodayAlertCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
let
cell
=
dequeueReusableCell
(
type
:
TodayAlertCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
configure
(
location
:
loc
)
return
cell
case
.
forecast
:
case
.
forecast
:
let
cell
=
dequeueReusableCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
let
cell
=
dequeueReusableCell
(
type
:
TodayForecastCell
.
self
,
tableView
:
tableView
,
indexPath
:
indexPath
)
cell
.
configure
(
with
:
loc
)
cell
.
configure
(
with
:
loc
)
...
@@ -191,7 +193,7 @@ class TodayCellFactory: CellFactoryProtocol {
...
@@ -191,7 +193,7 @@ class TodayCellFactory: CellFactoryProtocol {
}
}
let
location
=
self
.
todayViewModel
.
location
let
location
=
self
.
todayViewModel
.
location
if
location
?
.
notifications
?
.
nwsAlers
.
count
??
0
==
0
{
if
location
?
.
notifications
?
.
nwsAlers
.
filter
({
!
$0
.
expired
})
.
count
??
0
==
0
{
rowsToHide
.
insert
(
.
alert
)
rowsToHide
.
insert
(
.
alert
)
}
}
...
...
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