Commit 6609f62d by Demid Merzlyakov

IOS-259: fix potential duplicate WIDGET_UPDATE.

parent c2fa601a
...@@ -133,12 +133,8 @@ public class WidgetManager { ...@@ -133,12 +133,8 @@ public class WidgetManager {
params: [.ANALYTICS_KEY_WIDGET_NAME : name]) params: [.ANALYTICS_KEY_WIDGET_NAME : name])
} }
public func logUpdate(forLocation location: Location?) { public func logUpdate(forLocation location: Location?, kind: String, family: WidgetFamily) {
WidgetCenter.shared.getCurrentConfigurations {[weak self] result in if let option = WidgetOptions.option(forKind: kind, family: family) {
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) let name = WidgetOptions.name(for: option)
var params: [AnalyticsParameter : String] = [.ANALYTICS_KEY_WIDGET_NAME : name] var params: [AnalyticsParameter : String] = [.ANALYTICS_KEY_WIDGET_NAME : name]
...@@ -146,7 +142,7 @@ public class WidgetManager { ...@@ -146,7 +142,7 @@ public class WidgetManager {
// TODO: this needs to be unified. Any widget not using smart text shouldn't have that parameter. // TODO: this needs to be unified. Any widget not using smart text shouldn't have that parameter.
if option != .radarLarge { if option != .radarLarge {
if let updatedLocation = location { if let updatedLocation = location {
let smartText = self?.smartTextProvider.smartText(for: updatedLocation) ?? "" let smartText = smartTextProvider.smartText(for: updatedLocation)
params[.ANALYTICS_KEY_WIDGET_SMART_TEXT] = #"\#(smartText)"# params[.ANALYTICS_KEY_WIDGET_SMART_TEXT] = #"\#(smartText)"#
} }
} }
...@@ -155,11 +151,6 @@ public class WidgetManager { ...@@ -155,11 +151,6 @@ public class WidgetManager {
params: params) params: params)
} }
} }
case .failure(let error):
self?.log.error(error.localizedDescription)
}
}
}
private func sync(with widgetInfo: [WidgetInfo]) { private func sync(with widgetInfo: [WidgetInfo]) {
var currentOptions: WidgetOptions = [] var currentOptions: WidgetOptions = []
......
...@@ -21,10 +21,10 @@ class WeatherProvider: TimelineProvider { ...@@ -21,10 +21,10 @@ class WeatherProvider: TimelineProvider {
private let needsRadar: Bool private let needsRadar: Bool
private var weatherSource: WeatherSource private var weatherSource: WeatherSource
private let locationSource: WidgetLocationSource private let locationSource: WidgetLocationSource
private let widgetType: String private let widgetKind: String
public init(widgetType: String, locationSource: WidgetLocationSource = WidgetLocationSource.shared, weatherSource: WeatherSource = WdtWeatherSource(), needsRadar: Bool) { public init(widgetKind: String, locationSource: WidgetLocationSource = WidgetLocationSource.shared, weatherSource: WeatherSource = WdtWeatherSource(), needsRadar: Bool) {
self.widgetType = widgetType self.widgetKind = widgetKind
self.locationSource = locationSource self.locationSource = locationSource
self.weatherSource = weatherSource self.weatherSource = weatherSource
self.needsRadar = needsRadar self.needsRadar = needsRadar
...@@ -42,6 +42,7 @@ class WeatherProvider: TimelineProvider { ...@@ -42,6 +42,7 @@ class WeatherProvider: TimelineProvider {
func getTimeline(in context: Context, completion: @escaping (Timeline<WeatherEntry>) -> Void) { func getTimeline(in context: Context, completion: @escaping (Timeline<WeatherEntry>) -> Void) {
locationSource.getUpToDateLocation { [weak self] location in locationSource.getUpToDateLocation { [weak self] location in
guard let self = self else { return } guard let self = self else { return }
var needToLogUpdate = false
if if
let fetchedLocation = location, let fetchedLocation = location,
let coordinates = fetchedLocation.coordinates let coordinates = fetchedLocation.coordinates
...@@ -54,7 +55,7 @@ class WeatherProvider: TimelineProvider { ...@@ -54,7 +55,7 @@ class WeatherProvider: TimelineProvider {
let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())! let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())!
let entry = WeatherEntry(location: fetchedLocation, date: nextRefresh, radarMapImage: mapImage) let entry = WeatherEntry(location: fetchedLocation, date: nextRefresh, radarMapImage: mapImage)
let timeline = Timeline(entries: [entry], policy: .atEnd) let timeline = Timeline(entries: [entry], policy: .atEnd)
WidgetManager.shared.logUpdate(forLocation: fetchedLocation) needToLogUpdate = true
completion(timeline) completion(timeline)
} }
} }
...@@ -62,7 +63,7 @@ class WeatherProvider: TimelineProvider { ...@@ -62,7 +63,7 @@ class WeatherProvider: TimelineProvider {
let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())! let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())!
let entry = WeatherEntry(location: fetchedLocation, date: nextRefresh, radarMapImage: nil) let entry = WeatherEntry(location: fetchedLocation, date: nextRefresh, radarMapImage: nil)
let timeline = Timeline(entries: [entry], policy: .atEnd) let timeline = Timeline(entries: [entry], policy: .atEnd)
WidgetManager.shared.logUpdate(forLocation: fetchedLocation) needToLogUpdate = true
completion(timeline) completion(timeline)
} }
} }
...@@ -70,11 +71,16 @@ class WeatherProvider: TimelineProvider { ...@@ -70,11 +71,16 @@ class WeatherProvider: TimelineProvider {
let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())! let nextRefresh = Calendar.current.date(byAdding: .minute, value: 30, to: Date())!
let entry = WeatherEntry(location: location, date: nextRefresh) let entry = WeatherEntry(location: location, date: nextRefresh)
let timeline = Timeline(entries: [entry], policy: .atEnd) let timeline = Timeline(entries: [entry], policy: .atEnd)
WidgetManager.shared.logUpdate(forLocation: location) needToLogUpdate = true
completion(timeline) completion(timeline)
} }
if !context.isPreview {
WidgetManager.shared.refreshAnalytics() WidgetManager.shared.refreshAnalytics()
if needToLogUpdate {
WidgetManager.shared.logUpdate(forLocation: location, kind: self.widgetKind, family: context.family)
}
}
} }
} }
} }
...@@ -17,7 +17,7 @@ struct PrecipitationWidget: Widget { ...@@ -17,7 +17,7 @@ struct PrecipitationWidget: Widget {
// We currently display selectedLocation, so it's not really configurable, // We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point. // but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration(kind: kind, StaticConfiguration(kind: kind,
provider: WeatherProvider(widgetType: kind.components(separatedBy: ".").last ?? "-", needsRadar: false) provider: WeatherProvider(widgetKind: kind, needsRadar: false)
) { weatherEntry in ) { weatherEntry in
MediumPrecipitationWidgetView(widgetViewModel: ForecastWidgetViewModel(location: weatherEntry.location)) MediumPrecipitationWidgetView(widgetViewModel: ForecastWidgetViewModel(location: weatherEntry.location))
.widgetURL(URL(string: "ow-widget://precipitation-medium")) .widgetURL(URL(string: "ow-widget://precipitation-medium"))
......
...@@ -17,7 +17,7 @@ struct RadarWidget: Widget { ...@@ -17,7 +17,7 @@ struct RadarWidget: Widget {
// We currently display selectedLocation, so it's not really configurable, // We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point. // but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration(kind: kind, StaticConfiguration(kind: kind,
provider: WeatherProvider(widgetType: kind.components(separatedBy: ".").last ?? "-", needsRadar: true) provider: WeatherProvider(widgetKind: kind, needsRadar: true)
) { weatherEntry in ) { weatherEntry in
LargeRadarWidgetView(widgetViewModel: ForecastWidgetViewModel(location: weatherEntry.location, LargeRadarWidgetView(widgetViewModel: ForecastWidgetViewModel(location: weatherEntry.location,
radarImage: weatherEntry.radarMapImage)) radarImage: weatherEntry.radarMapImage))
......
...@@ -17,7 +17,7 @@ struct TemperatureWidget: Widget { ...@@ -17,7 +17,7 @@ struct TemperatureWidget: Widget {
// We currently display selectedLocation, so it's not really configurable, // We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point. // but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration(kind: kind, StaticConfiguration(kind: kind,
provider: WeatherProvider(widgetType: kind.components(separatedBy: ".").last ?? "-", needsRadar: false) provider: WeatherProvider(widgetKind: kind, needsRadar: false)
) { weatherEntry in ) { weatherEntry in
WidgetView(entry: weatherEntry) WidgetView(entry: weatherEntry)
} }
......
...@@ -17,7 +17,7 @@ struct WindWidget: Widget { ...@@ -17,7 +17,7 @@ struct WindWidget: Widget {
// We currently display selectedLocation, so it's not really configurable, // We currently display selectedLocation, so it's not really configurable,
// but we'll probably need to switch to an IntentConfiguration at some point. // but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration(kind: kind, StaticConfiguration(kind: kind,
provider: WeatherProvider(widgetType: kind.components(separatedBy: ".").last ?? "-", needsRadar: false) provider: WeatherProvider(widgetKind: kind, needsRadar: false)
) { weatherEntry in ) { weatherEntry in
WidgetView(entry: weatherEntry) WidgetView(entry: weatherEntry)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment