diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index b7aee79..c84328b 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -131,6 +131,7 @@ 65DBFB7425E2BBF20041CBA6 /* GADTMediumTemplateView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65DBFB6F25E2BBF20041CBA6 /* GADTMediumTemplateView.xib */; }; 65DBFB7525E2BBF20041CBA6 /* GADTMediumTemplateView.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DBFB7125E2BBF20041CBA6 /* GADTMediumTemplateView.m */; }; 65DBFB7625E2BBF20041CBA6 /* GADTTemplateView.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DBFB7225E2BBF20041CBA6 /* GADTTemplateView.m */; }; + 65E1B19B260F980600A0ACBA /* Dictionary+EQNExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E1B19A260F980600A0ACBA /* Dictionary+EQNExtensions.swift */; }; 8C10B0B92281FE7F00125C9F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8C10B0BD2281FE7F00125C9F /* Localizable.strings */; }; 8C10B0BA2281FE7F00125C9F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8C10B0BD2281FE7F00125C9F /* Localizable.strings */; }; 8C10B0BB2281FE7F00125C9F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8C10B0BD2281FE7F00125C9F /* Localizable.strings */; }; @@ -402,6 +403,7 @@ 65DBFB7125E2BBF20041CBA6 /* GADTMediumTemplateView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GADTMediumTemplateView.m; sourceTree = ""; }; 65DBFB7225E2BBF20041CBA6 /* GADTTemplateView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GADTTemplateView.m; sourceTree = ""; }; 65DBFB7325E2BBF20041CBA6 /* GADTMediumTemplateView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GADTMediumTemplateView.h; sourceTree = ""; }; + 65E1B19A260F980600A0ACBA /* Dictionary+EQNExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+EQNExtensions.swift"; sourceTree = ""; }; 8C10B0AF2281FBE800125C9F /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Main.strings; sourceTree = ""; }; 8C10B0B02281FBE800125C9F /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/LaunchScreen.strings; sourceTree = ""; }; 8C10B0B12281FBE800125C9F /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/MainInterface.strings; sourceTree = ""; }; @@ -734,6 +736,7 @@ DC105640251E7ECE002579BB /* UIFont+Extensions.swift */, 8C7A3B65225A5EA40045B266 /* NSDictionary+EQNExtensions.h */, 8C7A3B64225A5EA30045B266 /* NSDictionary+EQNExtensions.m */, + 65E1B19A260F980600A0ACBA /* Dictionary+EQNExtensions.swift */, ); path = Extensions; sourceTree = ""; @@ -1565,6 +1568,7 @@ DCBB84F0252CFC4600F12633 /* AlertsNoLocationTableViewCell.swift in Sources */, DCD3E3C024D15576007C78D4 /* PurchaseProVersionViewController.swift in Sources */, 651901B925F5358700CAFF20 /* EQNMapAnnotationSeismic.swift in Sources */, + 65E1B19B260F980600A0ACBA /* Dictionary+EQNExtensions.swift in Sources */, DC99A50324E66E270071BC9F /* EQNCommandProtocol.swift in Sources */, DCB45BC8250E86E100DB2D0C /* SeismicSettingsViewController.swift in Sources */, DCF10DC624D2B8C7009F34C3 /* EQNPurchaseUtility.swift in Sources */, diff --git a/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift b/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift index dfcc481..461e506 100644 --- a/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift +++ b/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift @@ -62,10 +62,7 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa let aps = notification["aps"] as? [String: Any], let alert = aps["alert"] as? [String: Any] else { return } - var intensity = -1 - if let intensityString = notification["intensity"] as? String, let anIntensity = Int(intensityString) { - intensity = anIntensity - } + let intensity = notification.eqn_intValue(for: "intensity") ?? 0 containerView.backgroundColor = color(for: intensity) if let title = alert["loc-key"] as? String, let args = alert["loc-args"] as? [String], let arg = args.first { @@ -74,8 +71,8 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa // get coordinate var coordinate: CLLocation? - if let latitudeString = notification["latitude"] as? String, let latitude = Double(latitudeString), - let longitudeString = notification["longitude"] as? String, let longitude = Double(longitudeString) { + if let latitude = notification.eqn_doubleValue(for: "latitude"), + let longitude = notification.eqn_doubleValue(for: "longitude") { coordinate = CLLocation(latitude: latitude, longitude: longitude) } diff --git a/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift b/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift new file mode 100644 index 0000000..73168e6 --- /dev/null +++ b/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift @@ -0,0 +1,31 @@ +// +// Dictionary+EQNExtensions.swift +// Earthquake Network +// +// Created by Andrea Busi on 27/03/21. +// Copyright © 2021 Earthquake Network. All rights reserved. +// + +import Foundation + + +extension Dictionary { + + func eqn_intValue(for key: Key) -> Int? { + if let value = self[key] as? Int { + return value + } else if let stringValue = self[key] as? String, let value = Int(stringValue) { + return value + } + return nil + } + + func eqn_doubleValue(for key: Key) -> Double? { + if let value = self[key] as? Double { + return value + } else if let stringValue = self[key] as? String, let value = Double(stringValue) { + return value + } + return nil + } +}