Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SettingsAndMoreVC.mm « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4344f9a4517a3fe5fc8c0ac4e1f9477df2001308 (plain)
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

#import "SettingsAndMoreVC.h"
#import "UIKitCategories.h"
#import <MessageUI/MFMailComposeViewController.h>
#import <sys/utsname.h>
#import "SettingsViewController.h"
#import "UIViewController+Navigation.h"
#import "WebViewController.h"
#import "CommunityVC.h"
#import "RichTextVC.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "platform/platform.hpp"

@interface SettingsAndMoreVC () <MFMailComposeViewControllerDelegate>

@property (nonatomic) NSArray * items;

@end

static NSString * const kiOSEmail = @"ios@maps.me";
extern NSString * const kLocaleUsedInSupportEmails = @"en_gb";
extern NSString * const kAlohalyticsTapEventKey;
extern NSDictionary * const deviceNames = @{@"x86_64" : @"Simulator",
                                     @"i386" : @"Simulator",
                                     @"iPod1,1" : @"iPod Touch",
                                     @"iPod2,1" : @"iPod Touch 2nd gen.",
                                     @"iPod3,1" : @"iPod Touch 3rd gen.",
                                     @"iPod4,1" : @"iPod Touch 4th gen.",
                                     @"iPod5,1" : @"iPod Touch 5th gen.",
                                     @"iPhone1,1" : @"iPhone",
                                     @"iPhone1,2" : @"iPhone 3G",
                                     @"iPhone2,1" : @"iPhone 3GS",
                                     @"iPhone3,1" : @"iPhone 4",
                                     @"iPhone4,1" : @"iPhone 4S",
                                     @"iPhone4,2" : @"iPhone 4S",
                                     @"iPhone4,3" : @"iPhone 4S",
                                     @"iPhone5,1" : @"iPhone 5",
                                     @"iPhone5,2" : @"iPhone 5",
                                     @"iPhone5,3" : @"iPhone 5c",
                                     @"iPhone5,4" : @"iPhone 5c",
                                     @"iPhone6,1" : @"iPhone 5s",
                                     @"iPhone6,2" : @"iPhone 5s",
                                     @"iPad1,1" : @"iPad WiFi",
                                     @"iPad1,2" : @"iPad GSM",
                                     @"iPad2,1" : @"iPad 2 WiFi",
                                     @"iPad2,2" : @"iPad 2 GSM",
                                     @"iPad2,2" : @"iPad 2 CDMA",
                                     @"iPad3,1" : @"iPad 3rd gen. WiFi",
                                     @"iPad3,2" : @"iPad 3rd gen. GSM",
                                     @"iPad3,3" : @"iPad 3rd gen. CDMA",
                                     @"iPad3,4" : @"iPad 4th gen. WiFi",
                                     @"iPad3,5" : @"iPad 4th gen. GSM",
                                     @"iPad3,6" : @"iPad 4th gen. CDMA",
                                     @"iPad4,1" : @"iPad Air WiFi",
                                     @"iPad4,2" : @"iPad Air GSM",
                                     @"iPad4,3" : @"iPad Air CDMA",
                                     @"iPad2,5" : @"iPad Mini WiFi",
                                     @"iPad2,6" : @"iPad Mini GSM",
                                     @"iPad2,7" : @"iPad Mini CDMA",
                                     @"iPad4,4" : @"iPad Mini 2nd gen. WiFi",
                                     @"iPad4,5" : @"iPad Mini 2nd gen. GSM",
                                     @"iPad4,6" : @"iPad Mini 2nd gen. CDMA"};


@implementation SettingsAndMoreVC

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.title = L(@"settings_and_more");
  self.items = @[@{@"Title" : @"",
                   @"Items" : @[@{@"Id" : @"Settings", @"Title" : L(@"settings"), @"Icon" : @"IconAppSettings"},
                                @{@"Id" : @"Help", @"Title" : L(@"help"), @"Icon" : @"IconHelp"},
                                @{@"Id" : @"ReportBug", @"Title" : L(@"report_a_bug"), @"Icon" : @"IconReportABug"}]},
                 @{@"Title" : @"",
                   @"Items" : @[@{@"Id" : @"Community", @"Title" : L(@"maps_me_community"), @"Icon" : @"IconSocial"},
                                @{@"Id" : @"RateApp", @"Title" : L(@"rate_the_app"), @"Icon" : @"IconRate"}]},
                 @{@"Title" : @"",
                   @"Items" : @[@{@"Id" : @"About", @"Title" : L(@"about_menu_title"), @"Icon" : @"IconAbout"},
                                @{@"Id" : @"Copyright", @"Title" : L(@"copyright"), @"Icon" : @"IconCopyright"}]}];
}

