From c00a29a222ea899fa08314fa884877c09c5de1ad Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Thu, 11 Mar 2021 20:21:51 +0100 Subject: [PATCH] refactor: Improve style and code for log controller --- .../project.pbxproj | 20 ++--- .../Debug/EQNLogViewController.h} | 4 +- .../Debug/EQNLogViewController.m} | 54 +++++-------- Sources/Earthquake Network/Costanti.h | 2 + .../Earthquake Network/Models/EQNManager.m | 10 +-- .../Storyboards/Base.lproj/Main.storyboard | 78 +++++++++---------- 6 files changed, 73 insertions(+), 95 deletions(-) rename Sources/Earthquake Network/{ViewController/LogViewController.h => Controllers/Debug/EQNLogViewController.h} (67%) rename Sources/Earthquake Network/{ViewController/LogViewController.m => Controllers/Debug/EQNLogViewController.m} (55%) diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index 4b0b40e..5a29e12 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -50,7 +50,7 @@ 8C6CBAE521597E79005C426A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8C6CBAE421597E79005C426A /* GoogleService-Info.plist */; }; 8C7A3B66225A5EA40045B266 /* NSDictionary+EQNExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C7A3B64225A5EA30045B266 /* NSDictionary+EQNExtensions.m */; }; 8C8EBBA721540039002784BA /* EQNUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C8EBBA621540039002784BA /* EQNUser.m */; }; - 8CADAA9421B2627D0044E256 /* LogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CADAA9321B2627D0044E256 /* LogViewController.m */; }; + 8CADAA9421B2627D0044E256 /* EQNLogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CADAA9321B2627D0044E256 /* EQNLogViewController.m */; }; 8CAFD7C521825E4A00F8BD29 /* EQNSisma.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CAFD7C421825E4A00F8BD29 /* EQNSisma.m */; }; 8CBD3DC72149B9AD0070C963 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CBD3DC62149B9AD0070C963 /* AppDelegate.m */; }; 8CBD3DCA2149B9AD0070C963 /* AllerteViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CBD3DC92149B9AD0070C963 /* AllerteViewController.m */; }; @@ -338,8 +338,8 @@ 8C7A3B65225A5EA40045B266 /* NSDictionary+EQNExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+EQNExtensions.h"; sourceTree = ""; }; 8C8EBBA521540039002784BA /* EQNUser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EQNUser.h; sourceTree = ""; }; 8C8EBBA621540039002784BA /* EQNUser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EQNUser.m; sourceTree = ""; }; - 8CADAA9221B2627D0044E256 /* LogViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogViewController.h; sourceTree = ""; }; - 8CADAA9321B2627D0044E256 /* LogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LogViewController.m; sourceTree = ""; }; + 8CADAA9221B2627D0044E256 /* EQNLogViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EQNLogViewController.h; sourceTree = ""; }; + 8CADAA9321B2627D0044E256 /* EQNLogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EQNLogViewController.m; sourceTree = ""; }; 8CAFD7C321825E4A00F8BD29 /* EQNSisma.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EQNSisma.h; sourceTree = ""; }; 8CAFD7C421825E4A00F8BD29 /* EQNSisma.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EQNSisma.m; sourceTree = ""; }; 8CBD3DC22149B9AD0070C963 /* Earthquake Network.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Earthquake Network.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -585,6 +585,8 @@ isa = PBXGroup; children = ( 6544416A25E9599000C41714 /* EQNDebugViewController.swift */, + 8CADAA9221B2627D0044E256 /* EQNLogViewController.h */, + 8CADAA9321B2627D0044E256 /* EQNLogViewController.m */, ); path = Debug; sourceTree = ""; @@ -630,15 +632,6 @@ path = EQNNotificationService; sourceTree = ""; }; - 8C5EA22E217645C8002DC156 /* ViewController */ = { - isa = PBXGroup; - children = ( - 8CADAA9221B2627D0044E256 /* LogViewController.h */, - 8CADAA9321B2627D0044E256 /* LogViewController.m */, - ); - path = ViewController; - sourceTree = ""; - }; 8CBD3DB92149B9AD0070C963 = { isa = PBXGroup; children = ( @@ -665,7 +658,6 @@ 8CBD3DC42149B9AD0070C963 /* Earthquake Network */ = { isa = PBXGroup; children = ( - 8C5EA22E217645C8002DC156 /* ViewController */, 8CF66050214C0F7F009F4314 /* Costanti.h */, 6535600325F398CD00BB57D2 /* Costanti+Extensions.swift */, 8CBD3DC52149B9AD0070C963 /* AppDelegate.h */, @@ -1587,7 +1579,7 @@ DCEFF21A24F587E3009D3FE1 /* SettingItem.swift in Sources */, 8C8EBBA721540039002784BA /* EQNUser.m in Sources */, DC553AF625692E37000B521B /* StoryboardInitializable.swift in Sources */, - 8CADAA9421B2627D0044E256 /* LogViewController.m in Sources */, + 8CADAA9421B2627D0044E256 /* EQNLogViewController.m in Sources */, DC3BA11124D1A9C90062EE7F /* SubscriptionsViewController.swift in Sources */, DC646F27252B694A000AA5FD /* AlertsSeismicNotificationExpandedTableViewCell.swift in Sources */, ); diff --git a/Sources/Earthquake Network/ViewController/LogViewController.h b/Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.h similarity index 67% rename from Sources/Earthquake Network/ViewController/LogViewController.h rename to Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.h index 223f06f..f63b07a 100644 --- a/Sources/Earthquake Network/ViewController/LogViewController.h +++ b/Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.h @@ -1,5 +1,5 @@ // -// LogViewController.h +// EQNLogViewController.h // Earthquake Network // // Created by Luca Beretta on 01/12/18. @@ -8,6 +8,6 @@ #import -@interface LogViewController : UIViewController +@interface EQNLogViewController : UIViewController @end diff --git a/Sources/Earthquake Network/ViewController/LogViewController.m b/Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.m similarity index 55% rename from Sources/Earthquake Network/ViewController/LogViewController.m rename to Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.m index 61eb1fb..adbbe8e 100644 --- a/Sources/Earthquake Network/ViewController/LogViewController.m +++ b/Sources/Earthquake Network/Controllers/Debug/EQNLogViewController.m @@ -1,30 +1,30 @@ // -// LogViewController.m +// EQNLogViewController.m // Earthquake Network // // Created by Luca Beretta on 01/12/18. // Copyright © 2018 Luca Beretta. All rights reserved. // -#import "LogViewController.h" +#import "EQNLogViewController.h" #import "EQNManager.h" #import "EQNAccelerometroManager.h" #import "EQNUser.h" -@interface LogViewController () - -@property (nonatomic, strong) IBOutlet UITextView *logView; +@interface EQNLogViewController () +@property (weak, nonatomic) IBOutlet UITextView *logView; @property (nonatomic, strong) NSString *testo; - --(IBAction)chiudi:(id)sender; @end -@implementation LogViewController +@implementation EQNLogViewController -- (void)viewDidLoad { +#pragma mark - View Lifecycle + +- (void)viewDidLoad +{ [super viewDidLoad]; - // Do any additional setup after loading the view. - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aggiornaLog:) name:@"AGGIORNA_LOG" object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aggiornaLog:) name:EQNDebugLogWillUpdateNotification object:nil]; [[EQNManager defaultManager] avviaManager]; [[EQNAccelerometroManager sharedInstance] startUpdatingLocationBackground]; @@ -34,13 +34,10 @@ self.logView.text = self.testo; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} --(IBAction)chiudi:(id)sender{ - - +#pragma mark - Actions + +- (IBAction)chiudi:(id)sender +{ [[EQNManager defaultManager] stopManager]; [[EQNAccelerometroManager sharedInstance] stopUpdatingLocation]; [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -48,29 +45,16 @@ [self dismissViewControllerAnimated:YES completion:nil]; } --(void)aggiornaLog:(NSNotification *)notificaton{ - +#pragma mark - Notifications + +- (void)aggiornaLog:(NSNotification *)notificaton +{ NSDictionary *messaggio = notificaton.userInfo; NSString *messagioString = messaggio[@"messaggio"]; NSString *mes = self.logView.text; - // [mes stringByAppendingString:messagioString]; dispatch_async(dispatch_get_main_queue(), ^{ - self.logView.text = [NSString stringWithFormat:@"%@\n%@", mes, messagioString]; }); - } - - -/* -#pragma mark - Navigation - -// In a storyboard-based application, you will often want to do a little preparation before navigation -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. -} -*/ - @end diff --git a/Sources/Earthquake Network/Costanti.h b/Sources/Earthquake Network/Costanti.h index 9bcba99..a9d18a5 100644 --- a/Sources/Earthquake Network/Costanti.h +++ b/Sources/Earthquake Network/Costanti.h @@ -92,6 +92,8 @@ static NSNotificationName const EQNInAppPurchaseDidCompleteNotification = @"EQNI static NSNotificationName const EQNInAppPurchaseDidFailNotification = @"EQNInAppPurchaseDidFailNotification"; /// Notifica di nessun acquisto trovato static NSNotificationName const EQNInAppPurchaseNoTransactionsNotification = @"EQNInAppPurchaseNoTransactionsNotification"; +/// Notifica per aggiornare i log di debug +static NSNotificationName const EQNDebugLogWillUpdateNotification = @"EQNDebugLogWillUpdateNotification"; #pragma mark - Other constants diff --git a/Sources/Earthquake Network/Models/EQNManager.m b/Sources/Earthquake Network/Models/EQNManager.m index 934aa98..64176cf 100644 --- a/Sources/Earthquake Network/Models/EQNManager.m +++ b/Sources/Earthquake Network/Models/EQNManager.m @@ -232,7 +232,7 @@ if (!self.calibrazione) { if (!self.inCalibrazione) { if(timer > TEMPO_LATENZA_CALIBRAZIONE){ - [[NSNotificationCenter defaultCenter] postNotificationName:@"AGGIORNA_LOG" object:nil userInfo:@{@"messaggio": @"Avvio Calibrazione"}]; + [[NSNotificationCenter defaultCenter] postNotificationName:EQNDebugLogWillUpdateNotification object:nil userInfo:@{@"messaggio": @"Avvio Calibrazione"}]; NSLog(@"Avvio Calibrazione"); self.inCalibrazione = YES; @@ -267,7 +267,7 @@ withObject:nil waitUntilDone:YES]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"AGGIORNA_LOG" object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"Media %f stato %li", cal.media, (long)cal.stato ]}]; + [[NSNotificationCenter defaultCenter] postNotificationName:EQNDebugLogWillUpdateNotification object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"Media %f stato %li", cal.media, (long)cal.stato ]}]; if (self.calibrazione.stato == nonCalibrato){ @@ -303,7 +303,7 @@ NSLog(@"Rilevamento data %@ stato %li deviaizone %f ", ril.timestamp, (long)ril.rilievo, ril.deviazione); - [[NSNotificationCenter defaultCenter] postNotificationName:@"AGGIORNA_LOG" object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"Rilevamento data %@ stato %li deviaizone %f deviazione calibrazione %f", ril.timestamp, (long)ril.rilievo, ril.deviazione, self.calibrazione.deviazione]}]; + [[NSNotificationCenter defaultCenter] postNotificationName:EQNDebugLogWillUpdateNotification object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"Rilevamento data %@ stato %li deviaizone %f deviazione calibrazione %f", ril.timestamp, (long)ril.rilievo, ril.deviazione, self.calibrazione.deviazione]}]; if (ril == NULL){ [self performSelectorOnMainThread:@selector(avviaCalibrazione) @@ -353,10 +353,10 @@ [[ServerRequest defaultServerConnectionSingleton] inviaInformazioniAlServerWithURL:[EQNGeneratoreURLServer urlMessagioStatoSmartPhone:anCalibrazione rilevamento:anRilevamento] richiesta:tipo success:^(id result) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"AGGIORNA_LOG" object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"invio informazione al server tipo %ld inviato ", (long)tipo]}]; + [[NSNotificationCenter defaultCenter] postNotificationName:EQNDebugLogWillUpdateNotification object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"invio informazione al server tipo %ld inviato ", (long)tipo]}]; } failure:^(NSError *error) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"AGGIORNA_LOG" object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"invio informazione al server tipo %ld fallito ", (long)tipo]}]; + [[NSNotificationCenter defaultCenter] postNotificationName:EQNDebugLogWillUpdateNotification object:nil userInfo:@{@"messaggio": [NSString stringWithFormat:@"invio informazione al server tipo %ld fallito ", (long)tipo]}]; }]; } diff --git a/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard b/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard index 7fc7c0c..d21c340 100644 --- a/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard +++ b/Sources/Earthquake Network/Storyboards/Base.lproj/Main.storyboard @@ -373,7 +373,7 @@ In più sostieni il progetto di ricerca il quale non riceve finanziamenti estern - + @@ -1208,7 +1208,7 @@ In più sostieni il progetto di ricerca il quale non riceve finanziamenti estern - + @@ -1745,19 +1745,19 @@ Sisma rilevato da 10 smartphone - + - +