-
Notifications
You must be signed in to change notification settings - Fork 1
/
RootViewController_j.m
653 lines (417 loc) · 18.8 KB
/
RootViewController_j.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/*
File: RootViewController_s.m
*/
#import "RootViewController_j.h"
//#import "ViewController.h"
#import "RegexKitLite.h"
#import "AsyncImageView.h"
#import "Favorite.h"
#import "FavoritesData.h"
#import "Mappa.h"
#import "UIImage+Resizing.h"
//#import "SchedaViewController.h"
//#import "MapView.h"
#import "ViewArticolo.h"
#import "ASIHTTPRequest.h"
@implementation RootViewController_j
//@synthesize earthquakeList;
@synthesize tableView = _tableView;
@synthesize magnitude;
@synthesize hud=_hud;
@synthesize isFiltered,prova;
@synthesize search,feeds;
@synthesize filteredListItems, savedSearchTerm, savedScopeButtonIndex, searchWasActive,titolo,ricerca,tracks;
@synthesize searchDisplayController;
#pragma mark -
- (void)dealloc {
// [earthquakeList release];
[dateFormatter release];
// [filteredFeed release];
[elencoFeed release];
// [self.tableView release], self.tableView = nil;
//[filteredListItems dealloc];
[super dealloc];
}
-(BOOL)canBecomeFirstResponder {
return YES;
}
- (void)dismissHUD:(id)arg {
[MBProgressHUD hideHUDForView:self.tableView animated:YES];
self.hud = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// getting an NSString
}
- (void)timeout:(id)arg {
_hud.labelText = nil;
_hud.detailsLabelText = nil;
_hud.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
_hud.mode = MBProgressHUDModeCustomView;
[self performSelector:@selector(dismissHUD:) withObject:nil afterDelay:1.0];
// [self.tableView reloadData];
}
-(void)viewWillAppear:(BOOL)animated{
if (IS_IPAD) {
self.view.frame=CGRectMake(0,0, 768, 1024);
toolBar.frame=CGRectMake(0, 0, 768, 44);
sfondotabella.frame=CGRectMake(0, 64, 768, 1024);
barraup.frame=CGRectMake(0, 60, 768, 10);
}
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:nil forKey:@"scheda"];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 768, 20);
// addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
addStatusBar.backgroundColor = [UIColor whiteColor]; //change this to match your navigation bar
[self.view addSubview:addStatusBar];
} else {
if (IS_IPAD) {
titolo.frame=CGRectMake(0, 32, 768, 20);
}
toolBar.tintColor=[UIColor colorWithRed:0.0/255.0 green:122.0/255.0 blue:255.0/255 alpha:1];
}
if (IS_IPAD) {
int t=64;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) t=44;
sfondotabella.frame=CGRectMake(0, t, 768, 1024);
sfondotabella.image=[UIImage imageNamed:@"sfondo_acqualta.png"];
}
[ self.tableView setBackgroundView:nil];
[ self.tableView setBackgroundView:[[[UIView alloc] init] autorelease]];
self.tableView.opaque=NO;
self.tableView.backgroundColor=[UIColor clearColor];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0 && IS_IPAD) {
barra.frame=CGRectMake(0,56, 768, 20);
}
}
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *livelli=[NSString stringWithFormat:@"%@?limit=10",[prefs objectForKey:@"apilivelli"]];
NSData *data = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:livelli]];
NSError *jsonError = nil;
NSJSONSerialization *jsonResponse = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
error:&jsonError];
self.tracks= (NSDictionary *)jsonResponse ;
titolo.text=self.title;
par=0;
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
[[FavoritesData sharedFavoritesData] getFavorites];
self.hud = [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
if ([self.title isEqualToString:@"Aziende"]) {
// _hud.labelText = @"Attendere qualche secondo..";
}
[self performSelector:@selector(timeout:) withObject:nil afterDelay:1];
start=1;
start1=0;
prev.enabled=NO;
// Add search bar to navigation bar
self.navigationItem.titleView = search;
[self.view bringSubviewToFront:toolBar];
[self.view bringSubviewToFront:titolo];
}
-(IBAction)nextpage{
start = start + 1;
start1 = start1 + 10;
self.hud = [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
_hud.labelText = nil;
[self performSelector:@selector(timeout:) withObject:nil afterDelay:1];
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(restart) userInfo:nil repeats:NO];
}
-(IBAction)prevpage{
start = start - 1;
start1=start1 -10;
self.hud = [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
_hud.labelText = nil;
[self performSelector:@selector(timeout:) withObject:nil afterDelay:1];
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(restart) userInfo:nil repeats:NO];
}
-(IBAction)reload{
start=1;
start1=0;
self.hud = [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
_hud.labelText = nil;
[self performSelector:@selector(timeout:) withObject:nil afterDelay:1];
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(restart) userInfo:nil repeats:NO];
// [self restart];
}
-(void)restart{
if (start==1) {
prev.enabled=NO;
succ.enabled=YES;
}else prev.enabled=YES;
if (start1==0) {
prev.enabled=NO;
succ.enabled=YES;
}else prev.enabled=YES;
NSString *aggiunta;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *livelli=[prefs objectForKey:@"apilivelli"];
livelli=[NSString stringWithFormat:@"%@?limit=10",livelli];
feeds=livelli;
// if ([titolo.text rangeOfString:@"News"].length != 0){
aggiunta=@"&offset=";
NSString *path = [NSString stringWithFormat:@"%@%@%i",feeds,aggiunta,start1];
NSLog(@"Path news =%@",path);
self.tracks=nil;
NSData *data = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:path]];
NSError *jsonError = nil;
NSJSONSerialization *jsonResponse = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
error:&jsonError];
self.tracks = (NSDictionary *)jsonResponse ;
[[self tableView] reloadData];
}
-(void)viewDidAppear:(BOOL)animated{
if (IS_IPAD) {
self.view.frame=CGRectMake(0,0, 768, 1024);
toolBar.frame=CGRectMake(0, 20, 768, 44);
[self.view bringSubviewToFront:barra];
[self.view bringSubviewToFront:toolBar];
[self.view bringSubviewToFront:titolo];
}
}
// On-demand initializer for read-only property.
- (NSDateFormatter *)dateFormatter {
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy' 'HH.mm.ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:3600*2]];
// [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
// [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
}
return dateFormatter;
}
#pragma mark -
#pragma mark UITableViewDelegate
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// NSLog(@"indexpath %longi",(long)indexPath.row);
return indexPath;
}
// The number of rows is equal to the number of earthquakes in the array.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// NSLog(@"Elenco feed =%li",[elencoFeed count]);
NSArray *monday = tracks[@"data"];
return [monday count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *monday = tracks[@"data"];
NSDictionary *item1;
NSString *CellIdentifier;
item1 = [[NSDictionary alloc] initWithDictionary:[monday objectAtIndex:indexPath.row]];
CellIdentifier = [NSString stringWithFormat:@"%@",item1[@"id"]];
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[[NSBundle mainBundle] loadNibNamed:@"CellCustomipad" owner:self options:NULL];
cell=CellCustomipad;
}
else {
[[NSBundle mainBundle] loadNibNamed:@"cellaView" owner:self options:NULL];
cell=cellaView;
}
}
cell.backgroundColor=[UIColor clearColor];
tableView.separatorColor=[UIColor clearColor];
BOOL isFav = [[FavoritesData sharedFavoritesData] favoriteWithId:CellIdentifier] != nil ;
NSString *starImage = isFav ? @"37x-Checkmark.png" : @"";
UIImage *cellBackground = [UIImage imageNamed:starImage] ;
check.image = cellBackground;
//background.frame = CGRectMake(295, 42, 10, 10);
check.contentMode = UIViewContentModeScaleAspectFill;
// background.backgroundColor=[UIColor clearColor];
CALayer * l1 = [check layer];
[l1 setMasksToBounds:YES];
[l1 setCornerRadius:5.0];
// You can even add a border
[l1 setBorderWidth:0.5];
[l1 setBorderColor:[[UIColor clearColor] CGColor]];
[cell.contentView addSubview:check];
NSString *link = item1[@"date_sent"];
link = [link stringByReplacingOccurrencesOfString:@" " withString:@""];
[link stripHtml];
// link=[link stringByReplacingOccurrencesOfString:@"T" withString:@" "];
// link = [link stringByReplacingOccurrencesOfString:@"Z" withString:@""];
link = [link stringByReplacingOccurrencesOfString:@".000" withString:@""];
UILabel *dateLabel = (UILabel *)[cell viewWithTag:3];
NSLog(@"date orig %@",link);
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat : @"yyyy-MM-dd'T'HH:mm:ss'Z'"];
// [dateFormatter1 setDateStyle:NSDateFormatterFullStyle];
[dateFormatter1 setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// NSDate *AppointmentDate = [dateFormatter1 dateFromString:link];
// NSString *dateString=[dateFormatter1 stringFromDate:AppointmentDate];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"eeee, dd-MMM-yy HH:mm:ss"];
NSString *dateString = [formatter stringFromDate:[dateFormatter1 dateFromString:link]];
// NSString *dateString=[NSString stringWithFormat:@"%@",AppointmentDate];
dateString=[dateString stringByReplacingOccurrencesOfString:@"+0000" withString:@""];
NSLog(@"DATE--> %@",dateString);
dateLabel.text = dateString;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0 && !IS_IPAD) {
sfondo.frame=CGRectMake(0, 0, 320, 83);
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0 && IS_IPAD) {
sfondo.frame=CGRectMake(0, 0, 620, 119);
}
if (indexPath.row==[elencoFeed count]-1) {
sfondo.image=[UIImage imageNamed:@"cellarossasf.png"];
// sfondo.alpha=0;
}
if (indexPath.row==0) {
sfondo.image=[UIImage imageNamed:@"cellarossasfup.png"];
// sfondo.alpha=0;
}
int minThreshold = [item1[@"level"] intValue]+0;
//float stringFloat = [item1[@"level"] floatValue];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:2];
titleLabel.text = [NSString stringWithFormat:@"%@", item1[@"level"]];
// cell.backgroundColor=[UIColor redColor];
UILabel *titleLabel1 = (UILabel *)[cell viewWithTag:11];
titleLabel1.text = [NSString stringWithFormat:@"%i cm.", minThreshold ];
// NSLog(@"qui 2");
UIImage *cellBackground1 = nil ;
UIImageView *imgview = (UIImageView *)[cell viewWithTag:10];
if ((minThreshold >=-50) && (minThreshold <=79)) {
titleLabel1.textColor=[UIColor greenColor];
// cellBackground1 = [UIImage imageNamed:@"sea1.gif"];
UIWebView *gifview =[[UIWebView alloc]initWithFrame:imgview.frame];
NSString *imageFileName = @"sea1b";
NSString *imageFileExtension = @"gif";
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];
NSString *imgHTMLTag = [NSString stringWithFormat:@"<img STYLE=\"position:absolute; TOP:0px; LEFT:0px; WIDTH:100%\" SRC=\"file://%@\"/>", imagePath];
gifview.opaque=NO;
gifview.backgroundColor=[UIColor clearColor];
gifview.userInteractionEnabled=NO;
//gifview.scalesPageToFit=YES;
[gifview loadHTMLString:imgHTMLTag baseURL:[[NSBundle mainBundle] bundleURL]];
CALayer * l3 = [gifview layer];
[l3 setMasksToBounds:YES];
[l3 setCornerRadius:5.0];
// You can even add a border
[l3 setBorderWidth:0.5];
[l3 setBorderColor:[[UIColor clearColor] CGColor]];
[cell addSubview:gifview];
}
if ((minThreshold >=80) && (minThreshold <=109)) {
titleLabel1.textColor=[UIColor yellowColor];
cellBackground1 = [UIImage imageNamed:@"sea2b.jpg"];
// NSLog(@"qui 3");
}
if ((minThreshold >=110) && (minThreshold <=139)) {
titleLabel1.textColor=[UIColor orangeColor];
cellBackground1 = [UIImage imageNamed:@"sea3b.jpg"];
}
if ((minThreshold >=110)&& (minThreshold <=190)) {
titleLabel1.textColor=[UIColor redColor];
cellBackground1 = [UIImage imageNamed:@"sea4b.jpg"];
}
NSString *titolo1 = item1[@"location"];
UILabel *subtitleLabel = (UILabel *)[cell viewWithTag:1];
subtitleLabel.text = [titolo1 uppercaseString] ;
subtitleLabel.textColor=titleLabel1.textColor;
CALayer * l11 = [imgview layer];
[l11 setMasksToBounds:YES];
[l11 setCornerRadius:5.0];
// You can even add a border
[l11 setBorderWidth:0.5];
// [l setBackgroundColor:[[UIColor whiteColor] CGColor]];
[l11 setBorderColor:[[UIColor clearColor] CGColor]];
imgview.image=cellBackground1;
[cell.contentView addSubview:imgview];
cell.selectionStyle=1;
// cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return 120;
}
else {
// return [[sectionInfo objectAtIndex:indexPath.row] floatValue];
return 84;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// NSString *CellIdentifier = [[elencoFeed objectAtIndex:indexPath.row] objectForKey:@"id"];
NSArray *monday = tracks[@"data"];
NSDictionary *item1;
NSString *CellIdentifier;
item1 = [[NSDictionary alloc] initWithDictionary:[monday objectAtIndex:indexPath.row]];
CellIdentifier = [NSString stringWithFormat:@"%@",item1[@"id"]];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIImage *cellBackground =[UIImage imageNamed:@"37x-Checkmark.png"];
// UIImageView *check = (UIImageView *)[cell viewWithTag:8];
check.image = cellBackground;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// background.frame = CGRectMake(655, 15, 15, 15);
}
else {
// background.frame = CGRectMake(280, 10, 10, 10);
}
//background.frame = CGRectMake(295, 42, 10, 10);
check.contentMode = UIViewContentModeScaleAspectFill;
// background.backgroundColor=[UIColor clearColor];
CALayer * l1 = [check layer];
[l1 setMasksToBounds:YES];
[l1 setCornerRadius:5.0];
// You can even add a border
[l1 setBorderWidth:0.5];
[l1 setBorderColor:[[UIColor clearColor] CGColor]];
[cell.contentView addSubview:check];
Favorite *favorite = [[FavoritesData sharedFavoritesData] favoriteWithId:CellIdentifier];
if(!favorite) {
Favorite *fav = [[Favorite alloc] init];
fav.favId = CellIdentifier;
//fav.description = FAV_DESC;
[[FavoritesData sharedFavoritesData] addFavorite:fav];
[fav release];
}
else {
// [[FavoritesData sharedFavoritesData] removeFavoriteById:CellIdentifier];
}
NSLog(@"self title %@",self.title);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"1" forKey:@"scheda"];
NSLog(@"apro singola scheda in mappa");
Mappa *controller = [[Mappa alloc] initWithNibName:@"Mappa" bundle:nil];
controller.feedlat=item1[@"latitude"];
controller.feedlon=item1[@"longitude"];
controller.feed=item1[@"location"];
controller.linkdapassare=@"";
controller.feedsubtit=[NSString stringWithFormat:@"%@", item1[@"level"]];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// [self.navigationController pushViewController: controller animated:YES];
// [controller release];
[self presentViewController:controller animated:YES completion:nil];
}
-(BOOL)ShouldAutorotate{
return false;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (IS_IPAD) {
return YES;
}else return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations{
if (IS_IPAD) {
return UIInterfaceOrientationMaskAll;
}else return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown) ;
}
-(IBAction)dismiss{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end