From 72441d05323d88f18365b9d1d0e2bd9c91ccbfda Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Mon, 10 Jun 2024 10:58:01 +0200 Subject: [PATCH] refactor: Create Swift version of SettingsBaseViewController --- .../project.pbxproj | 4 ++ .../SettingsBaseTableViewController.swift | 43 +++++++++++++++++++ .../Settings/SettingsBaseViewController.h | 1 + ...gsSeismicNetworkAlertsViewController.swift | 2 +- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Sources/Earthquake Network/Controllers/Settings/SettingsBaseTableViewController.swift diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index abf0438..6654b6c 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -59,6 +59,7 @@ 65D507DC2A85227F005BDC57 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6502470C2A612E4A001AC512 /* Constants.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 */; }; + 65DB60F02C16F5B100164366 /* SettingsBaseTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DB60EF2C16F5B100164366 /* SettingsBaseTableViewController.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 */; }; @@ -357,6 +358,7 @@ 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 = ""; }; + 65DB60EF2C16F5B100164366 /* SettingsBaseTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsBaseTableViewController.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 = ""; }; @@ -1173,6 +1175,7 @@ DCB28CED24FB8400001F557E /* SettingsViewController.swift */, DC52B8A024FC145500ABEBA6 /* SettingsBaseViewController.h */, DC52B8A124FC145500ABEBA6 /* SettingsBaseViewController.m */, + 65DB60EF2C16F5B100164366 /* SettingsBaseTableViewController.swift */, 8CCE165321EA378800173CD9 /* SettingsUserReportAlertsViewController.h */, 8CCE165421EA378800173CD9 /* SettingsUserReportAlertsViewController.m */, 65AB4A942C11BED400950DF7 /* SettingsSeismicNetworkAlertsViewController.swift */, @@ -1600,6 +1603,7 @@ 6552C1462926DBA1008E723C /* AppPreferences.swift in Sources */, DC08803F24F5A89000186D97 /* SettingEnableTableViewCell.swift in Sources */, 652A3C6B2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift in Sources */, + 65DB60F02C16F5B100164366 /* SettingsBaseTableViewController.swift in Sources */, 65AB4A952C11BED400950DF7 /* SettingsSeismicNetworkAlertsViewController.swift in Sources */, 6586971125F44C26009C0182 /* EQNBlurredCloseButton.swift in Sources */, 8CAFD7C521825E4A00F8BD29 /* EQNSisma.m in Sources */, diff --git a/Sources/Earthquake Network/Controllers/Settings/SettingsBaseTableViewController.swift b/Sources/Earthquake Network/Controllers/Settings/SettingsBaseTableViewController.swift new file mode 100644 index 0000000..7dddd47 --- /dev/null +++ b/Sources/Earthquake Network/Controllers/Settings/SettingsBaseTableViewController.swift @@ -0,0 +1,43 @@ +// +// SettingsBaseTableViewController.swift +// Earthquake Network +// +// Created by Andrea Busi on 10/06/24. +// Copyright © 2024 Earthquake Network. All rights reserved. +// + +import UIKit + +@objc +class SettingsBaseTableViewController: UITableViewController { + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + + if isMovingFromParent { + Self.saveSettings() + } + } + + // MARK: - Class + + @objc class func saveSettings() { + saveSettings { _ in + // nope + } + } + + @objc class func saveSettings( + completion: @escaping (_ success: Bool) -> Void + ) { + + let url = EQNGeneratoreURLServer.urlInvioImpostazioniNotifiche() + ServerRequest.default().inviaInformazioniAlServer(with: url, richiesta: .impostazioniNotifiche) { _ in + print("[SETTINGS] Settings saved successfully") + completion(true) + } failure: { error in + print("[SETTINGS] Settings saved failed. Error: \(error?.localizedDescription ?? "n.d.")") + completion(false) + } + } +} diff --git a/Sources/Earthquake Network/Controllers/Settings/SettingsBaseViewController.h b/Sources/Earthquake Network/Controllers/Settings/SettingsBaseViewController.h index f49f223..81cca98 100644 --- a/Sources/Earthquake Network/Controllers/Settings/SettingsBaseViewController.h +++ b/Sources/Earthquake Network/Controllers/Settings/SettingsBaseViewController.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +// TODO: da migrare a SettingsBaseTableViewController @interface SettingsBaseViewController : UITableViewController + (void)saveSettings; diff --git a/Sources/Earthquake Network/Controllers/Settings/SettingsSeismicNetworkAlertsViewController.swift b/Sources/Earthquake Network/Controllers/Settings/SettingsSeismicNetworkAlertsViewController.swift index 0fa8c36..f9136e8 100644 --- a/Sources/Earthquake Network/Controllers/Settings/SettingsSeismicNetworkAlertsViewController.swift +++ b/Sources/Earthquake Network/Controllers/Settings/SettingsSeismicNetworkAlertsViewController.swift @@ -9,7 +9,7 @@ import UIKit import Shogun -class SettingsSeismicNetworkAlertsViewController: SettingsBaseViewController { +class SettingsSeismicNetworkAlertsViewController: SettingsBaseTableViewController { private enum RowIdentifier: Int { case abilitaNotifiche