3884
|
1 |
/*
|
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices
|
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 |
*
|
|
18 |
* File created on 19/09/2010.
|
|
19 |
*/
|
|
20 |
|
3891
|
21 |
|
3884
|
22 |
#import "SupportViewController.h"
|
|
23 |
#import "CommodityFunctions.h"
|
|
24 |
|
|
25 |
@implementation SupportViewController
|
4115
|
26 |
@synthesize waysToSupport;
|
3884
|
27 |
|
4115
|
28 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
3884
|
29 |
return rotationManager(interfaceOrientation);
|
|
30 |
}
|
|
31 |
|
4115
|
32 |
#pragma mark -
|
|
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 {
|
3884
|
158 |
[super didReceiveMemoryWarning];
|
|
159 |
}
|
|
160 |
|
|
161 |
-(void) viewDidUnload {
|
4115
|
162 |
self.waysToSupport = nil;
|
|
163 |
MSG_DIDUNLOAD();
|
3884
|
164 |
[super viewDidUnload];
|
|
165 |
}
|
|
166 |
|
|
167 |
-(void) dealloc {
|
4115
|
168 |
[self.waysToSupport release];
|
3884
|
169 |
[super dealloc];
|
|
170 |
}
|
|
171 |
|
|
172 |
@end
|