-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAboutController.m
206 lines (167 loc) · 6.57 KB
/
AboutController.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
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
//
// AboutController.m
// iBroke
//
// Created by Mujtaba Hussain on 31/10/11.
// This code is distributed under the terms and conditions of the MIT license.
//
// Copyright (c) 2011 Mujtaba Hussain
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#import "AboutController.h"
#import "AboutView.h"
#import "NotificationView.h"
@interface AboutController ()
@property (nonatomic, retain) UIView *aboutView;
- (void)emailDeveloper;
@end
@implementation AboutController
@synthesize aboutView = _aboutView;
static NSString *kCantSendEmail = @"Please configure email via settings.";
static NSString *kEmailSent = @"Your email has been sent";
static NSString *kEmailSaved = @"Your email has been saved";
static NSString *kEmailCancelled = @"Your email has been cancelled";
static NSString *kEmailFailed = @"Your email could not be sent";
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
{
self = [super initWithNibName:nil bundle:nil];
if (self)
{
[self setTitle:@"About"];
UIButton *settings = [[UIButton alloc] initWithFrame:CGRectMake(0., 0., 35., 35.)];
[settings setImage:[UIImage imageNamed:@"Settings"] forState:UIControlStateNormal];
[settings addTarget:self action:@selector(settings) forControlEvents:UIControlEventTouchUpInside];
[settings setUserInteractionEnabled:YES];
[settings setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithCustomView:settings];
[[self navigationItem] setLeftBarButtonItem:settingsButton];
UIButton *email = [[UIButton alloc] initWithFrame:CGRectMake(0., 0., 30., 19.)];
[email setImage:[UIImage imageNamed:@"Email"] forState:UIControlStateNormal];
[email addTarget:self action:@selector(emailDeveloper) forControlEvents:UIControlEventTouchUpInside];
[email setUserInteractionEnabled:YES];
[email setShowsTouchWhenHighlighted:YES];
[[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:email]];
}
return self;
}
#pragma mark - UIBarButtonSelectors
- (void)settings;
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
}
- (void)emailDeveloper;
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
[controller setMailComposeDelegate:self];
[controller setSubject:@"iBroke"];
[controller setModalPresentationStyle:UIModalPresentationFormSheet];
[controller setMessageBody:@"" isHTML:NO];
[controller setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
[controller setWantsFullScreenLayout:NO];
if (controller)
{
[[self navigationController] presentModalViewController:controller animated:YES];
}
}
else
{
NotificationView *cantSendEmail = [[NotificationView alloc] initWithFrame:CGRectZero
andMessage:kCantSendEmail
andType:kErrorNotification];
[cantSendEmail setNeedsLayout];
[[self view] addSubview:cantSendEmail];
[UIView animateWithDuration:3.0
animations: ^ {
[cantSendEmail setAlpha:0.0];
}
completion: ^ (BOOL completed) {
[cantSendEmail removeFromSuperview];
}
];
}
}
#pragma mark - Mail
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error;
{
[controller dismissModalViewControllerAnimated:YES];
NSString *message = @"";
NotificationType type = kSuccessNotification;
if (result == MFMailComposeResultCancelled)
{
message = [message stringByAppendingFormat:@"%@", kEmailCancelled];
}
else if (result == MFMailComposeResultSaved)
{
message = [message stringByAppendingFormat:@"%@", kEmailSaved];
}
else if (result == MFMailComposeResultSent)
{
message = [message stringByAppendingFormat:@"%@", kEmailSent];
}
else
{
message = [message stringByAppendingFormat:@"%@", kEmailFailed];
type = kErrorNotification;
}
NotificationView *sentEmail = [[NotificationView alloc] initWithFrame:CGRectZero
andMessage:message
andType:type];
[sentEmail setNeedsLayout];
[[self view] addSubview:sentEmail];
[UIView animateWithDuration:3.0
animations: ^ {
[sentEmail setAlpha:0.0];
}
completion: ^ (BOOL completed) {
[sentEmail removeFromSuperview];
}
];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - ViewLifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
_aboutView = [[AboutView alloc] initWithFrame:CGRectZero];
[self setView:_aboutView];
[super viewDidLoad];
}
- (void)viewDidUnload;
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end