#pragma mark - TableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return [self.items count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
  return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
  return 20;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
  return self.items[section][@"Title"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return [self.items[section][@"Items"] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSDictionary * item = self.items[indexPath.section][@"Items"][indexPath.row];

  UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:[UITableViewCell className]];
  if (!cell) // iOS 5
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[UITableViewCell className]];

  cell.textLabel.text = item[@"Title"];
  cell.imageView.image = [UIImage imageNamed:item[@"Icon"]];

  return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSString * itemId = self.items[indexPath.section][@"Items"][indexPath.row][@"Id"];
  if ([itemId isEqualToString:@"About"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"about"];
    [self about];
  }
  else if ([itemId isEqualToString:@"Community"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"community"];
    CommunityVC * vc = [[CommunityVC alloc] initWithStyle:UITableViewStyleGrouped];
    [self.navigationController pushViewController:vc animated:YES];
  }
  else if ([itemId isEqualToString:@"RateApp"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"rate"];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self rateApp];
  }
  else if ([itemId isEqualToString:@"Settings"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"settingsMiles"];
    SettingsViewController * vc = [self.mainStoryboard instantiateViewControllerWithIdentifier:[SettingsViewController className]];
    [self.navigationController pushViewController:vc animated:YES];
  }
  else if ([itemId isEqualToString:@"ReportBug"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"reportABug"];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self reportBug];
  }
  else if ([itemId isEqualToString:@"Help"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"help"];
    [self help];
  }
  else if ([itemId isEqualToString:@"Copyright"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"copyright"];
    [self copyright];
  }
}

- (void)help
{
  NSString * path = [[NSBundle mainBundle] pathForResource:@"faq" ofType:@"html"];
  NSString * html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  WebViewController * aboutViewController = [[WebViewController alloc] initWithHtml:html baseUrl:nil andTitleOrNil:L(@"help")];
  aboutViewController.openInSafari = YES;
  [self.navigationController pushViewController:aboutViewController animated:YES];
}

- (void)about
{
  RichTextVC * vc = [[RichTextVC alloc] initWithText:L(@"about_text")];
  vc.title = L(@"about_menu_title");
  [self.navigationController pushViewController:vc animated:YES];
}

- (void)copyright
{
  string s; GetPlatform().GetReader("copyright.html")->ReadAsString(s);
  NSString * str = [NSString stringWithFormat:@"Version: %@ \n", [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"]];
  NSString * text = [NSString stringWithFormat:@"%@%@", str, @(s.c_str())];
  WebViewController * aboutViewController = [[WebViewController alloc] initWithHtml:text baseUrl:nil andTitleOrNil:L(@"copyright")];
  aboutViewController.openInSafari = YES;
  [self.navigationController pushViewController:aboutViewController animated:YES];
}

- (void)rateApp
{
  [[UIApplication sharedApplication] rateVersionFrom:@"rate_menu_item"];
}

- (void)reportBug
{
  struct utsname systemInfo;
  uname(&systemInfo);
  NSString * machine = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
  NSString * device = deviceNames[machine];
  if (!device)
    device = machine;
  NSString * languageCode = [[NSLocale preferredLanguages] firstObject];
  NSString * language = [[NSLocale localeWithLocaleIdentifier:kLocaleUsedInSupportEmails] displayNameForKey:NSLocaleLanguageCode value:languageCode];
  NSString * locale = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
  NSString * country = [[NSLocale localeWithLocaleIdentifier:kLocaleUsedInSupportEmails] displayNameForKey:NSLocaleCountryCode value:locale];
  NSString * bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
  NSString * text = [NSString stringWithFormat:@"\n\n\n\n- %@ (%@)\n- MAPS.ME %@\n- %@/%@", device, [UIDevice currentDevice].systemVersion, bundleVersion, language, country];
  if ([MFMailComposeViewController canSendMail])
  {
    MFMailComposeViewController * vc = [[MFMailComposeViewController alloc] init];
    vc.mailComposeDelegate = self;
    [vc setSubject:@"MAPS.ME"];
    [vc setToRecipients:@[kiOSEmail]];
    [vc setMessageBody:text isHTML:NO];
    [self presentViewController:vc animated:YES completion:nil];
  }
  else
  {
    NSString * text = [NSString stringWithFormat:L(@"email_error_body"), kiOSEmail];
    [[[UIAlertView alloc] initWithTitle:L(@"email_error_title") message:text delegate:nil cancelButtonTitle:L(@"ok") otherButtonTitles:nil] show];
  }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
  [self dismissViewControllerAnimated:YES completion:nil];
}

@end