Files
eqn.ios/Sources/Earthquake Network/ViewController/impostazioniNotifiche/NotificheSismiTableViewController.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

236 lines
8.0 KiB
Objective-C

//
// NotificheSismiTableViewController.m
// Earthquake Network
//
// Created by Luca Beretta on 08/01/2019.
// Copyright © 2019 Luca Beretta. 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, 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;
@property (nonatomic, strong) UIColor *textColor;
@end
@implementation NotificheSismiTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.lista = @[/*NSLocalizedString(@"Notifiche sismi rilevati in tempo reale", @"voce menu"),*/ NSLocalizedString(@"Notifiche segnalazioni utente", @"voce menu"), NSLocalizedString(@"Notifiche da reti sismiche", @"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.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
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellSection"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = NSLocalizedString(@"Notifiche sismi", @"titolo impostazioni notifiche");
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.lista.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
return 60;
break;
case 1:
return 60;
break;
/* case 2:
return 60;
break;*/
default:
break;
}
return 90;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 2:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneOrario"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Ricevi le notifiche solo in un intervallo del giorno", @"voce menu");
if (self.abilitaIntervallo){
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:@"cellaOrario"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[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.abilitaIntervallo;
if (self.abilitaIntervallo) {
titolo.textColor = [UIColor blackColor];
self.textFildInizio.textColor = self.textColor;
}
else{
titolo.textColor = [UIColor grayColor];
self.textFildInizio.textColor = [UIColor grayColor];
}
return cell;
}
break;
case 4:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaOrario"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[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.abilitaIntervallo;
if (self.abilitaIntervallo) {
titolo.textColor = [UIColor blackColor];
self.textFildfine.textColor = self.textColor;
}
else{
titolo.textColor = [UIColor grayColor];
self.textFildfine.textColor = [UIColor grayColor];
}
return cell;
}
break;
default:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"impostazioniNotifiche"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
return cell;
}
break;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
/* case 0:{
[self performSegueWithIdentifier:@"sismiTempoReale" sender:nil];
}break;*/
case 0:
[self performSegueWithIdentifier:@"segnalazioneUtenti" sender:nil];
break;
case 1:
[self performSegueWithIdentifier:@"retiSismiche" sender:nil];
break;
case 2:{
self.abilitaIntervallo = !self.abilitaIntervallo;
[EQNImpostazioniNotifiche center].attivaIntervalloNotifica = self.abilitaIntervallo;
[[EQNImpostazioniNotifiche center] saveUserInfo];
[self.tableView reloadData];
}break;
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)
[EQNImpostazioniNotifiche center].oraioInizio = data;
else
[EQNImpostazioniNotifiche center].orarioFine = data;
[[EQNImpostazioniNotifiche center] saveUserInfo];
[self setUpView];
[self.tableView endEditing:YES];
}
-(void)esci{
[self.tableView endEditing:YES];
}
@end