// // TempoRealeTableViewController.m // Earthquake Network // // Created by Luca Beretta on 09/01/2019. // Copyright © 2019 Luca Beretta. All rights reserved. // #import "TempoRealeTableViewController.h" #import "EQNNotificheTempoReale.h" #import "EQNUtility.h" #import "PickerViewController.h" #import "TBDInputViewControllerData.h" @interface TempoRealeTableViewController () @property (nonatomic, strong) NSArray *lista; @property (nonatomic, strong) NSArray *listaVibrazioni; @property (nonatomic, strong) PickerViewController *pikerViewDistanza; @property (nonatomic, strong) PickerViewController *pikerViewIntensita; @property (nonatomic, assign) BOOL isAbilitato; @property (nonatomic, assign) BOOL isSismaSenzaIntensita; @property (nonatomic, strong) UITextField *textsismiDaNotificare; @property (nonatomic, strong) UITextField *textFildSismiLievi; @property (nonatomic, strong) UITextField *textFildSismiForti; @property (nonatomic, strong) UITextField *textFild; @property (nonatomic, strong) NSString *stringSismiDaNotificare; @property (nonatomic, strong) NSString *stringDistanzaLievi; @property (nonatomic, strong) NSString *stringDistanzaForti; @end @implementation TempoRealeTableViewController - (void)viewDidLoad { [super viewDidLoad]; self.lista = @[NSLocalizedString(@"Abilitato", @"voce menu"), NSLocalizedString(@"Dettagli importanti sulla rilevazione dei sismi", @"voce menu"), NSLocalizedString(@"Sismi da notificare", @"voce menu"), NSLocalizedString(@"Sismi senza intensità", @"voce menu"), NSLocalizedString(@"Raggio sismi lievi", @"voce menu"), NSLocalizedString(@"Raggio sismi forti o intensità non disponibile", @"voce menu")]; self.listaVibrazioni = @[NSLocalizedString(@"Modifica impostazioni", @"voce menu")]; self.pikerViewDistanza = [[PickerViewController alloc] initWithNibName:@"PickerViewController" bundle:nil dati:[EQNUtility arrayRaggioSismi]]; self.pikerViewDistanza.delegate = self; self.pikerViewIntensita = [[PickerViewController alloc] initWithNibName:@"PickerViewController" bundle:nil dati:@[NSLocalizedString(@"Qualsiasi intensità", @"voce menu"), NSLocalizedString(@"Solo sismi forti", @"voce menu")]]; self.pikerViewIntensita.delegate = self; if (![EQNNotificheTempoReale center].distanzaTempoRealeLievi) [EQNNotificheTempoReale center].distanzaTempoRealeLievi = @"100000";// NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi"); if (![EQNNotificheTempoReale center].distanzaTempoRealeForti) [EQNNotificheTempoReale center].distanzaTempoRealeForti = @"100000"; // NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi"); [[EQNNotificheTempoReale center] saveUserInfo]; [self setUpView]; } -(void)setUpView{ self.isAbilitato = [EQNNotificheTempoReale center].attivaTempoReale; self.isSismaSenzaIntensita = [EQNNotificheTempoReale center].attivaSismiSenzaIntensita; if ([EQNNotificheTempoReale center].isSismiForti) self.stringSismiDaNotificare = NSLocalizedString(@"Solo sismi forti", @"voce menu"); else self.stringSismiDaNotificare = NSLocalizedString(@"Qualsiasi intensità", @"voce menu"); if ([[EQNNotificheTempoReale center].distanzaTempoRealeLievi isEqualToString:NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi") ]) self.stringDistanzaLievi = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"Abilitato", @""),[EQNNotificheTempoReale center].distanzaTempoRealeLievi]; else self.stringDistanzaLievi = [NSString stringWithFormat:@"%@, %@ km", NSLocalizedString(@"Abilitato", @""), [EQNNotificheTempoReale center].distanzaTempoRealeLievi]; if ([[EQNNotificheTempoReale center].distanzaTempoRealeForti isEqualToString:NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi")]) self.stringDistanzaForti = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"Abilitato", @""), [EQNNotificheTempoReale center].distanzaTempoRealeForti]; else self.stringDistanzaForti = [NSString stringWithFormat:@"%@, %@ km", NSLocalizedString(@"Abilitato", @""), [EQNNotificheTempoReale center].distanzaTempoRealeForti]; [self.tableView reloadData]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellSection"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; if (section == 0) titolo.text = NSLocalizedString(@"Notifiche sismi rilevati in tempo reale", @"titolo impostazioni notifiche"); else titolo.text = NSLocalizedString(@"Vibrazioni e suono", @"titolo impostazioni notifiche"); return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { switch (indexPath.row) { case 1: return 50; break; default: return 90; break; } } return 50; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { switch (section) { case 0: return self.lista.count; break; default: return self.listaVibrazioni.count; break; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { switch (indexPath.row) { case 0:{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.lista[indexPath.row]; UILabel *stato = (UILabel *)[cell viewWithTag:2]; stato.text = NSLocalizedString(@"Ricevi le notifiche in tempo reale dei sismi rilevati dalla rete smartphone", @"voce menu"); if (self.isAbilitato){ cell.accessoryType = UITableViewCellAccessoryCheckmark; titolo.textColor = [UIColor blackColor]; stato.textColor = [UIColor blackColor]; } else{ cell.accessoryType = UITableViewCellAccessoryNone; titolo.textColor = [UIColor grayColor]; stato.textColor = [UIColor grayColor]; } return cell; } break; case 3:{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.lista[indexPath.row]; UILabel *stato = (UILabel *)[cell viewWithTag:2]; stato.text = NSLocalizedString(@"Notifica anche sismi per i quali non è possibile stimare l'intensità", @"voce menu"); if (self.isSismaSenzaIntensita){ cell.accessoryType = UITableViewCellAccessoryCheckmark; titolo.textColor = [UIColor blackColor]; stato.textColor = [UIColor blackColor]; } else{ cell.accessoryType = UITableViewCellAccessoryNone; titolo.textColor = [UIColor grayColor]; stato.textColor = [UIColor grayColor]; } return cell; } case 2:{ // vociDettagli UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.lista[indexPath.row]; // Configure the cell... self.textsismiDaNotificare = (UITextField *)[cell viewWithTag:2]; self.textsismiDaNotificare.delegate = self; self.textsismiDaNotificare.inputView = self.pikerViewIntensita.view; self.textsismiDaNotificare.text = self.stringSismiDaNotificare; return cell; } break; case 4:{ // vociDettagli UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.lista[indexPath.row]; // Configure the cell... self.textFildSismiLievi = (UITextField *)[cell viewWithTag:2]; self.textFildSismiLievi.delegate = self; self.textFildSismiLievi.inputView = self.pikerViewDistanza.view; self.textFildSismiLievi.text = self.stringDistanzaLievi; return cell; } case 5:{ // vociDettagli UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.lista[indexPath.row]; // Configure the cell... self.textFildSismiForti = (UITextField *)[cell viewWithTag:2]; self.textFildSismiForti.delegate = self; self.textFildSismiForti.inputView = self.pikerViewDistanza.view; self.textFildSismiForti.text = self.stringDistanzaForti; return cell; } break; default:{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaEtichettaRossa"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = NSLocalizedString(@"Dettagli importanti sulla rilevazione di sismi", @"voce menu"); return cell; }break; } } // Configure the cell... UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaEtichettaRossa"]; UILabel *titolo = (UILabel *)[cell viewWithTag:1]; titolo.text = self.listaVibrazioni[indexPath.row]; titolo.textColor = [UIColor blackColor]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.section == 0) switch (indexPath.row) { case 0:{ self.isAbilitato = !self.isAbilitato; [EQNNotificheTempoReale center].attivaTempoReale = self.isAbilitato; [[EQNNotificheTempoReale center] saveUserInfo]; [self.tableView reloadData]; }break; case 3:{ self.isSismaSenzaIntensita = !self.isSismaSenzaIntensita; [EQNNotificheTempoReale center].attivaSismiSenzaIntensita = self.isSismaSenzaIntensita; [[EQNNotificheTempoReale center] saveUserInfo]; [self.tableView reloadData]; }break; default: break; } else{ } } # pragma textFild delegate - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ self.textFild = textField; return YES; } # pragma mark pikerView string -(void)inviaDati:(NSDictionary *)elementi{ NSString *elemento = elementi[@"elemento"]; if (self.textFild == self.textsismiDaNotificare){ if ([elemento isEqualToString:NSLocalizedString(@"Qualsiasi intensità", @"voce menu")]) [EQNNotificheTempoReale center].isSismiForti = NO; else [EQNNotificheTempoReale center].isSismiForti = YES; } if (self.textFild == self.textFildSismiLievi) [EQNNotificheTempoReale center].distanzaTempoRealeLievi = elemento; if (self.textFild == self.textFildSismiForti) [EQNNotificheTempoReale center].distanzaTempoRealeForti = elemento; [[EQNNotificheTempoReale center] saveUserInfo]; [self setUpView]; [self.tableView endEditing:YES]; } -(void)chiudiView{ [self.tableView endEditing:YES]; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ /* #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