/
FirstViewController.m
129 lines (97 loc) · 3.17 KB
/
FirstViewController.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
//
// FirstViewController.m
// CIMon
//
// Created by Mark Needham on 01/08/2010.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "FirstViewController.h"
#import "XMLParser.h"
#import "Project.h"
@implementation FirstViewController
@synthesize textField;
- (IBAction) updateText:(id) sender {
NSMutableArray *discardedItems = [NSMutableArray array];
for (id item in dynamicallyAddedFields) {
[discardedItems addObject:item];
[item removeFromSuperview];
}
[dynamicallyAddedFields removeObjectsInArray:discardedItems];
NSURL *url = [NSURL URLWithString:textField.text];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
XMLParser *theDelegate = [[XMLParser alloc] initXMLParser];
[xmlParser setDelegate:theDelegate];
[xmlParser parse];
NSInteger x = 30;
NSInteger y = 0;
NSInteger column1 = true;
for(Project *project in theDelegate.projects) {
if(column1) {
x = 30;
y = y + 110;
column1 = false;
} else {
x = 290;
column1 = true;
}
UILabel *aLabel = [self createLabelFrom:project withXCoordinate:x withYCoordinate:y];
[dynamicallyAddedFields addObject:aLabel];
[self.view addSubview: aLabel];
}
}
-(UILabel*) createLabelFrom:(Project *)project withXCoordinate:(NSInteger)x withYCoordinate:(NSInteger)y {
UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 250, 100)];
if([[project lastBuildStatus] isEqualToString:@"Success"]) {
aLabel.backgroundColor = [UIColor greenColor];
} else {
aLabel.backgroundColor = [UIColor redColor];
}
aLabel.numberOfLines = 2;
aLabel.text = [project name];
aLabel.textAlignment = UITextAlignmentCenter;
return [aLabel autorelease];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (CIMonAppDelegate *)[[UIApplication sharedApplication] delegate];
NSURL *url = [NSURL URLWithString:@"http://10.12.1.177/hudson/cc.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
XMLParser *theDelegate = [[XMLParser alloc] initXMLParser];
[xmlParser setDelegate:theDelegate];
[xmlParser parse];
NSInteger x = 30;
NSInteger y = 0;
NSInteger column1 = true;
dynamicallyAddedFields = [[NSMutableArray alloc] init];
for(Project *project in theDelegate.projects) {
if(column1) {
x = 30;
y = y + 110;
column1 = false;
} else {
x = 290;
column1 = true;
}
UILabel *aLabel = [self createLabelFrom:project withXCoordinate:x withYCoordinate:y];
[dynamicallyAddedFields addObject:aLabel];
[self.view addSubview:aLabel];
}
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end