From ea275e46b9fdda152f69c35a2b4a7e67331b85ff Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Sat, 26 Sep 2020 14:25:10 +0200 Subject: [PATCH] feat: Add command to set default settings --- .../project.pbxproj | 4 +++ .../Commands/EQNAppearanceCommand.swift | 1 - .../Commands/EQNStartupCommandsBuilder.swift | 3 +- .../Commands/EQNUserDefaultsCommand.swift | 32 +++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Sources/Earthquake Network/Models/Commands/EQNUserDefaultsCommand.swift diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index a3c69b1..752403e 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -115,6 +115,7 @@ DCC23DEC24D281CE003A2404 /* SubscriptionsActiveTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC23DEB24D281CE003A2404 /* SubscriptionsActiveTableViewCell.swift */; }; DCC23DEF24D28F58003A2404 /* EQNEdgeInsetLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC23DEE24D28F58003A2404 /* EQNEdgeInsetLabel.swift */; }; DCC76BD8251F56050005C4DC /* SeismicCardSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC76BD7251F56050005C4DC /* SeismicCardSettingsViewController.swift */; }; + DCC76BE4251F69FB0005C4DC /* EQNUserDefaultsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC76BE3251F69FB0005C4DC /* EQNUserDefaultsCommand.swift */; }; DCD3E3C024D15576007C78D4 /* PurchaseProVersionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCD3E3BF24D15576007C78D4 /* PurchaseProVersionViewController.swift */; }; DCD4571C24F6CF0D00B58304 /* EQNGenericValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCD4571B24F6CF0D00B58304 /* EQNGenericValue.swift */; }; DCDAB31925188BB3001AE40D /* EQNAllertaSismica.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C14113621EE502800A59729 /* EQNAllertaSismica.m */; }; @@ -317,6 +318,7 @@ DCC23DEB24D281CE003A2404 /* SubscriptionsActiveTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionsActiveTableViewCell.swift; sourceTree = ""; }; DCC23DEE24D28F58003A2404 /* EQNEdgeInsetLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNEdgeInsetLabel.swift; sourceTree = ""; }; DCC76BD7251F56050005C4DC /* SeismicCardSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicCardSettingsViewController.swift; sourceTree = ""; }; + DCC76BE3251F69FB0005C4DC /* EQNUserDefaultsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNUserDefaultsCommand.swift; sourceTree = ""; }; DCD3E3BF24D15576007C78D4 /* PurchaseProVersionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchaseProVersionViewController.swift; sourceTree = ""; }; DCD4571B24F6CF0D00B58304 /* EQNGenericValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNGenericValue.swift; sourceTree = ""; }; DCDE0BD724E58CCE00209778 /* EQNMainTabBarController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EQNMainTabBarController.h; sourceTree = ""; }; @@ -655,6 +657,7 @@ DC99A50224E66E270071BC9F /* EQNCommandProtocol.swift */, DC99A50624E66E5F0071BC9F /* EQNStartupCommandsBuilder.swift */, DC99A50424E66E430071BC9F /* EQNAppearanceCommand.swift */, + DCC76BE3251F69FB0005C4DC /* EQNUserDefaultsCommand.swift */, ); path = Commands; sourceTree = ""; @@ -1050,6 +1053,7 @@ 8CCE165821EB1E0000173CD9 /* SettingsSeismicNetworkAlertsViewController.m in Sources */, 8CCE165521EA378800173CD9 /* SettingsUserReportAlertsViewController.m in Sources */, DCBB268024D1ECE200F04559 /* SubscriptionDetailViewController.swift in Sources */, + DCC76BE4251F69FB0005C4DC /* EQNUserDefaultsCommand.swift in Sources */, DC4B67612517833F00634277 /* EQNSeismic.swift in Sources */, DCBB267E24D1EA2000F04559 /* SubscriptionProductTableViewCell.swift in Sources */, DC99A50524E66E430071BC9F /* EQNAppearanceCommand.swift in Sources */, diff --git a/Sources/Earthquake Network/Models/Commands/EQNAppearanceCommand.swift b/Sources/Earthquake Network/Models/Commands/EQNAppearanceCommand.swift index bc5ab8c..d0fd297 100644 --- a/Sources/Earthquake Network/Models/Commands/EQNAppearanceCommand.swift +++ b/Sources/Earthquake Network/Models/Commands/EQNAppearanceCommand.swift @@ -11,7 +11,6 @@ import Foundation public class EQNAppearanceCommand: EQNCommandProtocol { - // MARK: - Public func execute() { diff --git a/Sources/Earthquake Network/Models/Commands/EQNStartupCommandsBuilder.swift b/Sources/Earthquake Network/Models/Commands/EQNStartupCommandsBuilder.swift index 75f29b2..5d2a7bd 100644 --- a/Sources/Earthquake Network/Models/Commands/EQNStartupCommandsBuilder.swift +++ b/Sources/Earthquake Network/Models/Commands/EQNStartupCommandsBuilder.swift @@ -16,7 +16,8 @@ public class EQNStartupCommandsBuilder: NSObject { @objc func build() -> [EQNCommandProtocol] { return [ - EQNAppearanceCommand() + EQNAppearanceCommand(), + EQNUserDefaultsCommand() ] } diff --git a/Sources/Earthquake Network/Models/Commands/EQNUserDefaultsCommand.swift b/Sources/Earthquake Network/Models/Commands/EQNUserDefaultsCommand.swift new file mode 100644 index 0000000..a627028 --- /dev/null +++ b/Sources/Earthquake Network/Models/Commands/EQNUserDefaultsCommand.swift @@ -0,0 +1,32 @@ +// +// EQNUserDefaultsCommand.swift +// Earthquake Network +// +// Created by Busi Andrea on 26/09/2020. +// Copyright © 2020 Earthquake Network. All rights reserved. +// + +import Foundation + + +public class EQNUserDefaultsCommand: EQNCommandProtocol { + + // MARK: - Public + + func execute() { + print("EQNUserDefaultsCommand: start execute") + + applyDefaultSettings() + } + + // MARK: - Private + + private func applyDefaultSettings() { + + // seismic card settings + if UserDefaults.standard.array(forKey: EQNUserDefaultKeySesmicInformations) == nil { + let informations: [SeismicNetworkTableViewCell.InformationType] = [.distance, .coordinate, .population] + UserDefaults.standard.set(informations.map { $0.rawValue }, forKey: EQNUserDefaultKeySesmicInformations) + } + } +}