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
6609f62d
Commit
6609f62d
authored
Sep 03, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS-259: fix potential duplicate WIDGET_UPDATE.
parent
c2fa601a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
34 deletions
+31
-34
OneWeatherCore/OneWeatherCore/Managers/WidgetManager.swift
+14
-23
OneWeatherWidget/Data/WeatherProvider.swift
+13
-7
OneWeatherWidget/Widgets/PrecipitationWidget.swift
+1
-1
OneWeatherWidget/Widgets/RadarWidget.swift
+1
-1
OneWeatherWidget/Widgets/TemperatureWidget.swift
+1
-1
OneWeatherWidget/Widgets/WindWidget.swift
+1
-1
No files found.
OneWeatherCore/OneWeatherCore/Managers/WidgetManager.swift
View file @
6609f62d
...
...
@@ -133,31 +133,22 @@ public class WidgetManager {
params
:
[
.
ANALYTICS_KEY_WIDGET_NAME
:
name
])
}
public
func
logUpdate
(
forLocation
location
:
Location
?)
{
WidgetCenter
.
shared
.
getCurrentConfigurations
{[
weak
self
]
result
in
switch
result
{
case
.
success
(
let
widgetInfo
):
for
info
in
widgetInfo
{
if
let
option
=
WidgetOptions
.
option
(
forKind
:
info
.
kind
,
family
:
info
.
family
)
{
let
name
=
WidgetOptions
.
name
(
for
:
option
)
var
params
:
[
AnalyticsParameter
:
String
]
=
[
.
ANALYTICS_KEY_WIDGET_NAME
:
name
]
// Radar widget doesn't have smart text (IOS-260).
// TODO: this needs to be unified. Any widget not using smart text shouldn't have that parameter.
if
option
!=
.
radarLarge
{
if
let
updatedLocation
=
location
{
let
smartText
=
self
?
.
smartTextProvider
.
smartText
(
for
:
updatedLocation
)
??
""
params
[
.
ANALYTICS_KEY_WIDGET_SMART_TEXT
]
=
#
"
\
#(smartText)"
#
}
}
AppAnalytics
.
shared
.
log
(
event
:
.
ANALYTICS_WIDGET_UPDATED
,
params
:
params
)
}
public
func
logUpdate
(
forLocation
location
:
Location
?,
kind
:
String
,
family
:
WidgetFamily
)
{
if
let
option
=
WidgetOptions
.
option
(
forKind
:
kind
,
family
:
family
)
{
let
name
=
WidgetOptions
.
name
(
for
:
option
)
var
params
:
[
AnalyticsParameter
:
String
]
=
[
.
ANALYTICS_KEY_WIDGET_NAME
:
name
]
// Radar widget doesn't have smart text (IOS-260).
// TODO: this needs to be unified. Any widget not using smart text shouldn't have that parameter.
if
option
!=
.
radarLarge
{
if
let
updatedLocation
=
location
{
let
smartText
=
smartTextProvider
.
smartText
(
for
:
updatedLocation
)
params
[
.
ANALYTICS_KEY_WIDGET_SMART_TEXT
]
=
#
"
\
#(smartText)"
#
}
case
.
failure
(
let
error
):
self
?
.
log
.
error
(
error
.
localizedDescription
)
}
AppAnalytics
.
shared
.
log
(
event
:
.
ANALYTICS_WIDGET_UPDATED
,
params
:
params
)
}
}
...
...
OneWeatherWidget/Data/WeatherProvider.swift
View file @
6609f62d
...
...
@@ -21,10 +21,10 @@ class WeatherProvider: TimelineProvider {
private
let
needsRadar
:
Bool
private
var
weatherSource
:
WeatherSource
private
let
locationSource
:
WidgetLocationSource
private
let
widget
Type
:
String
private
let
widget
Kind
:
String
public
init
(
widget
Type
:
String
,
locationSource
:
WidgetLocationSource
=
WidgetLocationSource
.
shared
,
weatherSource
:
WeatherSource
=
WdtWeatherSource
(),
needsRadar
:
Bool
)
{
self
.
widget
Type
=
widgetType
public
init
(
widget
Kind
:
String
,
locationSource
:
WidgetLocationSource
=
WidgetLocationSource
.
shared
,
weatherSource
:
WeatherSource
=
WdtWeatherSource
(),
needsRadar
:
Bool
)
{
self
.
widget
Kind
=
widgetKind
self
.
locationSource
=
locationSource
self
.
weatherSource
=
weatherSource
self
.
needsRadar
=
needsRadar
...
...
@@ -42,6 +42,7 @@ class WeatherProvider: TimelineProvider {
func
getTimeline
(
in
context
:
Context
,
completion
:
@escaping
(
Timeline
<
WeatherEntry
>
)
->
Void
)
{
locationSource
.
getUpToDateLocation
{
[
weak
self
]
location
in
guard
let
self
=
self
else
{
return
}
var
needToLogUpdate
=
false
if
let
fetchedLocation
=
location
,
let
coordinates
=
fetchedLocation
.
coordinates
...
...
@@ -54,7 +55,7 @@ class WeatherProvider: TimelineProvider {
let
nextRefresh
=
Calendar
.
current
.
date
(
byAdding
:
.
minute
,
value
:
30
,
to
:
Date
())
!
let
entry
=
WeatherEntry
(
location
:
fetchedLocation
,
date
:
nextRefresh
,
radarMapImage
:
mapImage
)
let
timeline
=
Timeline
(
entries
:
[
entry
],
policy
:
.
atEnd
)
WidgetManager
.
shared
.
logUpdate
(
forLocation
:
fetchedLocation
)
needToLogUpdate
=
true
completion
(
timeline
)
}
}
...
...
@@ -62,7 +63,7 @@ class WeatherProvider: TimelineProvider {
let
nextRefresh
=
Calendar
.
current
.
date
(
byAdding
:
.
minute
,
value
:
30
,
to
:
Date
())
!
let
entry
=
WeatherEntry
(
location
:
fetchedLocation
,
date
:
nextRefresh
,
radarMapImage
:
nil
)
let
timeline
=
Timeline
(
entries
:
[
entry
],
policy
:
.
atEnd
)
WidgetManager
.
shared
.
logUpdate
(
forLocation
:
fetchedLocation
)
needToLogUpdate
=
true
completion
(
timeline
)
}
}
...
...
@@ -70,11 +71,16 @@ class WeatherProvider: TimelineProvider {
let
nextRefresh
=
Calendar
.
current
.
date
(
byAdding
:
.
minute
,
value
:
30
,
to
:
Date
())
!
let
entry
=
WeatherEntry
(
location
:
location
,
date
:
nextRefresh
)
let
timeline
=
Timeline
(
entries
:
[
entry
],
policy
:
.
atEnd
)
WidgetManager
.
shared
.
logUpdate
(
forLocation
:
location
)
needToLogUpdate
=
true
completion
(
timeline
)
}
WidgetManager
.
shared
.
refreshAnalytics
()
if
!
context
.
isPreview
{
WidgetManager
.
shared
.
refreshAnalytics
()
if
needToLogUpdate
{
WidgetManager
.
shared
.
logUpdate
(
forLocation
:
location
,
kind
:
self
.
widgetKind
,
family
:
context
.
family
)
}
}
}
}
}
OneWeatherWidget/Widgets/PrecipitationWidget.swift
View file @
6609f62d
...
...
@@ -17,7 +17,7 @@ struct PrecipitationWidget: Widget {
// We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration
(
kind
:
kind
,
provider
:
WeatherProvider
(
widget
Type
:
kind
.
components
(
separatedBy
:
"."
)
.
last
??
"-"
,
needsRadar
:
false
)
provider
:
WeatherProvider
(
widget
Kind
:
kind
,
needsRadar
:
false
)
)
{
weatherEntry
in
MediumPrecipitationWidgetView
(
widgetViewModel
:
ForecastWidgetViewModel
(
location
:
weatherEntry
.
location
))
.
widgetURL
(
URL
(
string
:
"ow-widget://precipitation-medium"
))
...
...
OneWeatherWidget/Widgets/RadarWidget.swift
View file @
6609f62d
...
...
@@ -17,7 +17,7 @@ struct RadarWidget: Widget {
// We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration
(
kind
:
kind
,
provider
:
WeatherProvider
(
widget
Type
:
kind
.
components
(
separatedBy
:
"."
)
.
last
??
"-"
,
needsRadar
:
true
)
provider
:
WeatherProvider
(
widget
Kind
:
kind
,
needsRadar
:
true
)
)
{
weatherEntry
in
LargeRadarWidgetView
(
widgetViewModel
:
ForecastWidgetViewModel
(
location
:
weatherEntry
.
location
,
radarImage
:
weatherEntry
.
radarMapImage
))
...
...
OneWeatherWidget/Widgets/TemperatureWidget.swift
View file @
6609f62d
...
...
@@ -17,7 +17,7 @@ struct TemperatureWidget: Widget {
// We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration
(
kind
:
kind
,
provider
:
WeatherProvider
(
widget
Type
:
kind
.
components
(
separatedBy
:
"."
)
.
last
??
"-"
,
needsRadar
:
false
)
provider
:
WeatherProvider
(
widget
Kind
:
kind
,
needsRadar
:
false
)
)
{
weatherEntry
in
WidgetView
(
entry
:
weatherEntry
)
}
...
...
OneWeatherWidget/Widgets/WindWidget.swift
View file @
6609f62d
...
...
@@ -17,7 +17,7 @@ struct WindWidget: Widget {
// We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration
(
kind
:
kind
,
provider
:
WeatherProvider
(
widget
Type
:
kind
.
components
(
separatedBy
:
"."
)
.
last
??
"-"
,
needsRadar
:
false
)
provider
:
WeatherProvider
(
widget
Kind
:
kind
,
needsRadar
:
false
)
)
{
weatherEntry
in
WidgetView
(
entry
:
weatherEntry
)
}
...
...
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