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

192 lines
6.6 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 <GoogleMaps/GoogleMaps.h>
#import "CellDettagliMappaTableViewCell.h"
#import "Cell_Reti_sismicheTableViewCell.h"
#import "Cell_Meteo_TableViewCell.h"
#import "ReteSismiDettagliMappa.h"
#import "SismaAnnotation.h"
#import <QuartzCore/QuartzCore.h>
@interface EQNRetiSismiViewController () <UITableViewDelegate, UITableViewDataSource>
@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
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aggiornaTabella:) name:NOTIFICA_DOWNLOAD_TERMINATO object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupView) name:IAPHelperPurchaseNotification object:nil];
[self setupView];
[self aggiornaTabella:nil];
}
-(void)setupView{
if([[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO] || [[NSUserDefaults standardUserDefaults] objectForKey:AQUISTO_PRO_SCONTATO])
self.fooTable.constant = 0;
}
-(void)aggiornaTabella:(id)sender{
self.listaSismi = [EQNUtility arrayRetisismicheFiltrate:[EQNManager defaultManager].retiSismiche];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(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 - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([segue.identifier isEqualToString:@"apri_mappa_dettagli"]) {
EQNSisma *sisma = (EQNSisma *)sender;
UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
ReteSismiDettagliMappa *mappaDett = (ReteSismiDettagliMappa *)nav.topViewController;
mappaDett.sisma = sisma;
}
}
#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];
}
@end