// // TsunamiViewController.m // Earthquake Network // // Created by Luca Beretta on 11/11/18. // Copyright © 2018 Luca Beretta. All rights reserved. // #import "TsunamiViewController.h" #import "Costanti.h" #import "EQNManager.h" #import "Tsunami.h" #import "DettagliTsunamiViewController.h" @interface TsunamiViewController () @property (nonatomic, weak) IBOutlet UITableView *tableView; @property (nonatomic, strong) NSArray *listaTsunami; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *fooTable; @end @implementation TsunamiViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aggiornaTabella:) name:NOTIFICA_DOWNLOAD_TERMINATO object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupView) name:IAPHelperPurchaseNotification object:nil]; [self setupView]; self.listaTsunami = [EQNManager defaultManager].listaTsunami; } - (void)setupView { if ([EQNPurchaseUtility isProVersionEnabled]) { self.fooTable.constant = 0; } } -(void)aggiornaTabella:(id)sender{ // self.listaSismi = [NSArray arrayWithArray:[EQNManager defaultManager].retiSismiche]; [self.tableView reloadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #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. if ([segue.identifier isEqualToString:@"apriDettagliTsunami"]) { DettagliTsunamiViewController *dettagli = (DettagliTsunamiViewController *)segue.destinationViewController; NSURL *link = (NSURL *)sender; dettagli.link = link; } } #pragma table view - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.listaTsunami.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 150; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ Tsunami *anTsunami = self.listaTsunami[indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tsunami" forIndexPath:indexPath]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = [anTsunami.message uppercaseString]; UILabel *descrizione = (UILabel *)[cell viewWithTag:3]; NSString *place = NSLocalizedString(@"Oceano Pacifico", @""); if ([anTsunami.receiver isEqualToString:@"Car"]) { place = NSLocalizedString(@"Mar dei Caraibi", @""); } if ([anTsunami.receiver isEqualToString:@"Haw"]) { place = NSLocalizedString(@"Isole Hawaii", @""); } descrizione.text = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Area di interesse", @""), place]; UILabel *dettagli = (UILabel *)[cell viewWithTag:5]; dettagli.text = [NSString stringWithFormat:@"%@: %@ %@ - %@",NSLocalizedString(@"Data", @""), anTsunami.date, NSLocalizedString(@"(Ora tua)", @""), anTsunami.differenza]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ Tsunami *anTsunami = self.listaTsunami[indexPath.row]; [self performSegueWithIdentifier:@"apriDettagliTsunami" sender:anTsunami.link]; } -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } @end