From c6ec20e1807d5341cf1fc0f1f480375c795fb9b6 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Thu, 17 Nov 2022 09:22:06 +0100 Subject: [PATCH] refactor: Migrate some extensions usage to Shogun --- .../project.pbxproj | 18 ----------- ...micNotificationExpandedTableViewCell.swift | 7 +++-- .../InApp/SubscriptionsViewController.swift | 1 + .../SegnalazioniMapViewController.swift | 5 +-- .../Cells/SeismicNetworkTableViewCell.swift | 5 +-- .../SeismicFiltersViewController.swift | 1 + ...ismicNetworksMapDetailViewController.swift | 3 +- .../SeismicNetworksViewController.swift | 1 + .../AlertSimulatorViewController.swift | 3 +- .../Extensions/Dictionary+EQNExtensions.swift | 31 ------------------- .../Extensions/Foundation+EQNExtensions.swift | 29 ----------------- .../Libs/Extensions/UIFont+Extensions.swift | 19 ------------ .../Libs/Extensions/UIKit+Extensions.swift | 13 -------- .../Libs/StoryboardInitializable.swift | 25 --------------- .../Models/EQNRealtimeAlert.swift | 9 +++--- .../Models/EQNReteSmartphone.swift | 13 ++++---- .../EQNMapAnnotationUserReport.swift | 5 +-- 17 files changed, 32 insertions(+), 156 deletions(-) delete mode 100644 Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift delete mode 100644 Sources/Earthquake Network/Libs/Extensions/Foundation+EQNExtensions.swift delete mode 100644 Sources/Earthquake Network/Libs/Extensions/UIFont+Extensions.swift delete mode 100644 Sources/Earthquake Network/Libs/StoryboardInitializable.swift diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index a3eab54..bc89417 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -141,14 +141,11 @@ 65D409942619BA34008CF356 /* SegnalazioniSendReportCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D409932619BA34008CF356 /* SegnalazioniSendReportCell.swift */; }; 65D9938A29219DEC00F2B0EB /* UIKit+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65583A04261B83BE00ECA9F9 /* UIKit+Extensions.swift */; }; 65D9938C2922647800F2B0EB /* AppTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC52B8A424FCCD6900ABEBA6 /* AppTheme.swift */; }; - 65D9938E292264F800F2B0EB /* Foundation+EQNExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D9938D292264F800F2B0EB /* Foundation+EQNExtensions.swift */; }; - 65D9938F2922652100F2B0EB /* Foundation+EQNExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D9938D292264F800F2B0EB /* Foundation+EQNExtensions.swift */; }; 65DBFB4B25E29DD60041CBA6 /* SeismicNetworksMapDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DBFB4A25E29DD60041CBA6 /* SeismicNetworksMapDetailViewController.swift */; }; 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 */; }; 65E1226C285C92AA000E294A /* EQNRealtimeAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E1226B285C92AA000E294A /* EQNRealtimeAlert.swift */; }; - 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 */; }; @@ -206,7 +203,6 @@ DC0AE1B92538204100111307 /* EQNSegnalazione.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C593E89217BA2470008B260 /* EQNSegnalazione.m */; }; DC0AE1BA2538204100111307 /* EQNPastquakes.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CF4F4DA216D44930057110B /* EQNPastquakes.m */; }; DC0E551324F8063300D54270 /* SettingSegmentedTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0E551224F8063300D54270 /* SettingSegmentedTableViewCell.swift */; }; - DC105641251E7ECE002579BB /* UIFont+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC105640251E7ECE002579BB /* UIFont+Extensions.swift */; }; DC27EB2F24F6EBE000ACBFE0 /* SettingsSeismicNetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC27EB2E24F6EBE000ACBFE0 /* SettingsSeismicNetworksViewController.swift */; }; DC2814302519C24400C1AFF7 /* SeismicNetworkTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC28142F2519C24400C1AFF7 /* SeismicNetworkTableViewCell.swift */; }; DC2814382519C56100C1AFF7 /* SeismicNetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC2814372519C56100C1AFF7 /* SeismicNetworksViewController.swift */; }; @@ -217,7 +213,6 @@ DC4B67612517833F00634277 /* EQNSeismic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4B67602517833F00634277 /* EQNSeismic.swift */; }; DC52B8A224FC145500ABEBA6 /* SettingsBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC52B8A124FC145500ABEBA6 /* SettingsBaseViewController.m */; }; DC52B8A524FCCD6900ABEBA6 /* AppTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC52B8A424FCCD6900ABEBA6 /* AppTheme.swift */; }; - DC553AF625692E37000B521B /* StoryboardInitializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC553AF525692E37000B521B /* StoryboardInitializable.swift */; }; DC646F27252B694A000AA5FD /* AlertsSeismicNotificationExpandedTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC646F26252B694A000AA5FD /* AlertsSeismicNotificationExpandedTableViewCell.swift */; }; DC646F32252B698B000AA5FD /* AlertsSeismicNotificationCompactTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC646F31252B698B000AA5FD /* AlertsSeismicNotificationCompactTableViewCell.swift */; }; DC65B391250F243E00251693 /* SeismicSettingsNetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC65B390250F243E00251693 /* SeismicSettingsNetworksViewController.swift */; }; @@ -433,7 +428,6 @@ 65BBB22B26064BE6005D6CDF /* SegnalazioniLast24HoursCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegnalazioniLast24HoursCell.swift; sourceTree = ""; }; 65CB83422915720400EE1E35 /* EQNUserData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNUserData.swift; sourceTree = ""; }; 65D409932619BA34008CF356 /* SegnalazioniSendReportCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegnalazioniSendReportCell.swift; sourceTree = ""; }; - 65D9938D292264F800F2B0EB /* Foundation+EQNExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Foundation+EQNExtensions.swift"; sourceTree = ""; }; 65DBFB4A25E29DD60041CBA6 /* SeismicNetworksMapDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicNetworksMapDetailViewController.swift; sourceTree = ""; }; 65DBFB6F25E2BBF20041CBA6 /* GADTMediumTemplateView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GADTMediumTemplateView.xib; sourceTree = ""; }; 65DBFB7025E2BBF20041CBA6 /* GADTTemplateView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GADTTemplateView.h; sourceTree = ""; }; @@ -441,7 +435,6 @@ 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 = ""; }; 65E1226B285C92AA000E294A /* EQNRealtimeAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNRealtimeAlert.swift; sourceTree = ""; }; - 65E1B19A260F980600A0ACBA /* Dictionary+EQNExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+EQNExtensions.swift"; sourceTree = ""; }; 8C10B0BC2281FE7F00125C9F /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = ""; }; 8C10B0BE2281FE9E00125C9F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 8C10B0BF2281FEA000125C9F /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; @@ -532,7 +525,6 @@ DC08803E24F5A89000186D97 /* SettingEnableTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingEnableTableViewCell.swift; sourceTree = ""; }; DC08804024F5B41400186D97 /* SettingSliderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingSliderTableViewCell.swift; sourceTree = ""; }; DC0E551224F8063300D54270 /* SettingSegmentedTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingSegmentedTableViewCell.swift; sourceTree = ""; }; - DC105640251E7ECE002579BB /* UIFont+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extensions.swift"; sourceTree = ""; }; DC27EB2E24F6EBE000ACBFE0 /* SettingsSeismicNetworksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSeismicNetworksViewController.swift; sourceTree = ""; }; DC28142F2519C24400C1AFF7 /* SeismicNetworkTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicNetworkTableViewCell.swift; sourceTree = ""; }; DC2814372519C56100C1AFF7 /* SeismicNetworksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicNetworksViewController.swift; sourceTree = ""; }; @@ -545,7 +537,6 @@ DC52B8A024FC145500ABEBA6 /* SettingsBaseViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsBaseViewController.h; sourceTree = ""; }; DC52B8A124FC145500ABEBA6 /* SettingsBaseViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsBaseViewController.m; sourceTree = ""; }; DC52B8A424FCCD6900ABEBA6 /* AppTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTheme.swift; sourceTree = ""; }; - DC553AF525692E37000B521B /* StoryboardInitializable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardInitializable.swift; sourceTree = ""; }; DC646F26252B694A000AA5FD /* AlertsSeismicNotificationExpandedTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertsSeismicNotificationExpandedTableViewCell.swift; sourceTree = ""; }; DC646F31252B698B000AA5FD /* AlertsSeismicNotificationCompactTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertsSeismicNotificationCompactTableViewCell.swift; sourceTree = ""; }; DC65B390250F243E00251693 /* SeismicSettingsNetworksViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicSettingsNetworksViewController.swift; sourceTree = ""; }; @@ -775,11 +766,8 @@ DC10563F251E7EC0002579BB /* Extensions */ = { isa = PBXGroup; children = ( - DC105640251E7ECE002579BB /* UIFont+Extensions.swift */, 8C7A3B65225A5EA40045B266 /* NSDictionary+EQNExtensions.h */, 8C7A3B64225A5EA30045B266 /* NSDictionary+EQNExtensions.m */, - 65E1B19A260F980600A0ACBA /* Dictionary+EQNExtensions.swift */, - 65D9938D292264F800F2B0EB /* Foundation+EQNExtensions.swift */, 65583A04261B83BE00ECA9F9 /* UIKit+Extensions.swift */, 650B23AA2632CCD3007AE752 /* UIView+EQNExtensions.swift */, ); @@ -972,7 +960,6 @@ DC3ADD2F24CB1EFB00737919 /* Libs */ = { isa = PBXGroup; children = ( - DC553AF525692E37000B521B /* StoryboardInitializable.swift */, DC10563F251E7EC0002579BB /* Extensions */, 8CF66054214C566A009F4314 /* Reachability.h */, 8CF66056214C566A009F4314 /* Reachability.m */, @@ -1637,7 +1624,6 @@ 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 */, @@ -1658,7 +1644,6 @@ 8C4E34422152B5E8008B0D2A /* EQNRilevamento.m in Sources */, 8C7A3B66225A5EA40045B266 /* NSDictionary+EQNExtensions.m in Sources */, 8CF66053214C12DC009F4314 /* EQNMath.m in Sources */, - 65D9938E292264F800F2B0EB /* Foundation+EQNExtensions.swift in Sources */, DCF4A54524F8DB8300B17326 /* SettingDateTableViewCell.swift in Sources */, DC7EEE4A252A11C9004B4A2A /* AlertsSmartphoneNetworkTableViewCell.swift in Sources */, DC7EEE4F252A1634004B4A2A /* AlertsPriorityServiceTableViewCell.swift in Sources */, @@ -1672,7 +1657,6 @@ 65D409942619BA34008CF356 /* SegnalazioniSendReportCell.swift in Sources */, 8CBD3DC72149B9AD0070C963 /* AppDelegate.m in Sources */, DC974AFF251748B300A139EC /* SeismicFiltersViewController.swift in Sources */, - DC105641251E7ECE002579BB /* UIFont+Extensions.swift in Sources */, DCB28CEE24FB8400001F557E /* SettingsViewController.swift in Sources */, DCB528212560161C005288E5 /* AlertSimulatorViewController.swift in Sources */, DCC76BD8251F56050005C4DC /* SeismicCardSettingsViewController.swift in Sources */, @@ -1681,7 +1665,6 @@ DC3CE50A250EB7A8005A7DD5 /* EQNGenericPickerViewController.swift in Sources */, DCEFF21A24F587E3009D3FE1 /* SettingItem.swift in Sources */, 8C8EBBA721540039002784BA /* EQNUser.m in Sources */, - DC553AF625692E37000B521B /* StoryboardInitializable.swift in Sources */, 8CADAA9421B2627D0044E256 /* EQNLogViewController.m in Sources */, DC3BA11124D1A9C90062EE7F /* SubscriptionsViewController.swift in Sources */, DC646F27252B694A000AA5FD /* AlertsSeismicNotificationExpandedTableViewCell.swift in Sources */, @@ -1699,7 +1682,6 @@ 654D18D625F9420500BB6DB0 /* EQNMapAnnotationPastquake.swift in Sources */, DC0AE1B52538202300111307 /* EQNUtility.m in Sources */, 653C67E625F3CC8400FE52AC /* EQNCustomAnnotationView.swift in Sources */, - 65D9938F2922652100F2B0EB /* Foundation+EQNExtensions.swift in Sources */, 654D18DA25F9424700BB6DB0 /* EQNUtility+Extensions.swift in Sources */, DC0AE1BA2538204100111307 /* EQNPastquakes.m in Sources */, 65D9938A29219DEC00F2B0EB /* UIKit+Extensions.swift in Sources */, diff --git a/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift b/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift index 114ea3b..df0867c 100644 --- a/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift +++ b/Sources/Earthquake Network/Controllers/Alerts/Cells/AlertsSeismicNotificationExpandedTableViewCell.swift @@ -8,6 +8,7 @@ import UIKit import MapKit +import Shogun class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMapViewDelegate { @@ -73,7 +74,7 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa let aps = notification["aps"] as? [String: Any], let alert = aps["alert"] as? [String: Any] else { return } - let intensity = notification.eqn_intValue(for: "intensity") ?? 0 + let intensity = notification.integer(forKey: "intensity", orDefault: 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 { @@ -82,8 +83,8 @@ class AlertsSeismicNotificationExpandedTableViewCell: EQNBaseTableViewCell, MKMa // get coordinate var coordinate: CLLocation? - if let latitude = notification.eqn_doubleValue(for: "latitude"), - let longitude = notification.eqn_doubleValue(for: "longitude") { + if let latitude = notification.double(forKey: "latitude"), + let longitude = notification.double(forKey: "longitude") { coordinate = CLLocation(latitude: latitude, longitude: longitude) } diff --git a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift index 404898c..bc0bbdb 100644 --- a/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift +++ b/Sources/Earthquake Network/Controllers/InApp/SubscriptionsViewController.swift @@ -8,6 +8,7 @@ import UIKit import StoreKit +import Shogun class SubscriptionsViewController: UITableViewController { diff --git a/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift b/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift index 9f80fab..6d5198b 100644 --- a/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift +++ b/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift @@ -8,6 +8,7 @@ import Foundation import MapKit +import Shogun class SegnalazioniMapViewController: EQNBaseMapViewController { @@ -48,7 +49,7 @@ class SegnalazioniMapViewController: EQNBaseMapViewController { title.translatesAutoresizingMaskIntoConstraints = false title.text = NSLocalizedString("app_name", comment: "") + " App" title.textColor = AppTheme.Colors.red - title.font = .preferredFont(for: .title3, weight: .semibold) + title.font = .preferredFont(forTextStyle: .title3, weight: .semibold) view.addSubview(title) title.leadingAnchor.constraint(equalTo: logo.trailingAnchor, constant: 10.0).isActive = true title.centerYAnchor.constraint(equalTo: logo.centerYAnchor).isActive = true @@ -68,7 +69,7 @@ class SegnalazioniMapViewController: EQNBaseMapViewController { [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120].forEach { magnitude in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.text = (magnitude / 10).toRoman() + label.text = (magnitude / 10).romanNumber() label.backgroundColor = UIColor(named: "Mercalli \(magnitude)") label.textAlignment = .center label.font = .preferredFont(forTextStyle: .callout) diff --git a/Sources/Earthquake Network/Controllers/Seismic Networks/Cells/SeismicNetworkTableViewCell.swift b/Sources/Earthquake Network/Controllers/Seismic Networks/Cells/SeismicNetworkTableViewCell.swift index 62a42e4..d80f5c1 100644 --- a/Sources/Earthquake Network/Controllers/Seismic Networks/Cells/SeismicNetworkTableViewCell.swift +++ b/Sources/Earthquake Network/Controllers/Seismic Networks/Cells/SeismicNetworkTableViewCell.swift @@ -9,6 +9,7 @@ import UIKit import MapKit import CoreLocation +import Shogun protocol SeismicNetworkTableViewCellDelegate: AnyObject { func seismicNetworkCellDidTapShare(_ cell: SeismicNetworkTableViewCell) @@ -55,7 +56,7 @@ class SeismicNetworkTableViewCell: UITableViewCell { private static let DefaultVerticalSpacing: CGFloat = 6.0 private static let DefaultBodyFont = UIFont.preferredFont(forTextStyle: .body) - private static let DefaultBodyFontLight = UIFont.preferredFont(for: .body, weight: .light) + private static let DefaultBodyFontLight = UIFont.preferredFont(forTextStyle: .body, weight: .light) /// Seismic to show private var seismic: EQNSisma? @@ -89,7 +90,7 @@ class SeismicNetworkTableViewCell: UITableViewCell { private lazy var placeLabel: UILabel = { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.font = UIFont.preferredFont(for: .title2, weight: .semibold) + label.font = UIFont.preferredFont(forTextStyle: .title2, weight: .semibold) label.numberOfLines = 3 return label }() diff --git a/Sources/Earthquake Network/Controllers/Seismic Networks/Filters/SeismicFiltersViewController.swift b/Sources/Earthquake Network/Controllers/Seismic Networks/Filters/SeismicFiltersViewController.swift index b5af8ed..b8e600e 100644 --- a/Sources/Earthquake Network/Controllers/Seismic Networks/Filters/SeismicFiltersViewController.swift +++ b/Sources/Earthquake Network/Controllers/Seismic Networks/Filters/SeismicFiltersViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Shogun protocol SeismicFiltersViewControllerDelegate: AnyObject { func seismicFiltersControllerDidUpdateFilters(_ controller: SeismicFiltersViewController) diff --git a/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksMapDetailViewController.swift b/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksMapDetailViewController.swift index 1dd67ed..d3c4af3 100644 --- a/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksMapDetailViewController.swift +++ b/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksMapDetailViewController.swift @@ -8,6 +8,7 @@ import UIKit import MapKit +import Shogun protocol SeismicNetworksMapDetailViewControllerDelegate: AnyObject { func seismicNetworksMapDetailControllerWillUpdateData(_ controller: SeismicNetworksMapDetailViewController, needsDataUpdate: Bool) @@ -164,7 +165,7 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController { // MARK: - Actions @objc override func filtersTapped(_ sender: UIGestureRecognizer) { - let controller = SeismicFiltersViewController.makeController() + let controller = SeismicFiltersViewController.makeViewController() controller.delegate = self controller.modalPresentationStyle = .overCurrentContext controller.modalTransitionStyle = .crossDissolve diff --git a/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksViewController.swift b/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksViewController.swift index 5b40ce0..283ed2f 100644 --- a/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksViewController.swift +++ b/Sources/Earthquake Network/Controllers/Seismic Networks/SeismicNetworksViewController.swift @@ -9,6 +9,7 @@ import UIKit import EventKitUI import DZNEmptyDataSet +import Shogun class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { diff --git a/Sources/Earthquake Network/Controllers/Simulator/AlertSimulatorViewController.swift b/Sources/Earthquake Network/Controllers/Simulator/AlertSimulatorViewController.swift index f794147..c9aafc0 100644 --- a/Sources/Earthquake Network/Controllers/Simulator/AlertSimulatorViewController.swift +++ b/Sources/Earthquake Network/Controllers/Simulator/AlertSimulatorViewController.swift @@ -8,6 +8,7 @@ import UIKit import MapKit +import Shogun class AlertSimulatorViewController: UIViewController, MKMapViewDelegate { @@ -243,7 +244,7 @@ class AlertSimulatorViewController: UIViewController, MKMapViewDelegate { } private func navigateToSubscriptions() { - let controller = SubscriptionsViewController.makeController() + let controller = SubscriptionsViewController.makeViewController() let navigationController = UINavigationController(rootViewController: controller) present(navigationController, animated: true) } diff --git a/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift b/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift deleted file mode 100644 index 73168e6..0000000 --- a/Sources/Earthquake Network/Libs/Extensions/Dictionary+EQNExtensions.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// 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 - } -} diff --git a/Sources/Earthquake Network/Libs/Extensions/Foundation+EQNExtensions.swift b/Sources/Earthquake Network/Libs/Extensions/Foundation+EQNExtensions.swift deleted file mode 100644 index b536783..0000000 --- a/Sources/Earthquake Network/Libs/Extensions/Foundation+EQNExtensions.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// Foundation+EQNExtensions.swift -// Earthquake Network -// -// Created by Andrea Busi on 14/11/22. -// Copyright © 2022 Earthquake Network. All rights reserved. -// - -import Foundation - - -extension Int { - func toRoman() -> String { - let conversionTable: [(intNumber: Int, romanNumber: String)] = - [(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), - (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), - (9, "IX"), (5, "V"), (4, "IV"), (1, "I")] - var roman = "" - var remainder = 0 - - for entry in conversionTable { - let quotient = (self - remainder) / entry.intNumber - remainder += quotient * entry.intNumber - roman += String(repeating: entry.romanNumber, count: quotient) - } - - return roman - } -} diff --git a/Sources/Earthquake Network/Libs/Extensions/UIFont+Extensions.swift b/Sources/Earthquake Network/Libs/Extensions/UIFont+Extensions.swift deleted file mode 100644 index d4e37db..0000000 --- a/Sources/Earthquake Network/Libs/Extensions/UIFont+Extensions.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// UIFont+Extensions.swift -// Earthquake Network -// -// Created by Busi Andrea on 25/09/2020. -// Copyright © 2020 Earthquake Network. All rights reserved. -// - -import Foundation - - -extension UIFont { - static func preferredFont(for style: TextStyle, weight: Weight) -> UIFont { - let metrics = UIFontMetrics(forTextStyle: style) - let desc = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style) - let font = UIFont.systemFont(ofSize: desc.pointSize, weight: weight) - return metrics.scaledFont(for: font) - } -} diff --git a/Sources/Earthquake Network/Libs/Extensions/UIKit+Extensions.swift b/Sources/Earthquake Network/Libs/Extensions/UIKit+Extensions.swift index e44d553..5df3c15 100644 --- a/Sources/Earthquake Network/Libs/Extensions/UIKit+Extensions.swift +++ b/Sources/Earthquake Network/Libs/Extensions/UIKit+Extensions.swift @@ -48,16 +48,3 @@ extension UIImage { return img } } - - -extension UIView { - /// Creates a snapshot of the current view - /// - Returns: Image with the snapshot of the view - public func createSnapshot() -> UIImage { - let renderer = UIGraphicsImageRenderer(size: bounds.size) - let image = renderer.image { ctx in - drawHierarchy(in: bounds, afterScreenUpdates: true) - } - return image - } -} diff --git a/Sources/Earthquake Network/Libs/StoryboardInitializable.swift b/Sources/Earthquake Network/Libs/StoryboardInitializable.swift deleted file mode 100644 index 3903b74..0000000 --- a/Sources/Earthquake Network/Libs/StoryboardInitializable.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// StoryboardInitializable.swift -// -// Created by Busi Andrea on 10/11/2020. -// - -import Foundation - - -protocol StoryboardInitializable where Self: UIViewController { - static var storyboardName: String { get } - static var storyboardControllerId: String { get } - - static func makeController() -> Self -} - -extension StoryboardInitializable { - static func makeController() -> Self { - let storyboard = UIStoryboard(name: storyboardName, bundle: Bundle(for: Self.self)) - guard let controller = storyboard.instantiateViewController(withIdentifier: storyboardControllerId) as? Self else { - fatalError("Unable to instantiate controller with anem \(storyboardControllerId)") - } - return controller - } -} diff --git a/Sources/Earthquake Network/Models/EQNRealtimeAlert.swift b/Sources/Earthquake Network/Models/EQNRealtimeAlert.swift index 696e9da..91384db 100644 --- a/Sources/Earthquake Network/Models/EQNRealtimeAlert.swift +++ b/Sources/Earthquake Network/Models/EQNRealtimeAlert.swift @@ -8,6 +8,7 @@ import Foundation import CoreLocation +import Shogun @objc @@ -41,8 +42,8 @@ class EQNRealtimeAlert: NSObject { if let title = alert["loc-key"] as? String, let args = alert["loc-args"] as? [String], let arg = args.first { self.title = String(format: NSLocalizedString(title, comment: ""), arg) } - self.intensity = notification.eqn_intValue(for: "intensity") ?? 0 - self.waveSpeed = (notification.eqn_doubleValue(for: "wave_speed") ?? 0) * 1000 // m/s + self.intensity = notification.integer(forKey: "intensity", orDefault: 0) + self.waveSpeed = notification.double(forKey: "wave_speed", orDefault: 0.0) * 1000 // m/s } func distanceFromUser() -> CLLocationDistance { @@ -82,8 +83,8 @@ class EQNRealtimeAlert: NSObject { static func getCoordinate( from notification: NotificationPayload ) -> CLLocation? { - guard let latitude = notification.eqn_doubleValue(for: "latitude"), - let longitude = notification.eqn_doubleValue(for: "longitude") else { + guard let latitude = notification.double(forKey: "latitude"), + let longitude = notification.double(forKey: "longitude") else { return nil } return CLLocation(latitude: latitude, longitude: longitude) diff --git a/Sources/Earthquake Network/Models/EQNReteSmartphone.swift b/Sources/Earthquake Network/Models/EQNReteSmartphone.swift index d9ed23c..5799e46 100644 --- a/Sources/Earthquake Network/Models/EQNReteSmartphone.swift +++ b/Sources/Earthquake Network/Models/EQNReteSmartphone.swift @@ -7,6 +7,7 @@ // import Foundation +import Shogun @objc @@ -26,12 +27,12 @@ class EQNReteSmartphone: NSObject { return result.merging(dictionary, uniquingKeysWith: { (_, new) in new }) } - self.counterLastDayAlerts = allValues.eqn_intValue(for: "eq") ?? 0 - self.counterTotalAlerts = allValues.eqn_intValue(for: "eq_p") ?? 0 - self.counterSmartphones = allValues.eqn_intValue(for: "green") ?? 0 - self.manual = allValues.eqn_intValue(for: "man") ?? 0 - self.lastSubscriptionDiff = allValues.eqn_intValue(for: "diff") ?? 0 - let subscriptionsDiscounted = allValues.eqn_intValue(for: "st") ?? 0 + self.counterLastDayAlerts = allValues.integer(forKey: "eq", orDefault: 0) + self.counterTotalAlerts = allValues.integer(forKey: "eq_p", orDefault: 0) + self.counterSmartphones = allValues.integer(forKey: "green", orDefault: 0) + self.manual = allValues.integer(forKey: "man", orDefault: 0) + self.lastSubscriptionDiff = allValues.integer(forKey: "diff", orDefault: 0) + let subscriptionsDiscounted = allValues.integer(forKey: "st", orDefault: 0) self.subscriptionsDiscounted = subscriptionsDiscounted == 1 super.init() diff --git a/Sources/Earthquake Network/Models/Map annotation/EQNMapAnnotationUserReport.swift b/Sources/Earthquake Network/Models/Map annotation/EQNMapAnnotationUserReport.swift index d2fc78f..54fb6db 100644 --- a/Sources/Earthquake Network/Models/Map annotation/EQNMapAnnotationUserReport.swift +++ b/Sources/Earthquake Network/Models/Map annotation/EQNMapAnnotationUserReport.swift @@ -8,6 +8,7 @@ import Foundation import MapKit +import Shogun @objc @@ -55,13 +56,13 @@ class EQNMapAnnotationUserReport: NSObject, MKAnnotation { private static func title(for magnitude: Int) -> String { let grade = magnitude / 10 - let roman = grade.toRoman() + let roman = grade.romanNumber() return String(format: NSLocalizedString("mercalli_intensity", comment: ""), roman) } private static func subtitle(for magnitude: Int) -> String { let grade = magnitude / 10 - let roman = grade.toRoman() + let roman = grade.romanNumber() let string = NSLocalizedString("mercalli_\(roman)", comment: "") // strings are in the format like "II - Appena percepito" // so we are going to remove the "II" from the string