// // SettingsViewController.m // Earthquake Network // // Refactored by Andrea Busi 25/08/2020. // Copyright © 2020 Earthquake Network. All rights reserved. // #import "SettingsViewController.h" #import "ServerRequest.h" #import "EQNGeneratoreURLServer.h" @interface SettingsViewController () @property (nonatomic, strong) NSArray *settings; @end @implementation SettingsViewController static NSString * const SegueIdentifierAllertaSismica = @"ShowAllertaSismica"; static NSString * const SegueIdentifierNotificheSismi = @"ShowNotificheSismi"; #pragma mark - View Lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.title = NSLocalizedString(@"Impostazioni", @""); [self.tableView registerClass:[SettingDetailTableViewCell class] forCellReuseIdentifier:SettingDetailTableViewCell.Identifier]; self.settings = @[ [[SettingItem alloc] initWithTitle:NSLocalizedString(@"Allerta in tempo reale", @"voce menu") subtitle:nil icon:@"🚨" segue:SegueIdentifierAllertaSismica], [[SettingItem alloc] initWithTitle:NSLocalizedString(@"Notifiche sismi", @"voce menu") subtitle:nil icon:@"🔔" segue:SegueIdentifierNotificheSismi] ]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.settings.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SettingDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingDetailTableViewCell.Identifier forIndexPath:indexPath]; SettingItem *setting = self.settings[indexPath.row]; cell.textLabel.text = setting.displayTitle; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SettingItem *setting = self.settings[indexPath.row]; if (setting.segue) { [self performSegueWithIdentifier:setting.segue sender:nil]; } } #pragma mark - Actions - (IBAction)closeTapped:(id)sender { [[ServerRequest defaultServerConnectionSingleton] inviaInformazioniAlServerWithURL:[EQNGeneratoreURLServer urlInvioImpostazioniNotifiche] richiesta:impostazioniNotifiche success:^(id result){ dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; }); } failure:^(NSError *error){ dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; }); }]; } @end