-
Notifications
You must be signed in to change notification settings - Fork 3
/
Bozo.mm
6635 lines (5181 loc) · 249 KB
/
Bozo.mm
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* PortoApp
iOS interface to the Colégio Visconde de Porto Seguro grade/news etc.
Created by Daniel Ferreira in 9/09/2013
(c) 2013 Daniel Ferreira
no rights whatsoever to the Fundação Visconde de Porto Seguro
The source code and copies built with it and binaries shipped with this source distribution are licensed under the GNU General Public License version 3.
The App Store copy has all rights reserved.
*/
// Tips:
// [23:41:33] <@DHowett> theiostream: At the top of the function, get 'self.bounds' out into a local variable. each time you call it is a dynamic dispatch because the compiler cannot assume that it has no side-effects
// Global TODOs:
// IMPLEMENT PRETTY SOON: URL Request Caching better handling
// IMPLEMENT PRETTY SOON: Better handling of the fuckshit view controller view bounds thing
// IMPLEMENT PRETTY SOON [23:42:13] <@DHowett> theiostream: the attributed strings and their CTFrameshit should be cached whenver possible. do not create a new attributed string every time the rect is drawn
// IMPLEMENT PRETTY SOON: Push Notifications
// IMPLEMENT PRETTY SOON: Learn NSURLSession (iOS7+, but regardless... we can do two branches for certain moment and afterwards implement compatibility measures.
/* Credits {{{
Personal thanks:
- Dustin Howett
- Guilherme (Lima) Stark
- Lucas Zamprogno
- Max Shavrick
- Natham Coracini
Project Thanks:
- HNKit (session design inspiration)
- MobileCydia.mm (goes without saying)
Code taken from third parties:
- XMLDocument, XMLElement were reproduced from Grant Paul (chpwn)'s HNKit.
(c) 2011 Xuzz Productions LLC
- LoginController, LoadingIndicatorView were changed minorly from Grant Paul (chpwn)'s news:yc.
(c) 2011 Xuzz Productions LLC
- KeychainItemWrapper was reproduced from Apple's GenericKeychain sample project.
(c) 2010 Apple Inc.
- ABTableViewCell was reproduced from enormego's github repo.
(c) 2008 Loren Brichter
- GTMNSStringHTMLAdditions category was taken from google-toolbox-for-mac.
(c) 2006-2008 Google Inc.
}}} */
/* Include {{{ */
#import <UIKit/UIKit.h>
#import <Security/Security.h>
#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>
#import <SystemConfiguration/SystemConfiguration.h>
#include <dlfcn.h>
#include "viewstate/viewstate.h"
/* }}} */
/* External {{{ */
#import "External.mm"
static UIImage *(*_UIImageWithName)(NSString *);
typedef enum : NSInteger {
NotReachable = 0,
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;
/* }}} */
/* Macros {{{ */
#define SYSTEM_VERSION_GT_EQ(v) \
([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define NUMBER_YES [NSNumber numberWithBool:YES]
#define NUMBER_NO [NSNumber numberWithBool:NO]
#ifdef DEBUG
#define debug(...) NSLog(__VA_ARGS__)
#else
#define debug(...)
#endif
// A Macro created on IRC by Maximus!
// I don't get shifts nor other bitwise operations.
#define UIColorFromHexWithAlpha(rgbValue,a) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:a]
// Thanks to http://stackoverflow.com/questions/139655/convert-pixels-to-points
#define pxtopt(px) ( px * 72 / 96 )
#define pttopx(pt) ( pt * 96 / 72 )
#define MAKE_CORETEXT_CONTEXT(context) \
CGContextRef context = UIGraphicsGetCurrentContext(); \
CGContextSetTextMatrix(context, CGAffineTransformIdentity); \
CGContextTranslateCTM(context, 0, self.bounds.size.height); \
CGContextScaleCTM(context, 1.0, -1.0);
#define AmericanLocale [NSLocale localeWithLocaleIdentifier:@"en_US"]
#define LOG_ALLOC(ptr) \
NSLog(@"%p: ALLOC (%d)", ptr, [ptr retainCount]);
#define LOG_RETAIN(ptr) \
NSLog(@"%p: RETAI (%d)", ptr, [ptr retainCount]);
#define LOG_RELEASE(ptr) \
NSLog(@"%p: RELES (%d)", ptr, [ptr retainCount]);
/* }}} */
/* Helpers {{{ */
// This is usually either quick functions written by me or stuff taken from StackOverflow :)
/* URL Encoding {{{ */
// Written by theiostream
static NSString *NSStringURLEncode(NSString *string) {
return [(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)string, NULL, CFSTR("!*'();:@&;=+$,/%?#[]"), kCFStringEncodingUTF8) autorelease];
}
static NSString *NSStringURLDecode(NSString *string) {
return [(NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (CFStringRef)string, CFSTR(""), kCFStringEncodingUTF8) autorelease];
}
static NSString *NSDictionaryURLEncode(NSDictionary *dict) {
NSMutableString *ret = [NSMutableString string];
NSArray *allKeys = [dict allKeys];
for (NSString *key in allKeys) {
[ret appendString:NSStringURLEncode(key)];
[ret appendString:@"="];
[ret appendString:NSStringURLEncode([dict objectForKey:key])];
[ret appendString:@"&"];
}
return [ret substringToIndex:[ret length]-1];
}
/* }}} */
/* Unescaping HTML {{{ */
// Found on StackOverflow.
static NSString *RemoveHTMLTags(NSString *content) {
NSString *newString = [[content copy] autorelease];
NSRange range;
while ((range = [newString rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
newString = [newString stringByReplacingCharactersInRange:range withString:@""];
return newString;
}
/* }}} */
/* News {{{ */
static NSString *ParseNewsParagraph(NSString *paragraph) {
NSString *unescaped = [RemoveHTMLTags(paragraph) gtm_stringByUnescapingFromHTML];
return unescaped;
}
/* }}} */
/* Caching {{{ */
// A pretty lame cache written by theiostream
static NSMutableDictionary *cache = nil;
static inline void InitCache() { cache = [[NSMutableDictionary alloc] init]; }
static inline id Cached(NSString *key) { return [cache objectForKey:key]; }
static inline void Cache(NSString *key, id object) { [cache setObject:object forKey:key]; }
/* }}} */
/* Pair {{{ */
// Pair class written by theiostream
@interface Pair : NSObject {
@public
id obj1;
id obj2;
}
- (id)initWithObjects:(id)object, ...;
@end
@implementation Pair
- (id)initWithObjects:(id)object, ... {
if ((self = [super init])) {
va_list args;
va_start(args, object);
obj1 = [object retain];
obj2 = [va_arg(args, id) retain];
va_end(args);
}
return self;
}
- (void)dealloc {
[obj1 release];
[obj2 release];
[super dealloc];
}
@end
/* }}} */
/* CoreText {{{ */
// CoreText helpers written by theiostream
/* Some history on these functions:
./2013-09-18.txt:[18:11:35] <@theiostream> i'm using coretext
./2013-09-18.txt:[19:23:51] <@theiostream> and Maximus, all made in coretext ;)
./2013-09-18.txt:[19:32:55] <@theiostream> Maximus: coretext doesn't let me
./2013-09-27.txt:[23:14:50] <@theiostream> i need to draw shit with coretext
./2013-09-27.txt:[23:15:03] <@theiostream> since i need to spin the context to draw coretext
./2013-09-27.txt:[23:16:47] <Maximus_> coretext is ok
./2013-09-01.txt:[16:37:47] <@DHowett> fucking coretext
*/
static CFAttributedStringRef CreateBaseAttributedString(CTFontRef font, CGColorRef textColor, CFStringRef string, BOOL underlined = NO, CTLineBreakMode lineBreakMode = kCTLineBreakByWordWrapping, CTTextAlignment alignment = kCTLeftTextAlignment) {
if (string == NULL) string = (CFStringRef)@"";
CGFloat spacing = 0.f;
CTParagraphStyleSetting settings[3] = {
{ kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), &spacing },
{ kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode },
{ kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment }
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, 3);
int underline = underlined ? 1 : kCTUnderlineStyleNone;
CFNumberRef number = CFNumberCreate(NULL, kCFNumberIntType, &underline);
const CFStringRef attributeKeys[4] = { kCTFontAttributeName, kCTForegroundColorAttributeName, kCTParagraphStyleAttributeName, kCTUnderlineStyleAttributeName };
const CFTypeRef attributeValues[4] = { font, textColor, paragraphStyle, number };
CFDictionaryRef attributes = CFDictionaryCreate(NULL, (const void **)attributeKeys, (const void **)attributeValues, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef attributedString = CFAttributedStringCreate(NULL, string, attributes);
CFRelease(attributes);
CFRelease(number);
CFRelease(paragraphStyle);
return attributedString;
}
static CTFramesetterRef CreateFramesetter(CTFontRef font, CGColorRef textColor, CFStringRef string, BOOL underlined, CTLineBreakMode lineBreakMode = kCTLineBreakByWordWrapping, CTTextAlignment alignment = kCTLeftTextAlignment) {
CFAttributedStringRef attributedString = CreateBaseAttributedString(font, textColor, string, underlined, lineBreakMode, alignment);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attributedString);
CFRelease(attributedString);
return framesetter;
}
static CTFrameRef CreateFrame(CTFramesetterRef framesetter, CGRect rect) {
CGPathRef path = CGPathCreateWithRect(rect, NULL);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(path);
return frame;
}
static void DrawFramesetter(CGContextRef context, CTFramesetterRef framesetter, CGRect rect) {
CTFrameRef frame = CreateFrame(framesetter, rect);
CTFrameDraw(frame, context);
CFRelease(frame);
}
/* }}} */
/* Colors {{{ */
// Taken from StackOverflow
// I wrote this!
// (and finally put bitwise operation knowledge to use)
/*#define MixColorHex 0x8FD8D8
static uint32_t GetNiceColor(int rr, int rg, int rb) {
int r = (rr + ((MixColorHex & 0xff0000) >> 16)) / 2;
int g = (rg + ((MixColorHex & 0xff00) >> 8)) / 2;
int b = (rb + (MixColorHex & 0xff)) / 2;
return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
}
static uint32_t RandomColorHex() {
// commentout
int rr = arc4random_uniform(256);
int rg = arc4random_uniform(256);
int rb = arc4random_uniform(256);
int rr = arc4random() % 256;
int rg = arc4random() % 256;
int rb = arc4random() % 256;
return GetNiceColor(rr, rg, rb);
}*/
static uint32_t Colors[64] = { 0x000000,0x00FF00,0x0000FF,0xFF0000,0x01FFFE,0xFFA6FE,0xFFDB66,0x006401,0x010067,0x95003A,0x007DB5,0xFF00F6,0xFFEEE8,0x774D00,0x90FB92,0x0076FF,0xD5FF00,0xFF937E,0x6A826C,0xFF029D,0xFE8900,0x7A4782,0x7E2DD2,0x85A900,0xFF0056,0xA42400,0x00AE7E,0x683D3B,0xBDC6FF,0x263400,0xBDD393,0x00B917,0x9E008E,0x001544,0xC28C9F,0xFF74A3,0x01D0FF,0x004754,0xE56FFE,0x788231,0x0E4CA1,0x91D0CB,0xBE9970,0x968AE8,0xBB8800,0x43002C,0xDEFF74,0x00FFC6,0xFFE502,0x620E00,0x008F9C,0x98FF52,0x7544B1,0xB500FF,0x00FF78,0xFF6E41,0x005F39,0x6B6882,0x5FAD4E,0xA75740,0xA5FFD2,0xFFB167,0x009BFF,0xE85EBE };
static uint32_t RandomColorHex() {
return Colors[arc4random_uniform(64)];
}
static UIColor *ColorForGrade(CGFloat grade, BOOL graded = YES) {
UIColor *color;
if (grade < 6) color = graded ? UIColorFromHexWithAlpha(0xFF3300, 1.f) : UIColorFromHexWithAlpha(0xC75F5F, 1.f);
else if (grade < 8) color = graded ? UIColorFromHexWithAlpha(0xFFCC00, 1.f) : UIColorFromHexWithAlpha(0xC7A15F, 1.f);
else color = graded ? UIColorFromHexWithAlpha(0x33CC33, 1.f) : UIColorFromHexWithAlpha(0x5FA4C7, 1.f);
return color;
}
/* }}} */
/* Image Resizing {{{ */
// From StackOverflow. Dude, how this answer has saved my ass so many times.
static UIImage *UIImageResize(UIImage *image, CGSize newSize) {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
/* }}} */
/* Fix View Bounds {{{ */
// I hate iOS 7.
// Like, everything was fine and then Apple decides to do whatever the shitfuck they're thinking to the bounding system.
// Thanks to http://iphonedevsdk.com/forum/iphone-sdk-development/7953-height-of-standard-navbar-tabbar-statusbar.html
#define HEIGHT_OF_STATUSBAR 20.f
#define HEIGHT_OF_NAVBAR 44.f
#define HEIGHT_OF_TABBAR 50.f
#define HEIGHT_WITH_TABBARCONTROLLER ([[UIScreen mainScreen] applicationFrame].size.height - HEIGHT_OF_NAVBAR - HEIGHT_OF_TABBAR)
static CGRect PerfectFrameForViewController(UIViewController *self) {
CGRect ret = [[UIScreen mainScreen] bounds];
if (SYSTEM_VERSION_GT_EQ(@"7.0")) {
ret.origin.y += HEIGHT_OF_STATUSBAR;
ret.size.height -= HEIGHT_OF_STATUSBAR;
if ([self navigationController]) {
ret.origin.y += HEIGHT_OF_NAVBAR;
ret.size.height -= HEIGHT_OF_NAVBAR;
}
}
else {
ret.size.height -= HEIGHT_OF_STATUSBAR;
if ([self navigationController])
ret.size.height -= HEIGHT_OF_NAVBAR;
}
if ([self tabBarController]) {
ret.size.height -= HEIGHT_OF_TABBAR;
}
ret.size.height += 1.f;
return ret;
/*CGRect ret = [[UIScreen mainScreen] applicationFrame];
ret.origin.y -= HEIGHT_OF_STATUSBAR;
ret.size.height += HEIGHT_OF_STATUSBAR;
return ret;*/
//return [[UIScreen mainScreen] applicationFrame];
}
static inline CGRect FrameWithNavAndTab() {
CGRect bounds = [[UIScreen mainScreen] bounds];
return CGRectMake(bounds.origin.x, (HEIGHT_OF_STATUSBAR + HEIGHT_OF_NAVBAR)*2, bounds.size.width, bounds.size.height - HEIGHT_OF_STATUSBAR - HEIGHT_OF_NAVBAR - HEIGHT_OF_TABBAR + 1.f);
}
static CGRect FixViewBounds(CGRect bounds) {
if (SYSTEM_VERSION_GT_EQ(@"7.0")) bounds.origin.y += HEIGHT_OF_STATUSBAR + HEIGHT_OF_NAVBAR;
bounds.size.height = HEIGHT_WITH_TABBARCONTROLLER + 1.f;
return bounds;
}
/* }}} */
/* Cool Button Delay Scroll View {{{ */
// Taken from http://stackoverflow.com/questions/3642547/uibutton-touch-is-delayed-when-in-uiscrollview
#define kNoDelayButtonTag 77
@interface NoButtonDelayScrollView : UIScrollView
@end
@implementation NoButtonDelayScrollView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[self setDelaysContentTouches:NO];
}
return self;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIButton class]]) return YES;
return [super touchesShouldCancelInContentView:view];
}
@end
@interface NoButtonDelayTableView : UITableView
@end
@implementation NoButtonDelayTableView
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
if ((self = [super initWithFrame:frame style:style])) {
[self setDelaysContentTouches:NO];
}
return self;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIButton class]]) return YES;
return [super touchesShouldCancelInContentView:view];
}
@end
/* }}} */
/* Circulares <a> tag {{{ */
static NSString *GetATagContent(NSString *aTag) {
NSLog(@"aTag is %@", aTag);
NSRange r1 = [aTag rangeOfString:@">"];
NSRange r2 = [aTag rangeOfString:@"<" options:0 range:NSMakeRange(r1.location + r1.length, [aTag length]-(r1.location + r1.length))];
NSRange r = NSMakeRange(r1.location + r1.length, r2.location - r1.location - r1.length);
return [[aTag substringWithRange:r] stringByDeletingPathExtension];
}
static NSString *GetATagHref(NSString *aTag) {
NSScanner *scanner = [NSScanner scannerWithString:aTag];
[scanner scanUpToString:@"href" intoString:NULL];
[scanner setScanLocation:[scanner scanLocation] + 6];
NSString *link;
[scanner scanUpToString:@"'" intoString:&link]; // replace ' with " and this becomes general-purpose
return link;
}
/* }}} */
/* Alert {{{ */
static void AlertError(NSString *title, NSString *text) {
UIAlertView *alertView = [[UIAlertView alloc] init];
[alertView setTitle:title];
[alertView setMessage:text];
[alertView addButtonWithTitle:@"OK"];
[alertView setDelegate:nil];
[alertView show];
[alertView release];
}
/* }}} */
/* Derp Cipher {{{ */
static char *decode_derpcipher(const char *str) {
char *r = (char *)malloc((strlen(str) + 1) * sizeof(char));
int i, len=strlen(str);
for (i=0; i<len; i++) { r[i] = str[i]-1; }
r[i] = '\0';
return r;
}
/* }}} */
/* }}} */
/* Constants {{{ */
#define kReportIssue "\n\nPara averiguarmos o problema, mande um email para [email protected] descrevendo o erro."
#define kServerError "\n\nTente recarregar a página ou espere o site se recuperar de algum problema."
#define kMissingGradesBacktraceStackTop @"notasParciaisWeb.NotasParciais.carregaPagina(String matricula) in D:\\Projetos\\Notas_Parciais\\notasParciaisWeb\\NotasParciais.aspx.cs:148"
#define kNoGradesLabelText @"Nenhuma avaliação ou nota encontrada para o aluno"
#define kNoZeugnisMessage @"O Boletim não pode ser visualizado no momento."
#define kPortoRootURL @"http://www.portoseguro.org.br/"
#define kPortoRootCircularesPage @"http://www.circulares.portoseguro.org.br/"
/* }}} */
/* Categories {{{ */
@interface NSDictionary (PortoURLEncoding)
- (NSString *)urlEncodedString;
@end
@implementation NSDictionary (PortoURLEncoding)
- (NSString *)urlEncodedString {
NSMutableString *ret = [NSMutableString string];
NSArray *allKeys = [self allKeys];
for (NSString *key in allKeys) {
[ret appendString:NSStringURLEncode(key)];
[ret appendString:@"="];
[ret appendString:NSStringURLEncode([self objectForKey:key])];
[ret appendString:@"&"];
}
return [ret substringToIndex:[ret length]-1];
}
@end
@interface NSString (AmericanFloat)
- (NSString *)americanFloat;
- (BOOL)isGrade;
@end
@implementation NSString (AmericanFloat)
- (NSString *)americanFloat {
return [self stringByReplacingOccurrencesOfString:@"," withString:@"."];
}
- (BOOL)isGrade {
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+[\\.,]\\d+" options:0 error:NULL];
return [regex numberOfMatchesInString:self options:0 range:NSMakeRange(0, [self length])] > 0;
}
@end
/* }}} */
/* Classes {{{ */
/* Sessions {{{ */
typedef void (^SessionAuthenticationHandler)(NSArray *, NSString *, NSError *);
@interface SessionAuthenticator : NSObject <NSURLConnectionDataDelegate> {
NSString *$username;
NSString *$password;
NSURLConnection *$connection;
SessionAuthenticationHandler $handler;
}
- (SessionAuthenticator *)initWithUsername:(NSString *)username password:(NSString *)password;
- (void)authenticateWithHandler:(SessionAuthenticationHandler)handler;
@end
@interface SessionController : NSObject {
KeychainItemWrapper *$keychainItem;
KeychainItemWrapper *$gradeKeyItem;
KeychainItemWrapper *$papersKeyItem;
KeychainItemWrapper *$truyyutItem;
NSDictionary *$accountInfo;
NSString *$gradeID;
NSString *$papersID;
NSString *$truyyut;
NSDictionary *$sessionInfo;
}
+ (SessionController *)sharedInstance;
- (NSDictionary *)accountInfo;
- (void)setAccountInfo:(NSDictionary *)secInfo;
- (BOOL)hasAccount;
- (NSString *)gradeID;
- (void)setGradeID:(NSString *)gradeID;
- (NSString *)papersID;
- (void)setPapersID:(NSString *)papersID;
- (NSString *)truyyut;
- (void)setTruyyut:(NSString *)truyyut;
- (NSDictionary *)sessionInfo;
- (void)setSessionInfo:(NSDictionary *)sessionInfo;
- (BOOL)hasSession;
- (void)loadSessionWithHandler:(void(^)(BOOL, NSError *))handler;
- (void)unloadSession;
- (NSArray *)authenticationCookies;
- (NSURLRequest *)requestForPageWithURL:(NSURL *)url method:(NSString *)method cookies:(NSArray *)cookies;
- (NSURLRequest *)requestForPageWithURL:(NSURL *)url method:(NSString *)method;
- (NSData *)loadPageWithURL:(NSURL *)url method:(NSString *)method response:(NSURLResponse **)response error:(NSError **)error;
@end
/* }}} */
/* Views {{{ */
/* Recovery View {{{ */
@class GradeContainer;
@protocol RecoveryTableViewCellDelegate;
@interface RecoveryTableViewCell : ABTableViewCell {
UISlider *$slider;
}
@property (nonatomic, assign) id<RecoveryTableViewCellDelegate> delegate;
@property (nonatomic, retain) GradeContainer *container;
@property (nonatomic, retain) GradeContainer *backupContainer;
@property (nonatomic, retain) NSString *rightText;
@property (nonatomic, retain) NSString *topText;
@property (nonatomic, retain) NSString *bottomText;
- (UISlider *)slider;
@end
@protocol RecoveryTableViewCellDelegate <NSObject>
- (void)sliderValueChangedForRecoveryCell:(RecoveryTableViewCell *)cell;
@end
/* }}} */
/* Pie Chart View {{{ */
@class GradeContainer;
@class PieChartView;
// i don't like iOS 7
@interface PickerActionSheet : UIView <UIPickerViewDelegate, UIPickerViewDataSource> {
UILabel *$subtitleLabel;
NSInteger *$rowMap;
NSInteger $selectedContainerType;
}
@property(nonatomic, assign) PieChartView *delegate;
- (id)initWithHeight:(CGFloat)height;
- (void)display;
- (void)dismiss;
- (void)setSubtitleLabelText:(NSString *)text;
@end
#define deg2rad(deg) (deg * (M_PI/180.f))
#define rad2deg(rad) (rad * (180.f/M_PI))
#define kPickerViewHeight 216.f
@interface PieChartPiece : NSObject
@property(nonatomic, assign) CGFloat percentage;
@property(nonatomic, retain) GradeContainer *container;
@property(nonatomic, assign) uint32_t color;
@property(nonatomic, retain) NSString *text;
@property(nonatomic, retain) CALayer *layer;
@property(nonatomic, assign) BOOL isBonus;
@end
// TODO: Better implementation.
// God, please tell me I am a bad programmer and that there is a better way to do this
// Why did you implement UISlider like this, Apple? Why do size changes need to be image-based
// instead of being built-in? Why, Apple, why?!
@interface PieChartSliderViewSlider : UISlider @end
@protocol PieChartSliderViewDelegate;
@interface PieChartSliderView : UIView {
PieChartPiece *$piece;
PieChartSliderViewSlider *$slider;
}
@property(nonatomic, assign) id<PieChartSliderViewDelegate> delegate;
- (UISlider *)slider;
- (PieChartPiece *)piece;
- (id)initWithFrame:(CGRect)frame piece:(PieChartPiece *)piece;
@end
@protocol PieChartSliderViewDelegate <NSObject>
@optional
- (void)pieChartSliderView:(PieChartSliderView *)sliderView didSlideWithValue:(float)value;
@end
@protocol PieChartViewDelegate;
@interface PieChartView : UIView <PieChartSliderViewDelegate> {
PieChartPiece *$emptyPiece;
NSMutableArray *$pieces;
CGFloat $radius;
NSInteger $percentageSum;
UIButton *$addGradeButton;
}
@property(nonatomic, assign) id<PieChartViewDelegate> delegate;
+ (CGFloat)extraHeight;
- (id)initWithFrame:(CGRect)frame pieces:(NSArray *)pieces count:(NSUInteger)count radius:(CGFloat)radius emptyPiece:(PieChartPiece *)empty;
- (void)updateBonusSliders;
- (void)didClosePickerSheet:(PickerActionSheet *)$pickerSheet withRowMap:(NSInteger *)$rowMap selectedContainerType:(NSInteger)$selectedContainerType;
- (void)didCancelPickerSheet:(PickerActionSheet *)pickerSheet;
@end
@protocol PieChartViewDelegate <NSObject>
@required
@optional
- (void)pieChartView:(PieChartView *)view didSelectPiece:(PieChartPiece *)piece;
@end
/* }}} */
/* Loading Indicator View {{{ */
@interface LoadingIndicatorView : UIView {
UIActivityIndicatorView *spinner_;
UILabel *label_;
UIView *container_;
}
@property (readonly, nonatomic) UILabel *label;
@property (readonly, nonatomic) UIActivityIndicatorView *activityIndicatorView;
@end
/* }}} */
/* Fail Views {{{ */
@interface FailView : UIView {
UIView *centerView;
UILabel *label;
UILabel *titleLabel;
}
@property(nonatomic, retain) NSString *text;
@property(nonatomic, retain) NSString *title;
@end
/* }}} */
/* }}} */
/* Controllers {{{ */
/* Web Data Controller {{{ */
@interface WebDataViewController : UIViewController {
dispatch_queue_t $queue;
LoadingIndicatorView *$loadingView;
FailView *$failureView;
UIView *$contentView;
UIView *$cacheView;
UIBarButtonItem *$refreshButton;
UIBarButtonItem *$spinnerButton;
NSData *$cachedData;
NSString *$cacheIdentifier;
}
- (WebDataViewController *)initWithIdentifier:(NSString *)identifier;
- (CGRect)contentViewFrame;
- (UIView *)contentView;
- (void)loadContentView;
- (void)unloadContentView;
- (void)refresh;
- (void)reloadData;
- (void)$freeViews;
- (void)freeData;
- (void)displayLoadingView;
- (void)hideLoadingView;
- (void)displayFailViewWithTitle:(NSString *)title text:(NSString *)text;
- (void)displayContentView;
- (void)$performUIBlock:(void(^)())block;
- (BOOL)shouldUseCachedData;
- (NSData *)cachedData;
- (void)cacheData:(NSData *)data;
@end
#define IfNotCached { if(![self shouldUseCachedData])
#define ElseNotCached(x) else{ x = [self cachedData]; } }
/* }}} */
/* Web View Controller {{{ */
@interface WebViewController : UIViewController <UIWebViewDelegate> {
UIWebView *$webView;
FailView *$failView;
LoadingIndicatorView *$loadingView;
UIBarButtonItem *$refreshButton;
UIBarButtonItem *$spinnerButton;
}
- (void)loadPage:(NSString *)page;
- (void)loadURL:(NSURL *)url;
- (void)loadLocalFile:(NSString *)file;
- (NSString *)executeJavascript:(NSString *)javascript;
/* UIWebView {{{ */
@property(nonatomic,assign) id<UIWebViewDelegate> delegate;
@property(nonatomic,readonly,retain) UIScrollView *scrollView NS_AVAILABLE_IOS(5_0);
- (void)loadRequest:(NSURLRequest *)request;
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;
@property(nonatomic,readonly,retain) NSURLRequest *request;
- (void)reload;
- (void)stopLoading;
- (void)goBack;
- (void)goForward;
@property(nonatomic,readonly,getter=canGoBack) BOOL canGoBack;
@property(nonatomic,readonly,getter=canGoForward) BOOL canGoForward;
@property(nonatomic,readonly,getter=isLoading) BOOL loading;
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;
@property(nonatomic) BOOL scalesPageToFit;
@property(nonatomic) BOOL detectsPhoneNumbers NS_DEPRECATED_IOS(2_0, 3_0);
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);
@property (nonatomic) BOOL allowsInlineMediaPlayback NS_AVAILABLE_IOS(4_0); // iPhone Safari defaults to NO. iPad Safari defaults to YES
@property (nonatomic) BOOL mediaPlaybackRequiresUserAction NS_AVAILABLE_IOS(4_0); // iPhone and iPad Safari both default to YES
@property (nonatomic) BOOL mediaPlaybackAllowsAirPlay NS_AVAILABLE_IOS(5_0); // iPhone and iPad Safari both default to YES
@property (nonatomic) BOOL suppressesIncrementalRendering NS_AVAILABLE_IOS(6_0); // iPhone and iPad Safari both default to NO
@property (nonatomic) BOOL keyboardDisplayRequiresUserAction NS_AVAILABLE_IOS(6_0); // default is YES
@property (nonatomic) UIWebPaginationMode paginationMode NS_AVAILABLE_IOS(7_0);
@property (nonatomic) UIWebPaginationBreakingMode paginationBreakingMode NS_AVAILABLE_IOS(7_0);
@property (nonatomic) CGFloat pageLength NS_AVAILABLE_IOS(7_0);
@property (nonatomic) CGFloat gapBetweenPages NS_AVAILABLE_IOS(7_0);
@property (nonatomic, readonly) NSUInteger pageCount NS_AVAILABLE_IOS(7_0);
/* }}} */
- (UIWebView *)webView;
@end
/* }}} */
/* Login Controller {{{ */
@protocol LoginControllerDelegate;
@interface LoginController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {
id<LoginControllerDelegate> $delegate;
UIImageView *$backgroundImageView;
UIView *$tableContainerView;
UIView *$centeringAlignmentView;
UITableView *$tableView;
UITableViewCell *$usernameCell;
UITableViewCell *$passwordCell;
UITableViewCell *$loadingCell;
UITextField *$usernameField;
UITextField *$passwordField;
UIImageView *$topImageView;
UILabel *$bottomLabel;
UIBarButtonItem *$cancelItem;
UIBarButtonItem *$completeItem;
BOOL $isAuthenticating;
}
@property (nonatomic, assign) id<LoginControllerDelegate> delegate;
- (void)sendRequest;
- (void)endRequestWithSuccess:(BOOL)success error:(NSError *)error;
- (void)authenticate;
- (NSArray *)gradientColors;
@end
@protocol LoginControllerDelegate <NSObject>
@optional
- (void)loginControllerDidLogin:(LoginController *)controller;
- (void)loginControllerDidCancel:(LoginController *)controller;
@end
@interface PortoLoginController : LoginController
@end
/* }}} */
/* News {{{ */
@interface NewsArticleWebViewController : WebViewController {
dispatch_queue_t $queue;
NSURL *$newsURL;
}
- (id)initWithQueue:(dispatch_queue_t)queue newsURL:(NSURL *)newsURL;
@end
@interface NavigationWebBrowserController : WebViewController {
dispatch_queue_t $queue;
}
- (id)initWithQueue:(dispatch_queue_t)queue;
@end
@interface NewsTableViewCell : ABTableViewCell {
UIImage *$newsImage;
NSString *$newsTitle;
NSString *$newsSubtitle;
UIImageView *$imageView;
}
@property(nonatomic, retain) UIImage *newsImage;
@property(nonatomic, retain) NSString *newsTitle;
@property(nonatomic, retain) NSString *newsSubtitle;
@end
@interface NewsViewController : WebDataViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *$imageData;
}
@end
/* }}} */
/* Grades {{{ */
#define kPortoAverage 60
@interface GradeContainer : NSObject <NSCopying>
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *grade;
@property(nonatomic, retain) NSString *value;
@property(nonatomic, retain) NSString *average;
@property(nonatomic, assign) NSInteger weight;
@property(nonatomic, retain) NSMutableArray *subGradeContainers;
@property(nonatomic, retain) NSMutableArray *subBonusContainers;
@property(nonatomic, assign) GradeContainer *superContainer;
@property(nonatomic, assign) BOOL isBonus;
@property(nonatomic, assign) NSUInteger section;
@property(nonatomic, assign) BOOL showsGraph;
@property(nonatomic, assign) BOOL isRecovery;
- (NSInteger)totalWeight;
- (BOOL)isAboveAverage;
- (void)makeValueTen;
- (NSString *)gradePercentage;
- (void)calculateGradeFromSubgrades;
- (void)calculateAverageFromSubgrades;
- (NSInteger)indexAtSupercontainer;
- (float)gradeInSupercontainer;
- (float)$gradePercentage;
- (BOOL)hasGrade;
- (BOOL)hasAverage;
@property(nonatomic, assign) NSInteger debugLevel;
@end
@interface TestView : UIView {
}
@property(nonatomic, retain) GradeContainer *container;
- (void)drawDataZoneRect:(CGRect)rect textColor:(CGColorRef)textColor dataFont:(CTFontRef)dataFont boldFont:(CTFontRef)boldFont inContext:(CGContextRef)context;
@end
@interface SubjectTableHeaderView : TestView
@end
@interface SubjectTableViewCellContentView : TestView
@end
@interface SubjectBonusTableHeaderView : TestView <UITextFieldDelegate> {
UITextField *$textField;
}
@end