21 |
21 |
22 #import "SupportViewController.h" |
22 #import "SupportViewController.h" |
23 #import "CommodityFunctions.h" |
23 #import "CommodityFunctions.h" |
24 |
24 |
25 @implementation SupportViewController |
25 @implementation SupportViewController |
|
26 @synthesize waysToSupport; |
26 |
27 |
27 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
28 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
28 return rotationManager(interfaceOrientation); |
29 return rotationManager(interfaceOrientation); |
29 } |
30 } |
30 |
31 |
31 -(void) didReceiveMemoryWarning { |
32 #pragma mark - |
32 // Releases the view if it doesn't have a superview. |
33 #pragma mark View lifecycle |
|
34 -(void) viewDidLoad { |
|
35 [super viewDidLoad]; |
|
36 |
|
37 NSArray *array = [[NSArray alloc] initWithObjects: |
|
38 NSLocalizedString(@"Leave a positive review on iTunes!",@""), |
|
39 NSLocalizedString(@"Join us on Facebook",@""), |
|
40 NSLocalizedString(@"Follow on Twitter",@""), |
|
41 NSLocalizedString(@"Visit website",@""), |
|
42 nil]; |
|
43 self.waysToSupport = array; |
|
44 [array release]; |
|
45 |
|
46 self.tableView.rowHeight = 50; |
|
47 } |
|
48 |
|
49 #pragma mark - |
|
50 #pragma mark Table view data source |
|
51 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
|
52 return 2; |
|
53 } |
|
54 |
|
55 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
56 if (section == 0) |
|
57 return 1; |
|
58 else |
|
59 return [self.waysToSupport count] - 1; |
|
60 } |
|
61 |
|
62 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
63 static NSString *CellIdentifier = @"Cell"; |
|
64 NSInteger row = [indexPath row]; |
|
65 NSInteger section = [indexPath section]; |
|
66 |
|
67 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
68 if (cell == nil) |
|
69 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
70 |
|
71 NSString *rowString = [self.waysToSupport objectAtIndex:(row + section)]; |
|
72 cell.textLabel.text = rowString; |
|
73 |
|
74 if (section == 0) { |
|
75 cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
76 cell.imageView.image = nil; |
|
77 } else { |
|
78 cell.textLabel.textAlignment = UITextAlignmentLeft; |
|
79 NSString *imgString = nil; |
|
80 switch (row) { |
|
81 case 0: |
|
82 imgString = @"fb.png"; |
|
83 break; |
|
84 case 1: |
|
85 imgString = @"tw.png"; |
|
86 break; |
|
87 case 2: |
|
88 imgString = @"Icon-Small.png"; |
|
89 break; |
|
90 default: |
|
91 DLog(@"No way"); |
|
92 break; |
|
93 } |
|
94 |
|
95 UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString]; |
|
96 cell.imageView.image = img; |
|
97 [img release]; |
|
98 } |
|
99 |
|
100 return cell; |
|
101 } |
|
102 |
|
103 #pragma mark - |
|
104 #pragma mark Table view delegate |
|
105 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
106 NSString *urlString = nil; |
|
107 if ([indexPath section] == 0) |
|
108 urlString = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; |
|
109 else |
|
110 switch ([indexPath row]) { |
|
111 case 0: |
|
112 urlString = @"http://www.facebook.com/Hedgewars"; |
|
113 break; |
|
114 case 1: |
|
115 urlString = @"http://twitter.com/hedgewars"; |
|
116 break; |
|
117 case 2: |
|
118 urlString = @"http://www.hedgewars.org"; |
|
119 break; |
|
120 default: |
|
121 DLog(@"No way"); |
|
122 break; |
|
123 } |
|
124 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; |
|
125 } |
|
126 |
|
127 -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
|
128 if (section == 1) { |
|
129 UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)]; |
|
130 UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"surprise.png"]; |
|
131 UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
132 [img release]; |
|
133 imgView.center = CGPointMake(self.tableView.frame.size.width/2, 120); |
|
134 [footer addSubview:imgView]; |
|
135 [imgView release]; |
|
136 |
|
137 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)]; |
|
138 label.textAlignment = UITextAlignmentCenter; |
|
139 label.text = @" ♥ THANK YOU ♥ "; |
|
140 label.backgroundColor = [UIColor clearColor]; |
|
141 label.center = CGPointMake(self.tableView.frame.size.width/2, 250); |
|
142 [footer addSubview:label]; |
|
143 [label release]; |
|
144 |
|
145 return [footer autorelease]; |
|
146 } else |
|
147 return nil; |
|
148 } |
|
149 |
|
150 -(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
|
151 // image height + label height |
|
152 return 265; |
|
153 } |
|
154 |
|
155 #pragma mark - |
|
156 #pragma mark Memory management |
|
157 -(void)didReceiveMemoryWarning { |
33 [super didReceiveMemoryWarning]; |
158 [super didReceiveMemoryWarning]; |
34 // Release any cached data, images, etc that aren't in use. |
|
35 } |
159 } |
36 |
160 |
37 -(void) viewDidUnload { |
161 -(void) viewDidUnload { |
|
162 self.waysToSupport = nil; |
|
163 MSG_DIDUNLOAD(); |
38 [super viewDidUnload]; |
164 [super viewDidUnload]; |
39 // Release any retained subviews of the main view. |
|
40 // e.g. self.myOutlet = nil; |
|
41 } |
165 } |
42 |
166 |
43 -(void) dealloc { |
167 -(void) dealloc { |
|
168 [self.waysToSupport release]; |
44 [super dealloc]; |
169 [super dealloc]; |
45 } |
170 } |
46 |
171 |
47 -(IBAction) buttonPressed:(id) sender { |
|
48 NSString *reviewURL = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; |
|
49 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]]; |
|
50 } |
|
51 |
|
52 @end |
172 @end |