From ea6172226da752dea000819d578fbb2bbb9fc965 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Fri, 18 Aug 2023 16:10:31 +0200 Subject: [PATCH] feat: Add a debug screen for saved background positions --- .../project.pbxproj | 4 + .../Alerts/AllerteViewController.m | 7 ++ ...BackgrounPositionDebugViewController.swift | 78 +++++++++++++++++++ .../Storyboards/Base.lproj/Main.storyboard | 77 +++++++++--------- 4 files changed, 130 insertions(+), 36 deletions(-) create mode 100644 Sources/Earthquake Network/Controllers/Debug/EQNBackgrounPositionDebugViewController.swift diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index 9e561d6..2087750 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 650B23AB2632CCD3007AE752 /* UIView+EQNExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 650B23AA2632CCD3007AE752 /* UIView+EQNExtensions.swift */; }; 651901B925F5358700CAFF20 /* EQNMapAnnotationSeismic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651901B825F5358700CAFF20 /* EQNMapAnnotationSeismic.swift */; }; 6525A82625E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6525A82525E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift */; }; + 652A3C6B2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652A3C6A2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift */; }; 652C37BD26092B3C0068EC3B /* FiltersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652C37BC26092B3C0068EC3B /* FiltersViewModel.swift */; }; 65355FFF25F38D3300BB57D2 /* SegnalazioniMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65355FFE25F38D3300BB57D2 /* SegnalazioniMapViewController.swift */; }; 653604E9262348FA00B2B651 /* EQNBaseMapFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653604E8262348FA00B2B651 /* EQNBaseMapFilter.swift */; }; @@ -306,6 +307,7 @@ 650B23AA2632CCD3007AE752 /* UIView+EQNExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+EQNExtensions.swift"; sourceTree = ""; }; 651901B825F5358700CAFF20 /* EQNMapAnnotationSeismic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNMapAnnotationSeismic.swift; sourceTree = ""; }; 6525A82525E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicNetworkAdvertiseTableViewCell.swift; sourceTree = ""; }; + 652A3C6A2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNBackgrounPositionDebugViewController.swift; sourceTree = ""; }; 652C37BC26092B3C0068EC3B /* FiltersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersViewModel.swift; sourceTree = ""; }; 65355FFE25F38D3300BB57D2 /* SegnalazioniMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegnalazioniMapViewController.swift; sourceTree = ""; }; 653604E8262348FA00B2B651 /* EQNBaseMapFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNBaseMapFilter.swift; sourceTree = ""; }; @@ -646,6 +648,7 @@ 6544416A25E9599000C41714 /* EQNDebugViewController.swift */, 8CADAA9221B2627D0044E256 /* EQNLogViewController.h */, 8CADAA9321B2627D0044E256 /* EQNLogViewController.m */, + 652A3C6A2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift */, ); path = Debug; sourceTree = ""; @@ -1672,6 +1675,7 @@ DCF10DCD24D2C935009F34C3 /* EQNPurchaseAvailability.swift in Sources */, 6552C1462926DBA1008E723C /* AppPreferences.swift in Sources */, DC08803F24F5A89000186D97 /* SettingEnableTableViewCell.swift in Sources */, + 652A3C6B2A8A757800719796 /* EQNBackgrounPositionDebugViewController.swift in Sources */, 6586971125F44C26009C0182 /* EQNBlurredCloseButton.swift in Sources */, 8CAFD7C521825E4A00F8BD29 /* EQNSisma.m in Sources */, DCC23DEC24D281CE003A2404 /* SubscriptionsActiveTableViewCell.swift in Sources */, diff --git a/Sources/Earthquake Network/Controllers/Alerts/AllerteViewController.m b/Sources/Earthquake Network/Controllers/Alerts/AllerteViewController.m index d321927..f11e8e1 100644 --- a/Sources/Earthquake Network/Controllers/Alerts/AllerteViewController.m +++ b/Sources/Earthquake Network/Controllers/Alerts/AllerteViewController.m @@ -175,6 +175,13 @@ typedef NS_ENUM(NSInteger, AllerteTableRow) { [self refreshUI]; } +- (IBAction)backgroundPositionDebugTapped:(id)sender +{ + EQNBackgroundPositionDebugViewController *controller = [[EQNBackgroundPositionDebugViewController alloc] init]; + UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller]; + [self presentViewController:navController animated:YES completion:nil]; +} + - (void)actionCloseNotification { [self resetRealtimeAlert]; diff --git a/Sources/Earthquake Network/Controllers/Debug/EQNBackgrounPositionDebugViewController.swift b/Sources/Earthquake Network/Controllers/Debug/EQNBackgrounPositionDebugViewController.swift new file mode 100644 index 0000000..b9851c9 --- /dev/null +++ b/Sources/Earthquake Network/Controllers/Debug/EQNBackgrounPositionDebugViewController.swift @@ -0,0 +1,78 @@ +// +// EQNBackgrounPositionDebugViewController.swift +// Earthquake Network +// +// Created by Andrea Busi on 14/08/23. +// Copyright © 2023 Earthquake Network. All rights reserved. +// + +import UIKit +import CoreLocation + + +class EQNBackgroundPositionDebugViewController: UITableViewController { + + private var positions = [EQNBackgroundPosition]() + private let formatter: DateFormatter = { + let formatter = DateFormatter() + formatter.timeStyle = .medium + formatter.dateStyle = .medium + return formatter + }() + + + // MARK: - Init + + convenience init() { + self.init(style: .insetGrouped) + } + + // MARK: - View Lifecycle + + override func viewDidLoad() { + super.viewDidLoad() + + configureUI() + loadData() + } + + private func configureUI() { + tableView.rowHeight = UITableView.automaticDimension + tableView.estimatedRowHeight = 60.0 + + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .trash, target: self, action: #selector(onTapDeleteButton(_:))) + } + + private func loadData() { + positions = EQNBackgroundPosition.load() + tableView.reloadData() + } + + // MARK: - Table view data source + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + positions.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let position = positions[indexPath.row] + let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "PositionCell") + cell.textLabel?.text = formatter.string(from: position.date) + cell.detailTextLabel?.text = String(format: "Lat: %.4f - Lon: %.4f", position.coordinate.latitude, position.coordinate.longitude) + return cell + } + + // MARK: - Actions + + @objc private func onTapDeleteButton(_ sender: UIBarButtonItem) { + EQNBackgroundPosition.reset() + loadData() + } + + // MARK: - Class + + @objc + class func resetAll() { + EQNBackgroundPosition.reset() + } +} diff --git a/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard b/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard index 633601b..72e8dfe 100644 --- a/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard +++ b/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard @@ -1990,16 +1990,16 @@ Sisma rilevato da 10 smartphone - + - + -