refactor: Add a type inside the SettingItem model

This commit is contained in:
Andrea Busi
2020-08-26 14:00:56 +02:00
parent b70bd95a6d
commit 1c0a449c05
6 changed files with 18 additions and 547 deletions
@@ -1,17 +0,0 @@
//
// RetiSismicheTableViewController.h
// Earthquake Network
//
// Created by Luca Beretta on 13/01/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RetiSismicheTableViewController : UITableViewController
@end
NS_ASSUME_NONNULL_END
@@ -1,514 +0,0 @@
//
// RetiSismicheTableViewController.m
// Earthquake Network
//
// Created by Luca Beretta on 13/01/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import "RetiSismicheTableViewController.h"
#import "EQNNotificeReteSismiche.h"
#import "EQNUtility.h"
#import "PickerViewController.h"
@interface RetiSismicheTableViewController () <PickerViewDelegate, UITextFieldDelegate>
@property (nonatomic, strong) NSArray *lista;
@property (nonatomic, strong) NSArray *listaVibrazioni;
@property (nonatomic, assign) BOOL isAbilitato;
@property (nonatomic, assign) BOOL isAbilitaVicini;
@property (nonatomic, assign) BOOL isTerremortiForti;
@property (nonatomic, strong) PickerViewController *pikerViewDistanza;
@property (nonatomic, strong) PickerViewController *pikerViewMagnitudoDebole;
@property (nonatomic, strong) PickerViewController *pikerViewMagnitudoForte;
@property (nonatomic, strong) UITextField *textRaggioPosizione;
@property (nonatomic, strong) NSString *stringRaggioPosizione;
@property (nonatomic, strong) UITextField *textEnergiaSisma;
@property (nonatomic, strong) NSString *stringEnergiaSisma;
@property (nonatomic, strong) UITextField *textDistanzaVicini;
@property (nonatomic, strong) NSString *stringDistanzaVicini;
@property (nonatomic, strong) UITextField *textEnergiaTerremotiForti;
@property (nonatomic, strong) NSString *stringEnergiaTerremotiForti;
@property (nonatomic, strong) UITextField *textFild;
@property (nonatomic, strong) UIColor *coloreTesto;
@end
@implementation RetiSismicheTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.lista = @[NSLocalizedString(@"Abilitato", @"voce menu"), NSLocalizedString(@"Reti sismiche", @"voce menu"), NSLocalizedString(@"Raggio dalla tua posizione", @"voce menu"), NSLocalizedString(@"Energia sisma", @"voce menu"), NSLocalizedString(@"Terremoti vicini", @"voce menu"), NSLocalizedString(@"Distanza", @"voce menu"), NSLocalizedString(@"Terremoti forti", @"voce menu"), NSLocalizedString(@"Magnitudo", @"voce menu")];
self.listaVibrazioni = @[NSLocalizedString(@"Modifica impostazioni", @"voce menu")];
self.pikerViewDistanza = [[PickerViewController alloc] initWithNibName:@"PickerViewController" bundle:nil dati:[EQNUtility arrayRaggioSismi]];
self.pikerViewDistanza.delegate = self;
self.pikerViewMagnitudoDebole = [[PickerViewController alloc] initWithNibName:@"PickerViewController" bundle:nil dati:@[NSLocalizedString(@"Magnitudo >= 2.0", @"voce menu"), NSLocalizedString(@"Magnitudo >= 3.0", @"voce menu"), NSLocalizedString(@"Magnitudo >= 3.5", @"voce menu"), NSLocalizedString(@"Magnitudo >= 4.5", @"voce menu"), NSLocalizedString(@"Magnitudo >= 5.5", @"voce menu")]];
self.pikerViewMagnitudoDebole.delegate = self;
self.pikerViewMagnitudoForte = [[PickerViewController alloc] initWithNibName:@"PickerViewController" bundle:nil dati:@[NSLocalizedString(@"Magnitudo >= 5.5", @"voce menu"), NSLocalizedString(@"Magnitudo >= 6.0", @"voce menu"), NSLocalizedString(@"Magnitudo >= 6.5", @"voce menu"), NSLocalizedString(@"Magnitudo >= 7.5", @"voce menu"), NSLocalizedString(@"Magnitudo >= 7.5", @"voce menu")]];
self.pikerViewMagnitudoForte.delegate = self;
if (![EQNNotificeReteSismiche center].distanzaPosizione)
[EQNNotificeReteSismiche center].distanzaPosizione = @"100000";
if (![EQNNotificeReteSismiche center].distanzaVicini)
[EQNNotificeReteSismiche center].distanzaVicini = @"100000"; //NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi");
if (![EQNNotificeReteSismiche center].listaEnti) {
[EQNNotificeReteSismiche center].listaEnti = [[EQNUtility arrayEnti] copy];
[[EQNNotificeReteSismiche center] saveUserInfo];
}
[[EQNNotificeReteSismiche center] saveUserInfo];
self.coloreTesto = [UIColor colorWithRed:0 green:0.5647 blue:0.317 alpha:1];
[self setupView];
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.tableView reloadData];
}
-(void)setupView{
self.isAbilitato = [EQNNotificeReteSismiche center].isAbilitato;
self.isAbilitaVicini = [EQNNotificeReteSismiche center].isAbilitaVicini;
self.isTerremortiForti = [EQNNotificeReteSismiche center].isTerremortiForti;
if ([[EQNNotificeReteSismiche center].distanzaPosizione isEqualToString:@"100000"])
self.stringRaggioPosizione = NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi");
else
self.stringRaggioPosizione = [EQNNotificeReteSismiche center].distanzaPosizione;
if ([[EQNNotificeReteSismiche center].distanzaVicini isEqualToString:@"100000"])
self.stringDistanzaVicini = NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi") ;
else
self.stringDistanzaVicini = [EQNNotificeReteSismiche center].distanzaVicini;
if ([EQNNotificeReteSismiche center].energiaSisma)
self.stringEnergiaSisma = [NSString stringWithFormat:@"%@ >= %@", NSLocalizedString(@"Magnitudo", @""),[EQNNotificeReteSismiche center].energiaSisma];
else{
[EQNNotificeReteSismiche center].energiaSisma = @"2.0";
self.stringEnergiaSisma = [NSString stringWithFormat:@"%@ >= %@", NSLocalizedString(@"Magnitudo", @""), [EQNNotificeReteSismiche center].energiaSisma];
}
if ([EQNNotificeReteSismiche center].energiaTerremotiForti)
self.stringEnergiaTerremotiForti = [NSString stringWithFormat:@"%@ >= %@", NSLocalizedString(@"Magnitudo", @""),[EQNNotificeReteSismiche center].energiaTerremotiForti];
else{
[EQNNotificeReteSismiche center].energiaTerremotiForti = @"5.5";
self.stringEnergiaTerremotiForti = [NSString stringWithFormat:@"%@ >= %@", NSLocalizedString(@"Magnitudo", @""), [EQNNotificeReteSismiche center].energiaTerremotiForti];
}
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return self.lista.count;
else
return self.listaVibrazioni.count;
}
- (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 da reti sismiche", @"titolo impostazioni notifiche");
else
titolo.text = NSLocalizedString(@"Vibrazioni e suono", @"titolo impostazioni notifiche");
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0)
return 90;
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Ricevi le notifiche dei sismi rilevati dalle agenzie nazionalie internazionali", @"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;
case 1:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaEnti"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *enti = (UILabel *)[cell viewWithTag:2];
NSString *elencoEnti = @"";
int i = 1;
for (NSString *ente in [EQNNotificeReteSismiche center].listaEnti){
NSString *formato = [NSString stringWithFormat:@"%@, ",ente ];
if (i == [EQNNotificeReteSismiche center].listaEnti.count)
formato = ente;
elencoEnti = [elencoEnti stringByAppendingString:formato];
i++;
}
enti.text = elencoEnti;
if (self.isAbilitato){
titolo.textColor = [UIColor blackColor];
enti.textColor = self.coloreTesto;
}
else{
titolo.textColor = [UIColor grayColor];
enti.textColor = [UIColor grayColor];
}
return cell;
}
break;
case 2:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
// Configure the cell...
self.textRaggioPosizione = (UITextField *)[cell viewWithTag:2];
self.textRaggioPosizione.inputView = self.pikerViewDistanza.view;
self.textRaggioPosizione.text = self.stringRaggioPosizione;
self.textRaggioPosizione.delegate = self;
if (self.isAbilitato){
self.textRaggioPosizione.textColor = self.coloreTesto;
titolo.textColor = [UIColor blackColor];
}
else{
self.textRaggioPosizione.textColor = [UIColor grayColor];
titolo.textColor = [UIColor grayColor];
}
self.textRaggioPosizione.enabled = self.isAbilitato;
return cell;
}
break;
case 4:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Notifica sismi di qualsiasi magnitudo se la distanza è inferiore a", @"voce menu");
if (self.isAbilitaVicini && 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;
case 3:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
// Configure the cell...
self.textEnergiaSisma = (UITextField *)[cell viewWithTag:2];
self.textEnergiaSisma.inputView = self.pikerViewMagnitudoDebole.view;
self.textEnergiaSisma.text = self.stringEnergiaSisma;
self.textEnergiaSisma.delegate = self;
if (self.isAbilitato){
self.textEnergiaSisma.textColor = self.coloreTesto;
titolo.textColor = [UIColor blackColor];
}
else{
self.textEnergiaSisma.textColor = [UIColor grayColor];
titolo.textColor = [UIColor grayColor];
}
self.textEnergiaSisma.enabled = self.isAbilitato;
return cell;
}
break;
case 5:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
// Configure the cell...
self.textDistanzaVicini = (UITextField *)[cell viewWithTag:2];
self.textDistanzaVicini.inputView = self.pikerViewDistanza.view;
self.textDistanzaVicini.text = self.stringDistanzaVicini;
self.textDistanzaVicini.delegate = self;
if (self.isAbilitaVicini && self.isAbilitato){
self.textDistanzaVicini.textColor = self.coloreTesto;
titolo.textColor = [UIColor blackColor];
}
else{
self.textDistanzaVicini.textColor = [UIColor grayColor];
titolo.textColor = [UIColor grayColor];
}
self.textDistanzaVicini.enabled = self.isAbilitaVicini;
self.textDistanzaVicini.enabled = self.isAbilitato;
return cell;
}
break;
case 6:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = NSLocalizedString(@"Notifica sismi forti a qualsiasi distanza se la magnitudo è maggiore a", @"voce menu");
if (self.isTerremortiForti && 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;
case 7:{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"vociDettagli"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.lista[indexPath.row];
// Configure the cell...
self.textEnergiaTerremotiForti = (UITextField *)[cell viewWithTag:2];
self.textEnergiaTerremotiForti.inputView = self.pikerViewMagnitudoForte.view;
self.textEnergiaTerremotiForti.text = self.stringEnergiaTerremotiForti;
self.textEnergiaTerremotiForti.delegate = self;
if (self.isTerremortiForti && self.isAbilitato){
self.textEnergiaTerremotiForti.textColor = self.coloreTesto;
titolo.textColor = [UIColor blackColor];
}
else{
self.textEnergiaTerremotiForti.textColor = [UIColor grayColor];
titolo.textColor = [UIColor grayColor];
}
self.textEnergiaTerremotiForti.enabled = self.isAbilitaVicini;
self.textEnergiaTerremotiForti.enabled = self.isAbilitato;
return cell;
}
break;
default:{
}break;
}
}
// Configure the cell...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaEtichettaRossa"];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = self.listaVibrazioni[indexPath.row];
titolo.textColor = [UIColor blackColor];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0)
switch (indexPath.row) {
case 0:{
self.isAbilitato = !self.isAbilitato;
[EQNNotificeReteSismiche center].isAbilitato = self.isAbilitato;
[[EQNNotificeReteSismiche center] saveUserInfo];
[self.tableView reloadData];
}break;
case 1:
[self performSegueWithIdentifier:@"listaEventi" sender:nil];
break;
case 4:{
self.isAbilitaVicini = !self.isAbilitaVicini;
[EQNNotificeReteSismiche center].isAbilitaVicini = self.isAbilitaVicini;
[[EQNNotificeReteSismiche center] saveUserInfo];
[self.tableView reloadData];
}break;
case 6:{
self.isTerremortiForti = !self.isTerremortiForti;
[EQNNotificeReteSismiche center].isTerremortiForti = self.isTerremortiForti;
[[EQNNotificeReteSismiche center] saveUserInfo];
[self.tableView reloadData];
}break;
default:
break;
}
else{
}
}
# pragma textFild delegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
self.textFild = textField;
return YES;
}
# pragma mark pikerView string
-(void)inviaDati:(NSDictionary *)elementi{
NSString *elemento = elementi[@"elemento"];
NSNumber *indice = elementi[@"indice"];
if ([elemento isEqualToString:NSLocalizedString(@"Qualsiasi distanza", @"voce elenco raggio sismi")]) {
elemento = @"100000";
}
if (self.textFild == self.textRaggioPosizione)
[EQNNotificeReteSismiche center].distanzaPosizione = elemento;
if (self.textFild == self.textDistanzaVicini)
[EQNNotificeReteSismiche center].distanzaVicini = elemento;
if (self.textFild == self.textEnergiaSisma){
NSString *intesita = @"";
switch ([indice intValue]) {
case 0:
intesita = @"2.0";
break;
case 1:
intesita = @"3.0";
break;
case 2:
intesita = @"3.5";
break;
case 3:
intesita = @"4.0";
break;
case 4:
intesita = @"4.5";
break;
case 5:
intesita = @"5.0";
break;
case 6:
intesita = @"5.5";
break;
default:
break;
}
[EQNNotificeReteSismiche center].energiaSisma = intesita;
}
if (self.textFild == self.textEnergiaTerremotiForti) {
NSString *intesita = @"";
switch ([indice intValue]) {
case 0:
intesita = @"5.5";
break;
case 1:
intesita = @"6.0";
break;
case 2:
intesita = @"6.5";
break;
case 3:
intesita = @"7.0";
break;
case 4:
intesita = @"7.5";
break;
default:
break;
}
[EQNNotificeReteSismiche center].energiaTerremotiForti = intesita;
}
[[EQNNotificeReteSismiche center] saveUserInfo];
[self setupView];
[self.tableView endEditing:YES];
}
-(void)chiudiView{
[self.tableView endEditing:YES];
}
@end