refactor: Move card informations to AppPreferences
This commit is contained in:
@@ -58,6 +58,8 @@ extension UserDefaults {
|
|||||||
static let AlertsShowCardOptions = "EQNetwork.AlertsShowAllCards"
|
static let AlertsShowCardOptions = "EQNetwork.AlertsShowAllCards"
|
||||||
/// Indica lo stile di pin da visualizzare nelle mappe
|
/// Indica lo stile di pin da visualizzare nelle mappe
|
||||||
static let MapPinStyle = "EQNetwork.MapPinStyle"
|
static let MapPinStyle = "EQNetwork.MapPinStyle"
|
||||||
|
/// Indica le informazioni da visualizzare nelle card `small` e `full` nella Lista Sismi
|
||||||
|
static let SeismicNetworksCardInformations = "EQNetwork.SeismicInformations";
|
||||||
|
|
||||||
// Migrazioni
|
// Migrazioni
|
||||||
static let AppMigrationV5_3 = "EQNUserDefaultMigrationV5_3"
|
static let AppMigrationV5_3 = "EQNUserDefaultMigrationV5_3"
|
||||||
|
|||||||
+4
-6
@@ -29,17 +29,16 @@ class SeismicCardSettingsViewController: UIViewController {
|
|||||||
@IBOutlet private weak var informationPopulationSwitch: UISwitch!
|
@IBOutlet private weak var informationPopulationSwitch: UISwitch!
|
||||||
@IBOutlet private weak var closeButton: UIButton!
|
@IBOutlet private weak var closeButton: UIButton!
|
||||||
|
|
||||||
private var informations = [SeismicNetworkTableViewCell.InformationType]()
|
private var informations: [SeismicNetworkTableViewCell.InformationType] {
|
||||||
|
get { AppPreferences.shared.seismicNetworksInformations }
|
||||||
|
set { AppPreferences.shared.seismicNetworksInformations = newValue }
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - View Lifecycle
|
// MARK: - View Lifecycle
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
if let saved = UserDefaults.standard.array(forKey: EQNUserDefaultKeySesmicInformations) as? [Int] {
|
|
||||||
informations = saved.compactMap { SeismicNetworkTableViewCell.InformationType(rawValue: $0) }
|
|
||||||
}
|
|
||||||
|
|
||||||
setupUI()
|
setupUI()
|
||||||
updateUI()
|
updateUI()
|
||||||
}
|
}
|
||||||
@@ -84,7 +83,6 @@ class SeismicCardSettingsViewController: UIViewController {
|
|||||||
toggle(information: .population)
|
toggle(information: .population)
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDefaults.standard.set(informations.map { $0.rawValue }, forKey: EQNUserDefaultKeySesmicInformations)
|
|
||||||
updateUI()
|
updateUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-6
@@ -36,7 +36,10 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
|||||||
private var rows = [CellType]()
|
private var rows = [CellType]()
|
||||||
private var seismicViewModels = [SeismicNetworkViewModel]()
|
private var seismicViewModels = [SeismicNetworkViewModel]()
|
||||||
/// Informations to display on a single cell
|
/// Informations to display on a single cell
|
||||||
private var informations = [SeismicNetworkTableViewCell.InformationType]()
|
private var informations: [SeismicNetworkTableViewCell.InformationType] {
|
||||||
|
get { AppPreferences.shared.seismicNetworksInformations }
|
||||||
|
set { AppPreferences.shared.seismicNetworksInformations = newValue }
|
||||||
|
}
|
||||||
/// Index path of row with map expanded
|
/// Index path of row with map expanded
|
||||||
private var openMapIndexPath: IndexPath?
|
private var openMapIndexPath: IndexPath?
|
||||||
/// Push notification opened by the user
|
/// Push notification opened by the user
|
||||||
@@ -260,10 +263,6 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
|||||||
private func refreshUI() {
|
private func refreshUI() {
|
||||||
elaborateData()
|
elaborateData()
|
||||||
|
|
||||||
if let saved = UserDefaults.standard.array(forKey: EQNUserDefaultKeySesmicInformations) as? [Int] {
|
|
||||||
informations = saved.compactMap { SeismicNetworkTableViewCell.InformationType(rawValue: $0) }
|
|
||||||
}
|
|
||||||
|
|
||||||
if informations.contains(.buttons) {
|
if informations.contains(.buttons) {
|
||||||
expandeCollapseButton.image = UIImage(named: "navbar-icon-arrow-collapse")
|
expandeCollapseButton.image = UIImage(named: "navbar-icon-arrow-collapse")
|
||||||
} else {
|
} else {
|
||||||
@@ -638,7 +637,6 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
|||||||
informations.append(.buttons)
|
informations.append(.buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDefaults.standard.set(informations.map { $0.rawValue }, forKey: EQNUserDefaultKeySesmicInformations)
|
|
||||||
refreshUI()
|
refreshUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ static NSString * const EQNServerUrlAlertSimulator = @"https://srv.earthquakenet
|
|||||||
|
|
||||||
#pragma mark - UserDefaults Keys
|
#pragma mark - UserDefaults Keys
|
||||||
|
|
||||||
static NSString * const EQNUserDefaultKeySesmicInformations = @"EQNetwork.SeismicInformations";
|
|
||||||
static NSString * const EQNUserDefaultSeismicNetworkCards = @"EQNData.RetiSismiche";
|
static NSString * const EQNUserDefaultSeismicNetworkCards = @"EQNData.RetiSismiche";
|
||||||
|
|
||||||
#pragma mark - NSNotification
|
#pragma mark - NSNotification
|
||||||
|
|||||||
@@ -39,4 +39,17 @@ class AppPreferences: NSObject {
|
|||||||
UserDefaults.standard.set(newValue.rawValue, forKey: UserDefaults.MapPinStyle)
|
UserDefaults.standard.set(newValue.rawValue, forKey: UserDefaults.MapPinStyle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var seismicNetworksInformations: [SeismicNetworkTableViewCell.InformationType] {
|
||||||
|
get {
|
||||||
|
if let saved = UserDefaults.standard.array(forKey: UserDefaults.SeismicNetworksCardInformations) as? [Int] {
|
||||||
|
let informations = saved.compactMap { SeismicNetworkTableViewCell.InformationType(rawValue: $0) }
|
||||||
|
return informations
|
||||||
|
}
|
||||||
|
return [.buttons, .distance, .coordinate, .population, .intensityMap]
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
UserDefaults.standard.set(newValue.map { $0.rawValue }, forKey: UserDefaults.SeismicNetworksCardInformations)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ public class EQNUserDefaultsCommand: EQNCommandProtocol {
|
|||||||
func execute() {
|
func execute() {
|
||||||
print("[EQNUserDefaultsCommand] Start execute")
|
print("[EQNUserDefaultsCommand] Start execute")
|
||||||
|
|
||||||
applyDefaultSettings()
|
|
||||||
|
|
||||||
migrationV5_8()
|
migrationV5_8()
|
||||||
migrationFirstAppStat()
|
migrationFirstAppStat()
|
||||||
migrationCriticalAlerts()
|
migrationCriticalAlerts()
|
||||||
@@ -27,15 +25,6 @@ public class EQNUserDefaultsCommand: EQNCommandProtocol {
|
|||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func applyDefaultSettings() {
|
|
||||||
|
|
||||||
// seismic card settings
|
|
||||||
if UserDefaults.standard.array(forKey: EQNUserDefaultKeySesmicInformations) == nil {
|
|
||||||
let informations: [SeismicNetworkTableViewCell.InformationType] = [.buttons, .distance, .coordinate, .population, .intensityMap]
|
|
||||||
UserDefaults.standard.set(informations.map { $0.rawValue }, forKey: EQNUserDefaultKeySesmicInformations)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func migrationV5_8() {
|
private func migrationV5_8() {
|
||||||
let migrationPerformed = UserDefaults.standard.bool(forKey: UserDefaults.AppMigrationV5_8)
|
let migrationPerformed = UserDefaults.standard.bool(forKey: UserDefaults.AppMigrationV5_8)
|
||||||
if migrationPerformed {
|
if migrationPerformed {
|
||||||
@@ -117,14 +106,13 @@ public class EQNUserDefaultsCommand: EQNCommandProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let saved = userDefaults.array(forKey: EQNUserDefaultKeySesmicInformations) as? [Int] {
|
// add new intensity map
|
||||||
var informations = saved.compactMap { SeismicNetworkTableViewCell.InformationType(rawValue: $0) }
|
var informations = AppPreferences.shared.seismicNetworksInformations
|
||||||
if !informations.contains(.intensityMap) {
|
if !informations.contains(.intensityMap) {
|
||||||
informations.append(.intensityMap)
|
informations.append(.intensityMap)
|
||||||
print("[EQNUserDefaultsCommand] Add intensityMap to seismic informations")
|
print("[EQNUserDefaultsCommand] Add intensityMap to seismic informations")
|
||||||
}
|
|
||||||
userDefaults.set(informations.map { $0.rawValue }, forKey: EQNUserDefaultKeySesmicInformations)
|
|
||||||
}
|
}
|
||||||
|
AppPreferences.shared.seismicNetworksInformations = informations
|
||||||
|
|
||||||
userDefaults.set(true, forKey: UserDefaults.AppMigrationV5_9)
|
userDefaults.set(true, forKey: UserDefaults.AppMigrationV5_9)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user