Files
eqn.ios/Sources/Earthquake Network/ViewController/ElencoFiltroEntiTableViewController.m
T

115 lines
3.6 KiB
Objective-C

//
// ElencoFiltroEntiTableViewController.m
// Earthquake Network
//
// Created by Luca Beretta on 06/02/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import "ElencoFiltroEntiTableViewController.h"
#import "EQNUtility.h"
#import "costanti.h"
@interface ElencoFiltroEntiTableViewController ()
@property (nonatomic, strong) NSArray *listaEnti;
-(IBAction)save:(id)sender;
-(IBAction)cancell:(id)sender;
@end
@implementation ElencoFiltroEntiTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
if([[NSUserDefaults standardUserDefaults] objectForKey:IMPOSTAZIONE_ENTI_RETI_SISMICHEI]){
self.listaEnti = [[NSUserDefaults standardUserDefaults] objectForKey:IMPOSTAZIONE_ENTI_RETI_SISMICHEI];
}else{
self.listaEnti = [EQNUtility arrayEnti];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [EQNUtility arrayEnti].count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *descrizioni = [EQNUtility arrayDescrizioneEnti];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellaSelezioneAbilita" forIndexPath:indexPath];
UILabel *titolo = (UILabel *)[cell viewWithTag:1];
titolo.text = [EQNUtility arrayEnti][indexPath.row];
UILabel *stato = (UILabel *)[cell viewWithTag:2];
stato.text = descrizioni[indexPath.row];//NSLocalizedString(@"Ricevi le notifiche dei sismi rilevati dalle agenzie nazionalie internazionali", @"voce menu");
cell.accessoryType = UITableViewCellAccessoryNone;
if ([self.listaEnti containsObject:titolo.text]){
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;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray *array = [self.listaEnti mutableCopy];
NSString *selezioneEnete = [EQNUtility arrayEnti][indexPath.row];
if ([array containsObject:selezioneEnete])
[array removeObject:selezioneEnete];
else
[array addObject:selezioneEnete];
self.listaEnti = [NSArray arrayWithArray:array];
[self.tableView reloadData];
}
-(IBAction)save:(id)sender{
[[NSUserDefaults standardUserDefaults] setObject:self.listaEnti forKey:IMPOSTAZIONE_ENTI_RETI_SISMICHEI];
if (self.listaEnti.count == 1){
NSArray *enti = [EQNUtility arrayEnti];
NSUInteger index = [enti indexOfObject:[self.listaEnti firstObject]];
[[NSUserDefaults standardUserDefaults] setInteger:index forKey:IMPOSTAZIONE_NAZIONE_RETI_SISMICHEI];
}else{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:IMPOSTAZIONE_NAZIONE_RETI_SISMICHEI];
}
if ([self.delegate respondsToSelector:@selector(elencoFiltroEnti:willSendData:)]) {
[self.delegate elencoFiltroEnti:self willSendData:enti];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)cancell:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end