Files
eqn.ios/Sources/Earthquake Network/Controllers/Settings/SettingsViewController.m
T
Andrea Busi 9344eae39a refactor: New style for main settings page
- renamed from DettadliMenuTableViewController to SettingsViewController
- used inset table view style
- improve code
2020-08-26 13:45:26 +02:00

77 lines
2.6 KiB
Objective-C

//
// 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<SettingItem *> *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") icon:@"🚨" segue:SegueIdentifierAllertaSismica],
[[SettingItem alloc] initWithTitle:NSLocalizedString(@"Notifiche sismi", @"voce menu") 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];
NSString *segueIdentifier = setting.segue;
[self performSegueWithIdentifier:segueIdentifier 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