258 lines
8.7 KiB
Objective-C
258 lines
8.7 KiB
Objective-C
//
|
|
// EQNRetiSismiViewController.m
|
|
// Earthquake Network
|
|
//
|
|
// Created by Luca Beretta on 25/10/18.
|
|
// Copyright © 2018 Luca Beretta. All rights reserved.
|
|
//
|
|
|
|
#import "EQNRetiSismiViewController.h"
|
|
#import "EQNManager.h"
|
|
#import "EQNSisma.h"
|
|
#import "Costanti.h"
|
|
|
|
#import "SWRevealViewController.h"
|
|
#import "CellDettagliMappaTableViewCell.h"
|
|
#import "Cell_Reti_sismicheTableViewCell.h"
|
|
#import "Cell_Meteo_TableViewCell.h"
|
|
#import "ReteSismiDettagliMappa.h"
|
|
#import "SismaAnnotation.h"
|
|
#import "MenuFiltroEntiViewController.h"
|
|
#import "MenuSelezioneEntiViewController.h"
|
|
#import "ElencoFiltroEntiTableViewController.h"
|
|
#import <GoogleMaps/GoogleMaps.h>
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
|
|
@interface EQNRetiSismiViewController () <UITableViewDelegate, UITableViewDataSource, MenuFiltroEntiDelegate, MenuSelezioneEntiDelegate, MenuListaEntiDelegate>
|
|
|
|
@property (nonatomic, strong) NSArray *listaSismi;
|
|
@property (nonatomic, strong) IBOutlet UITableView *tableView;
|
|
@property (nonatomic, strong) NSIndexPath *selectIndex;
|
|
@property (nonatomic, assign) EQNReteSismicaCell tipoCell;
|
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fooTable;
|
|
|
|
@end
|
|
|
|
@implementation EQNRetiSismiViewController
|
|
|
|
static NSString * const SegueIdentifierFilters = @"FiltriEntiSismici";
|
|
static NSString * const SegueIdentifierSettings = @"impostazioniEntiSismi";
|
|
static NSString * const SegueIdentifierSeismicNetworks = @"elencoRetiSismiche";
|
|
|
|
#pragma mark - View Lifecycle
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
self.title = NSLocalizedString(@"tab_official", nil);
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:NOTIFICA_DOWNLOAD_TERMINATO object:nil];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupView) name:IAPHelperPurchaseNotification object:nil];
|
|
|
|
[self setupView];
|
|
[self refreshUI];
|
|
}
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
|
{
|
|
if ([segue.identifier isEqualToString:@"apri_mappa_dettagli"]) {
|
|
EQNSisma *sisma = (EQNSisma *)sender;
|
|
UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
|
|
ReteSismiDettagliMappa *mappaDett = (ReteSismiDettagliMappa *)nav.topViewController;
|
|
mappaDett.sisma = sisma;
|
|
} else if ([segue.identifier isEqualToString:SegueIdentifierFilters]) {
|
|
MenuFiltroEntiViewController *controller = (MenuFiltroEntiViewController *)segue.destinationViewController;
|
|
controller.delegate = self;
|
|
} else if ([segue.identifier isEqualToString:SegueIdentifierSettings]) {
|
|
MenuSelezioneEntiViewController *controller = (MenuSelezioneEntiViewController *)segue.destinationViewController;
|
|
controller.delegate = self;
|
|
} else if([segue.identifier isEqualToString:SegueIdentifierSeismicNetworks]){
|
|
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
|
|
ElencoFiltroEntiTableViewController *controller = (ElencoFiltroEntiTableViewController *)navController.topViewController;
|
|
controller.delegate = self;
|
|
}
|
|
}
|
|
|
|
#pragma mark - Private
|
|
|
|
- (void)setupView
|
|
{
|
|
if ([EQNPurchaseUtility isProVersionEnabled]) {
|
|
self.fooTable.constant = 0;
|
|
}
|
|
}
|
|
|
|
- (void)refreshUI
|
|
{
|
|
[super refreshUI];
|
|
|
|
self.listaSismi = [EQNUtility arrayRetisismicheFiltrate:[EQNManager defaultManager].retiSismiche];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self.tableView reloadData];
|
|
});
|
|
}
|
|
|
|
-(void)apriDettagli:(id)sender{
|
|
|
|
UIButton *button = (UIButton *)sender;
|
|
UITableViewCell *cell = (UITableViewCell *)[[[button superview] superview] superview];
|
|
self.selectIndex = [self.tableView indexPathForCell:cell];
|
|
switch (button.tag) {
|
|
case 12:
|
|
self.tipoCell = mappaCell;
|
|
break;
|
|
case 14:
|
|
self.tipoCell = meteoCell;
|
|
break;
|
|
default:
|
|
self.tipoCell = defaultCell;
|
|
[self chiudiMappa];
|
|
return;
|
|
break;
|
|
}
|
|
[self.tableView reloadRowsAtIndexPaths:@[self.selectIndex] withRowAnimation:UITableViewRowAnimationNone];
|
|
[self.tableView scrollToRowAtIndexPath:self.selectIndex
|
|
atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
|
|
|
}
|
|
|
|
-(void)apriDettagliMappa:(id)sender{
|
|
|
|
UIButton *button = (UIButton *)sender;
|
|
UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
|
|
NSIndexPath *index = [self.tableView indexPathForCell:cell];
|
|
|
|
EQNSisma *sisma = self.listaSismi[index.row];
|
|
[self performSegueWithIdentifier:@"apri_mappa_dettagli" sender:sisma];
|
|
|
|
}
|
|
-(void)chiudiMappa{
|
|
|
|
NSIndexPath *indexDelete = [self.selectIndex copy];
|
|
self.selectIndex = nil;
|
|
[self.tableView reloadRowsAtIndexPaths:@[indexDelete] withRowAnimation:UITableViewRowAnimationNone];
|
|
indexDelete = nil;
|
|
self.tipoCell = defaultCell;
|
|
[self.tableView scrollToRowAtIndexPath:indexDelete
|
|
atScrollPosition:UITableViewScrollPositionTop animated:NO];
|
|
}
|
|
|
|
#pragma mark - Actions
|
|
|
|
- (IBAction)refreshDataTapped:(id)sender
|
|
{
|
|
[[EQNManager defaultManager] sincronizza];
|
|
}
|
|
|
|
- (IBAction)openFilterTapped:(id)sender
|
|
{
|
|
// apriManu
|
|
[self performSegueWithIdentifier:SegueIdentifierFilters sender:nil];
|
|
}
|
|
|
|
- (IBAction)openSettingsTapped:(id)sender
|
|
{
|
|
// apriImpostazioni
|
|
[self performSegueWithIdentifier:SegueIdentifierSettings sender:nil];
|
|
}
|
|
|
|
#pragma table view
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
|
|
return self.listaSismi.count;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
if (self.selectIndex && self.selectIndex.row == indexPath.row)
|
|
return 368;
|
|
return 180;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
EQNSisma *sisma = self.listaSismi[indexPath.row];
|
|
Cell_Reti_sismicheTableViewCell *cell;
|
|
if (self.selectIndex && self.selectIndex.row == indexPath.row){
|
|
switch (self.tipoCell)
|
|
case mappaCell:{
|
|
cell = (CellDettagliMappaTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"sismaCell_mappa" forIndexPath:indexPath];
|
|
break;
|
|
default:
|
|
cell = (Cell_Meteo_TableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"sismaCell_meteo" forIndexPath:indexPath];
|
|
break;
|
|
}
|
|
[cell createOtherButton];
|
|
|
|
|
|
}
|
|
else
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"sismaCell" forIndexPath:indexPath];
|
|
|
|
cell.sisma = sisma;
|
|
[cell setupView];
|
|
[cell.chiudi addTarget:self action:@selector(chiudiMappa) forControlEvents:UIControlEventTouchDown];
|
|
[cell.mappaButton addTarget:self action:@selector(apriDettagli:) forControlEvents:UIControlEventTouchDown];
|
|
[cell.meteoButton addTarget:self action:@selector(apriDettagli:) forControlEvents:UIControlEventTouchDown];
|
|
[cell.dettagliMappa addTarget:self action:@selector(apriDettagliMappa:) forControlEvents:UIControlEventTouchDown];
|
|
[cell.clickMappa addTarget:self action:@selector(apriDettagliMappa:) forControlEvents:UIControlEventTouchDown];
|
|
[cell.condividi addTarget:self action:@selector(condividiView:) forControlEvents:UIControlEventTouchDown];
|
|
return cell;
|
|
|
|
}
|
|
|
|
-(void)condividiView:(id)sender{
|
|
|
|
UIButton *button = (UIButton *)sender;
|
|
CellDettagliMappaTableViewCell *cell = (CellDettagliMappaTableViewCell *)button.superview.superview.superview;
|
|
[self presentViewController:[EQNUtility shareFileWithPath:[cell condividiViewPath]] animated:YES completion:^{}];
|
|
|
|
}
|
|
|
|
-(void)dealloc{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
#pragma mark MenuFiltroEntiDelegate
|
|
|
|
- (void)menuFiltroEntiDidUpdateFilter:(MenuFiltroEntiViewController *)controller
|
|
{
|
|
[self refreshUI];
|
|
}
|
|
|
|
#pragma mark MenuSelezioneEntiDelegate
|
|
|
|
- (void)menuSelezioneEnti:(MenuSelezioneEntiViewController *)controller willSendData:(EQNfiltroEnti)filtro
|
|
{
|
|
[[NSUserDefaults standardUserDefaults] setInteger:filtro forKey:IMPOSTAZIONE_TIPO_FILTRO_RETI_SISMICHEI];
|
|
|
|
[self refreshUI];
|
|
}
|
|
|
|
- (void)menuSelezioneEntiWillOpenProviders:(MenuSelezioneEntiViewController *)controller
|
|
{
|
|
[self performSegueWithIdentifier:SegueIdentifierSeismicNetworks sender:nil];
|
|
}
|
|
|
|
#pragma mark MenuListaEntiDelegate
|
|
|
|
- (void)elencoFiltroEnti:(ElencoFiltroEntiTableViewController *)controller willSendData:(EQNfiltroEnti)filtro
|
|
{
|
|
[[NSUserDefaults standardUserDefaults] setInteger:filtro forKey:IMPOSTAZIONE_TIPO_FILTRO_RETI_SISMICHEI];
|
|
|
|
[self refreshUI];
|
|
}
|
|
|
|
@end
|