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
7c4248a5
Commit
7c4248a5
authored
May 07, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Legacy migration: migrate old locations without reverse geocoding when possible.
parent
45366f35
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
33 deletions
+48
-33
1Weather/Model/DeviceLocationMonitor.swift
+10
-30
1Weather/Model/LocationManager.swift
+21
-2
1Weather/Model/ModelObjects/GeoNamesPlace.swift
+4
-1
1Weather/Model/ModelObjects/Location.swift
+4
-0
1Weather/Model/Protocols/PartialLocation.swift
+2
-0
1Weather/Storage/LegacyMigrationManager.swift
+4
-0
1Weather/Storage/LegacyWdtLocation.swift
+3
-0
No files found.
1Weather/Model/DeviceLocationMonitor.swift
View file @
7c4248a5
...
...
@@ -63,13 +63,9 @@ internal class DeviceLocationMonitor: NSObject {
}
public
struct
DeviceLocation
:
PartialLocation
{
public
var
nickname
:
String
?
{
return
nil
}
public
var
selected
:
Bool
?
{
return
nil
}
public
var
countryCode
:
String
?
public
let
nickname
:
String
?
=
nil
public
let
selected
:
Bool
?
=
nil
private
static
let
coordinatesStringAccuracy
=
6
// 6 digits after the dot
private
let
location
:
CLLocation
?
...
...
@@ -77,9 +73,7 @@ internal class DeviceLocationMonitor: NSObject {
self
.
location
=
location
}
public
var
deviceLocation
:
Bool
{
return
true
}
public
let
deviceLocation
:
Bool
=
true
public
var
lat
:
String
?
{
guard
let
coordinate
=
location
?
.
coordinate
else
{
...
...
@@ -95,30 +89,16 @@ internal class DeviceLocationMonitor: NSObject {
return
String
(
format
:
"%.
\(
DeviceLocation
.
coordinatesStringAccuracy
)
f"
,
coordinate
.
longitude
)
}
public
var
countryName
:
String
?
{
nil
}
public
var
region
:
String
?
{
nil
}
public
var
cityName
:
String
?
{
nil
}
public
let
countryName
:
String
?
=
nil
public
let
region
:
String
?
=
nil
public
let
cityName
:
String
?
=
nil
public
var
nameForDisplay
:
String
{
// this should never be called.
return
""
}
public
var
fipsCode
:
String
?
{
nil
}
public
var
optionalCityId
:
String
?
{
return
nil
}
public
let
fipsCode
:
String
?
=
nil
public
let
optionalCityId
:
String
?
=
nil
public
let
timeZoneIdentifier
:
String
?
=
nil
}
public
typealias
CurrentLocationCompletion
=
(
LocationRequestResult
)
->
()
...
...
1Weather/Model/LocationManager.swift
View file @
7c4248a5
...
...
@@ -482,13 +482,14 @@ public class LocationManager {
public
func
addIfNeeded
(
partialLocation
:
PartialLocation
,
selectLocation
:
Bool
,
completion
:
@escaping
(
Bool
)
->
())
{
if
let
location
=
partialLocation
as?
Location
{
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
completion
(
true
)
}
else
{
makeLocation
(
from
:
partialLocation
)
{
(
location
)
in
onMain
{
[
weak
self
]
in
if
let
location
=
location
{
completion
(
true
)
self
?
.
addIfNeeded
(
location
:
location
,
selectLocation
:
selectLocation
)
completion
(
true
)
}
else
{
completion
(
false
)
...
...
@@ -572,6 +573,24 @@ public class LocationManager {
return
}
let
coordinates
=
CLLocationCoordinate2D
(
latitude
:
lat
,
longitude
:
lon
)
if
let
tzId
=
partialLocation
.
timeZoneIdentifier
,
let
timeZone
=
TimeZone
(
identifier
:
tzId
),
partialLocation
.
cityName
!=
nil
||
partialLocation
.
countryName
!=
nil
||
partialLocation
.
region
!=
nil
{
var
location
=
Location
(
deviceLocation
:
partialLocation
.
deviceLocation
,
timeZone
:
timeZone
)
location
.
cityName
=
partialLocation
.
cityName
location
.
countryName
=
partialLocation
.
countryName
location
.
countryCode
=
partialLocation
.
countryCode
location
.
fipsCode
=
partialLocation
.
fipsCode
location
.
coordinates
=
coordinates
location
.
region
=
partialLocation
.
region
location
.
nickname
=
partialLocation
.
nickname
log
.
debug
(
"Geo lookup: migrated legacy location without geocoding:
\(
location
)
"
)
completion
(
location
)
return
}
let
location
=
CLLocation
(
latitude
:
lat
,
longitude
:
lon
)
let
geocodeCompletion
:
CLGeocodeCompletionHandler
=
{
[
weak
self
]
(
placemarks
,
error
)
in
...
...
@@ -597,7 +616,7 @@ public class LocationManager {
}
result
=
Location
(
deviceLocation
:
partialLocation
.
deviceLocation
,
timeZone
:
timeZone
)
result
?
.
coordinates
=
CLLocationCoordinate2D
(
latitude
:
lat
,
longitude
:
lon
)
result
?
.
coordinates
=
coordinates
result
?
.
cityName
=
partialLocation
.
cityName
??
placemark
.
locality
result
?
.
countryName
=
partialLocation
.
countryName
??
placemark
.
country
result
?
.
countryCode
=
placemark
.
isoCountryCode
...
...
1Weather/Model/ModelObjects/GeoNamesPlace.swift
View file @
7c4248a5
...
...
@@ -103,7 +103,6 @@ extension GeoNamesPlace: PartialLocation {
var
selected
:
Bool
?
{
return
nil
}
var
nameForDisplay
:
String
{
//TODO: refactor this
...
...
@@ -162,4 +161,8 @@ extension GeoNamesPlace: PartialLocation {
var
cityName
:
String
?
{
return
city
}
var
timeZoneIdentifier
:
String
?
{
return
nil
}
}
1Weather/Model/ModelObjects/Location.swift
View file @
7c4248a5
...
...
@@ -230,6 +230,10 @@ extension Location: PartialLocation {
}
}
public
var
timeZoneIdentifier
:
String
?
{
timeZone
.
identifier
}
public
var
optionalCityId
:
String
?
{
cityId
}
...
...
1Weather/Model/Protocols/PartialLocation.swift
View file @
7c4248a5
...
...
@@ -13,12 +13,14 @@ public protocol PartialLocation {
var
lat
:
String
?
{
get
}
var
lon
:
String
?
{
get
}
var
countryName
:
String
?
{
get
}
var
countryCode
:
String
?
{
get
}
var
region
:
String
?
{
get
}
var
cityName
:
String
?
{
get
}
var
fipsCode
:
String
?
{
get
}
var
optionalCityId
:
String
?
{
get
}
var
nickname
:
String
?
{
get
}
var
selected
:
Bool
?
{
get
}
var
timeZoneIdentifier
:
String
?
{
get
}
var
nameForDisplay
:
String
{
get
}
}
1Weather/Storage/LegacyMigrationManager.swift
View file @
7c4248a5
...
...
@@ -41,12 +41,14 @@ class LegacyMigrationManager {
var
countryName
:
String
?
var
region
:
String
?
var
cityName
:
String
?
var
countryCode
:
String
?
var
fipsCode
:
String
?
let
optionalCityId
:
String
?
=
nil
var
nickname
:
String
?
var
nameForDisplay
:
String
{
"
\(
countryName
??
""
)
:
\(
region
??
""
)
:
\(
cityName
??
""
)
(
\(
nickname
??
""
)
) – @
\(
lat
??
""
)
;
\(
lon
??
""
)
; isDevice:
\(
deviceLocation
)
"
}
var
timeZoneIdentifier
:
String
?
}
private
var
lastMigrationResult
:
MigrationResult
?
{
...
...
@@ -132,10 +134,12 @@ class LegacyMigrationManager {
converted
.
lat
=
String
(
format
:
"%.8f"
,
legacyLocation
.
geoPointLat
)
converted
.
lon
=
String
(
format
:
"%.8f"
,
legacyLocation
.
geoPointLong
)
converted
.
countryName
=
legacyLocation
.
countryName
converted
.
countryCode
=
legacyLocation
.
country
converted
.
region
=
legacyLocation
.
region
converted
.
cityName
=
legacyLocation
.
city
converted
.
fipsCode
=
legacyLocation
.
fips
converted
.
selected
=
legacyLocation
.
selectedLocation
converted
.
timeZoneIdentifier
=
legacyLocation
.
timeZone
result
.
append
(
converted
)
}
self
.
lastMigrationResult
=
.
success
...
...
1Weather/Storage/LegacyWdtLocation.swift
View file @
7c4248a5
...
...
@@ -21,6 +21,7 @@ class LegacyWdtLocation: NSObject, NSCoding {
var
geoPointLat
:
Double
=
-
1
var
geoPointLong
:
Double
=
-
1
var
fips
:
String
?
var
timeZone
:
String
?
class
var
documentsFolder
:
String
{
...
...
@@ -55,6 +56,7 @@ class LegacyWdtLocation: NSObject, NSCoding {
self
.
myLocation
=
decoder
.
decodeBool
(
forKey
:
"myLocation"
)
self
.
selectedLocation
=
decoder
.
decodeBool
(
forKey
:
"selectedLocation"
)
self
.
fips
=
decoder
.
decodeObject
(
forKey
:
"fips"
)
as?
String
self
.
timeZone
=
decoder
.
decodeObject
(
forKey
:
"timezone"
)
as?
String
}
func
encode
(
with
coder
:
NSCoder
)
{
...
...
@@ -70,5 +72,6 @@ class LegacyWdtLocation: NSObject, NSCoding {
coder
.
encode
(
self
.
myLocation
,
forKey
:
"myLocation"
)
coder
.
encode
(
self
.
selectedLocation
,
forKey
:
"selectedLocation"
)
coder
.
encode
(
self
.
fips
,
forKey
:
"fips"
)
coder
.
encode
(
self
.
timeZone
,
forKey
:
"timezone"
)
}
}
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