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

CommunityVC.m « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0592e661243382705ce66f014cb5692f31c05329 (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

#import "CommunityVC.h"
#import "UIViewController+Navigation.h"
#import "UIKitCategories.h"
#import <MessageUI/MFMailComposeViewController.h>
#import "../../3party/Alohalytics/src/alohalytics_objc.h"

extern NSString * const kAlohalyticsTapEventKey;

@interface CommunityVC () <MFMailComposeViewControllerDelegate>

@property (nonatomic) NSArray * items;

@end

@implementation CommunityVC

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.title = L(@"maps_me_community");

  self.items = @[@{@"Title" : @"",
                   @"Items" : @[@{@"Id" : @"Facebook", @"Title" : L(@"like_on_facebook"), @"Icon" : @"IconFacebook"},
                                @{@"Id" : @"Twitter", @"Title" : L(@"follow_on_twitter"), @"Icon" : @"IconTwitter"},
                                @{@"Id" : @"Subscribe", @"Title" : L(@"subscribe_to_news"), @"Icon" : @"IconSubscribe"}]},
                 @{@"Title" : @"",
                   @"Items" : @[@{@"Id" : @"Contact", @"Title" : L(@"contact_us"), @"Icon" : @"IconReportABug"}]}];
}

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

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

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

- (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:@"Facebook"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"likeOnFb"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://facebook.com/MapsWithMe"]];
  }
  else if ([itemId isEqualToString:@"Twitter"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"followOnTwitter"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/MAPS_ME"]];
  }
  else if ([itemId isEqualToString:@"Contact"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"contactUs"];
    [self contact];
  }
  else if ([itemId isEqualToString:@"Subscribe"])
  {
    [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"subscribeToNews"];
    [self subscribe];
  }
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)contact
{
  [self sendEmailWithText:nil subject:@"MAPS.ME" toRecipient:@"ios@maps.me"];
}

- (void)subscribe
{
  [self sendEmailWithText:L(@"subscribe_me_body") subject:L(@"subscribe_me_subject") toRecipient:@"subscribe@maps.me"];
}

- (void)sendEmailWithText:(NSString *)text subject:(NSString *)subject toRecipient:(NSString *)email
{
  if ([MFMailComposeViewController canSendMail])
  {
    MFMailComposeViewController * vc = [[MFMailComposeViewController alloc] init];
    vc.mailComposeDelegate = self;
    [vc setSubject:subject];
    [vc setMessageBody:text isHTML:NO];
    [vc setToRecipients:@[email]];
    [self presentViewController:vc animated:YES completion:nil];
  }
  else
  {
    NSString * text = [NSString stringWithFormat:L(@"email_error_body"), email];
    [[[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