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
04f0f45b
Commit
04f0f45b
authored
Apr 14, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The NavigationBar time is now the current time in the specified location.
parent
84a11e67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
12 deletions
+50
-12
1Weather/Resources/en.lproj/Localizable.strings
+3
-0
1Weather/UI/Buttons/NavigationCityButton.swift
+47
-12
No files found.
1Weather/Resources/en.lproj/Localizable.strings
View file @
04f0f45b
...
@@ -94,6 +94,9 @@
...
@@ -94,6 +94,9 @@
"tabBar.radar" = "radar";
"tabBar.radar" = "radar";
"tabBar.menu" = "menu";
"tabBar.menu" = "menu";
//Navigation bar
"navigationBar.noCityAvailable" = "N/A";
// Search
// Search
"search.add" = "add";
"search.add" = "add";
"search.popularCities" = "Popular cities";
"search.popularCities" = "Popular cities";
...
...
1Weather/UI/Buttons/NavigationCityButton.swift
View file @
04f0f45b
...
@@ -15,10 +15,22 @@ class NavigationCityButton: UIControl {
...
@@ -15,10 +15,22 @@ class NavigationCityButton: UIControl {
private
let
downArrowImageView
=
UIImageView
()
private
let
downArrowImageView
=
UIImageView
()
private
let
timeLabel
=
UILabel
()
private
let
timeLabel
=
UILabel
()
private
let
kSpaceForDownArrow
:
CGFloat
=
10
private
let
kSpaceForDownArrow
:
CGFloat
=
10
private
static
let
timeFormatter
:
DateFormatter
=
{
private
var
timer
:
Timer
?
private
var
timeZone
:
TimeZone
?
{
didSet
{
if
oldValue
!=
timeZone
{
if
let
timeZone
=
timeZone
{
timeFormatter
.
timeZone
=
timeZone
}
updateTime
()
}
}
}
private
let
timeFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
let
fmt
=
DateFormatter
()
fmt
.
dateFormat
=
"h:mm a"
fmt
.
timeStyle
=
.
short
fmt
.
dateFormat
=
.
none
return
fmt
return
fmt
}()
}()
...
@@ -57,19 +69,42 @@ class NavigationCityButton: UIControl {
...
@@ -57,19 +69,42 @@ class NavigationCityButton: UIControl {
}
}
public
func
configure
(
with
location
:
Location
?)
{
public
func
configure
(
with
location
:
Location
?)
{
guard
let
loc
=
location
else
{
self
.
cityLabel
.
text
=
location
?
.
cityName
??
"navigationBar.noCityAvailable"
.
localized
()
self
.
cityLabel
.
text
=
"N/A"
self
.
timeZone
=
location
?
.
timeZone
configureTimer
()
}
private
func
updateTime
()
{
if
timeZone
!=
nil
{
self
.
timeLabel
.
text
=
timeFormatter
.
string
(
from
:
Date
())
}
else
{
self
.
timeLabel
.
text
=
nil
self
.
timeLabel
.
text
=
nil
return
}
}
}
self
.
cityLabel
.
text
=
loc
.
cityName
if
let
today
=
loc
.
today
?
.
date
{
private
func
configureTimer
()
{
NavigationCityButton
.
timeFormatter
.
timeZone
=
loc
.
timeZone
if
let
timeZone
=
timeZone
{
self
.
timeLabel
.
text
=
NavigationCityButton
.
timeFormatter
.
string
(
from
:
today
)
if
timer
==
nil
{
var
calendar
=
Calendar
(
identifier
:
.
gregorian
)
calendar
.
timeZone
=
timeZone
var
dateComponents
=
calendar
.
dateComponents
([
.
year
,
.
month
,
.
day
,
.
hour
,
.
minute
,
.
second
],
from
:
Date
())
if
let
oldMinutes
=
dateComponents
.
minute
{
dateComponents
.
minute
=
oldMinutes
+
1
// dateComponents handle rolling over 60.
}
dateComponents
.
second
=
0
let
firstFireDate
=
calendar
.
date
(
from
:
dateComponents
)
??
Date
()
.
addingTimeInterval
(
5
)
let
newTimer
=
Timer
(
fire
:
firstFireDate
,
interval
:
30.0
,
repeats
:
true
,
block
:
{
[
weak
self
]
_
in
self
?
.
updateTime
()
})
RunLoop
.
main
.
add
(
newTimer
,
forMode
:
.
common
)
self
.
timer
=
newTimer
}
}
}
else
{
else
{
self
.
timeLabel
.
text
=
nil
timer
?
.
invalidate
()
timer
=
nil
}
}
}
}
}
}
...
...
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