Files
eqn.ios/Sources/Earthquake Network/ViewController/impostazioniNotifiche/NotificheTsunamiTableViewController.m
T
Andrea Busi 4d8bbdc7ef Production version
Add to Git the current app version (the same available in the OriginalZip folder)
2020-07-24 15:33:53 +02:00

301 lines
11 KiB
Objective-C

//
// NotificheTsunamiTableViewController.m
// Earthquake Network
//
// Created by Luca Beretta on 13/01/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import "NotificheTsunamiTableViewController.h"
#import "EQNNotificheTsunami.h"
#import "TBDInputViewControllerData.h"
#import "EQNUtility.h"
@interface NotificheTsunamiTableViewController () <InputViewControllerDataDelegate, UITextFieldDelegate>
@property (nonatomic, strong) NSArray *lista;
@property (nonatomic, strong) NSArray *listaVibrazioni;
@property (nonatomic, assign) BOOL isAbilitato;
@property (nonatomic, assign) BOOL isIntervalloNotifiche;
@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;
@property (nonatomic, strong) UIColor *textColor;
@end
@implementation NotificheTsunamiTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.lista = @[NSLocalizedString(@"Abilitato", @"voce menu"), /*NSLocalizedString(@"Tipo messaggio", @"voce menu"),*/ NSLocalizedString(@"Area di interesse", @"voce menu" )];
self.listaVibrazioni = @[NSLocalizedString(@"Modifica impostazioni", @"voce menu"), NSLocalizedString(@"Intervallo notifiche", @"voce menu"), NSLocalizedString(@"Ora inizio", @"voce menu"), NSLocalizedString(@"Ora fine", @"voce menu")];
self.pikerViewController = [[TBDInputViewControllerData alloc] initWithNibName:@"TBDInputViewControllerData" bundle:nil];
self.pikerViewController.delegate = self;
self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"HH:mm"];
self.textColor = [UIColor colorWithRed:0 green:0.5647 blue:0.317 alpha:1];
[self setupView];
}
-(void)setupView{
self.isAbilitato = [EQNNotificheTsunami center].isAbilitato;
self.isIntervalloNotifiche = [EQNNotificheTsunami center].isIntervalloNotifiche;
if ([EQNNotificheTsunami center].oraioInizio)
self.oraInizio = [self.dateFormatter stringFromDate:[EQNNotificheTsunami center].oraioInizio];
else
self.oraInizio = @"8:00";
if ([EQNNotificheTsunami center].orarioFine)
self.oraFine = [self.dateFormatter stringFromDate:[EQNNotificheTsunami center].orarioFine];
else
self.oraFine = @"22:00";
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (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 tsunami", @"titolo impostazioni notifiche");
else
titolo.text = NSLocalizedString(@"Vibrazioni e suono", @"titolo impostazioni notifiche");
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return self.lista.count;
else
return self.listaVibrazioni.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0)
switch (indexPath.row) {
case 0:
return 90;
break;
default:
return 60;
break;
}
switch (indexPath.row) {
case 0:
return 60;
break;
default:
return 90;
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Ricevi le notifiche per i messaggi rilasciati dal Pacific Tsunami Warning Center", @"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;
default:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"impostazioniNotifiche" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
if (self.isAbilitato){
titolo.textColor = [UIColor blackColor];
}
else{
titolo.textColor = [UIColor grayColor];
}
return cell;
}break;
}
}
switch (indexPath.row) {
case 0:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaEtichettaRossa" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.listaVibrazioni[indexPath.row];
titolo.textColor = [UIColor blackColor];
return cell;
}
break;
case 1:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.listaVibrazioni[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Ricevi le notifiche per i messaggi rilasciati dal Pacific Tsunami Warning Center", @"voce menu");
if (self.isIntervalloNotifiche){
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 2:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaOrario" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.listaVibrazioni[indexPath.row];
self.textFildInizio = (UITextField *)[cell viewWithTag:2];
self.textFildInizio.delegate = self;
self.textFildInizio.inputView = self.pikerViewController.view;
self.textFildInizio.text = self.oraInizio;
self.textFildInizio.enabled = self.isIntervalloNotifiche;
if (self.isIntervalloNotifiche) {
titolo.textColor = [UIColor blackColor];
self.textFildInizio.textColor = self.textColor;
}
else{
titolo.textColor = [UIColor grayColor];
self.textFildInizio.textColor = [UIColor grayColor];
}
return cell;
}
break;
default:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaOrario" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.listaVibrazioni[indexPath.row];
self.textFildfine = (UITextField *)[cell viewWithTag:2];
self.textFildfine.delegate = self;
self.textFildfine.inputView = self.pikerViewController.view;
self.textFildfine.text = self.oraFine;
self.textFildfine.enabled = self.isIntervalloNotifiche;
if (self.isIntervalloNotifiche) {
titolo.textColor = [UIColor blackColor];
self.textFildfine.textColor = self.textColor;
}
else{
titolo.textColor = [UIColor grayColor];
self.textFildfine.textColor = [UIColor grayColor];
}
return cell;
}break;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0)
switch (indexPath.row) {
case 0:{
self.isAbilitato = !self.isAbilitato;
[EQNNotificheTsunami center].isAbilitato = self.isAbilitato;
[[EQNNotificheTsunami center] saveUserInfo];
[self.tableView reloadData];
}break;
/* case 1:
if (self.isAbilitato)
[self performSegueWithIdentifier:@"messaggioInformativo" sender:nil];
break;*/
case 1:{
if (self.isAbilitato)
[self performSegueWithIdentifier:@"areaInteresse" sender:nil];
}break;
default:
break;
}
else{
switch (indexPath.row) {
case 1:{
self.isIntervalloNotifiche = !self.isIntervalloNotifiche;
[EQNNotificheTsunami center].isIntervalloNotifiche = self.isIntervalloNotifiche;
[[EQNNotificheTsunami center] saveUserInfo];
[self.tableView reloadData];
default:
break;
}
}
}
}
# pragma textFild delegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
self.textFild = textField;
return YES;
}
# pragma mark pikerViewdata data
-(void)dataSelezionata:(NSDate *)data withTextFild:(UITextField *)textFild{
self.textFild.text = [self.dateFormatter stringFromDate:data];
if (self.textFild == self.textFildInizio)
[EQNNotificheTsunami center].oraioInizio = data;
else
[EQNNotificheTsunami center].orarioFine = data;
[[EQNNotificheTsunami center] saveUserInfo];
[self setupView];
[self.tableView endEditing:YES];
}
-(void)esci{
[self.tableView endEditing:YES];
}
@end