Files
eqn.ios/Sources/Earthquake Network/Controllers/Settings/NotificheSismiTableViewController.m
T
2020-08-27 18:43:45 +02:00

125 lines
4.6 KiB
Objective-C

//
// NotificheSismiTableViewController.m
// Earthquake Network
//
// Refactored by Andrea Busi 25/08/2020.
// Copyright © 2020 Earthquake Network. All rights reserved.
//
#import "NotificheSismiTableViewController.h"
#import "TBDInputViewControllerData.h"
#import "EQNImpostazioniNotifiche.h"
#import "EQNUtility.h"
#import "EQNNotificheTempoReale.h"
#import "EQNNotificheSegnalazioniUtente.h"
@interface NotificheSismiTableViewController () <InputViewControllerDataDelegate, UITextFieldDelegate>
@property (nonatomic, strong) NSArray<SettingItem *> *settings;
@property (nonatomic, assign) BOOL abilitaIntervallo;
@property (nonatomic, strong) TBDInputViewControllerData *pikerViewController;
@property (nonatomic, strong) NSString *oraInizio;
@property (nonatomic, strong) NSString *oraFine;
@property (nonatomic, strong) UITextField *textFildInizio;
@property (nonatomic, strong) UITextField *textFildfine;
@property (nonatomic, strong) UITextField *textFild;
@property (nonatomic, strong) NSDateFormatter *dateFormatter;
@end
@implementation NotificheSismiTableViewController
static NSString * const SegueIdentifierSegnalazioniUtente = @"segnalazioneUtenti";
static NSString * const SegueIdentifierRetiSismiche = @"retiSismiche";
#pragma mark - View Lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.settings = @[
[[SettingItem alloc] initWithType:SettingTypeDetail title:NSLocalizedString(@"Notifiche segnalazioni utente", @"voce menu") subtitle:nil icon:nil segue:SegueIdentifierSegnalazioniUtente],
[[SettingItem alloc] initWithType:SettingTypeDetail title:NSLocalizedString(@"Notifiche da reti sismiche", @"voce menu") subtitle:nil icon:nil segue:SegueIdentifierRetiSismiche]
];
[self.tableView registerClass:[SettingDetailTableViewCell class] forCellReuseIdentifier:SettingDetailTableViewCell.Identifier];
[self.tableView registerClass:[SettingSectionHeaderView class] forHeaderFooterViewReuseIdentifier:SettingSectionHeaderView.Identifier];
self.pikerViewController = [[TBDInputViewControllerData alloc] initWithNibName:@"TBDInputViewControllerData" bundle:nil];
self.pikerViewController.delegate = self;
self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"HH:mm"];
[self updateUI];
}
#pragma mark - Private
- (void)updateUI
{
self.abilitaIntervallo = [EQNImpostazioniNotifiche center].attivaIntervalloNotifica;
if ([EQNImpostazioniNotifiche center].oraioInizio)
self.oraInizio = [self.dateFormatter stringFromDate:[EQNImpostazioniNotifiche center].oraioInizio];
else
self.oraInizio = @"8:00";
if ([EQNImpostazioniNotifiche center].orarioFine)
self.oraFine = [self.dateFormatter stringFromDate:[EQNImpostazioniNotifiche center].orarioFine];
else
self.oraFine = @"22:00";
}
#pragma mark - Table view data source
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
SettingSectionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SettingSectionHeaderView.Identifier];
headerView.titleLabel.text = NSLocalizedString(@"Notifiche sismi", @"titolo impostazioni notifiche");
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return SettingSectionHeaderView.Height;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.settings.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SettingDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingDetailTableViewCell.Identifier];
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 pikerViewdata data
- (void)dataSelezionata:(NSDate *)data withTextFild:(UITextField *)textFild
{
self.textFild.text = [self.dateFormatter stringFromDate:data];
if (self.textFild == self.textFildInizio)
[EQNImpostazioniNotifiche center].oraioInizio = data;
else
[EQNImpostazioniNotifiche center].orarioFine = data;
[[EQNImpostazioniNotifiche center] saveUserInfo];
[self updateUI];
[self.tableView endEditing:YES];
}
@end