Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
SettingsVC: added feedback button
Browse files Browse the repository at this point in the history
  • Loading branch information
dvor committed Sep 3, 2014
1 parent 3e23c43 commit 15689d4
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion Antidote/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "SettingsColorView.h"
#import "AppDelegate.h"
#import "NSString+Utilities.h"
#import "MFMailComposeViewController+BlocksKit.h"

@interface SettingsViewController () <UITextFieldDelegate, ToxIdViewDelegate, SettingsColorViewDelegate>

Expand All @@ -27,6 +28,8 @@ @interface SettingsViewController () <UITextFieldDelegate, ToxIdViewDelegate, Se

@property (strong, nonatomic) SettingsColorView *colorView;

@property (strong, nonatomic) UIButton *feedbackButton;

@end

@implementation SettingsViewController
Expand All @@ -53,6 +56,7 @@ - (void)loadView
[self createStatusMessageField];
[self createToxIdView];
[self createColorView];
[self createFeedbackButton];
}

- (void)viewDidLayoutSubviews
Expand All @@ -62,6 +66,32 @@ - (void)viewDidLayoutSubviews
[self adjustSubviews];
}

#pragma mark - Actions

- (void)feedbackButtonPressed
{
if (! [MFMailComposeViewController canSendMail]) {
[[[UIAlertView alloc] initWithTitle:nil
message:NSLocalizedString(@"Please configure your mail settings", @"Settings")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"Settings")
otherButtonTitles:nil] show];

return;
}

MFMailComposeViewController *vc = [MFMailComposeViewController new];
vc.navigationBar.tintColor = [AppearanceManager textMainColor];
[vc setSubject:@"Feedback"];
[vc setToRecipients:@[@"[email protected]"]];

vc.bk_completionBlock = ^(MFMailComposeViewController *vc, MFMailComposeResult result, NSError *error) {
[self dismissViewControllerAnimated:YES completion:nil];
};

[self presentViewController:vc animated:YES completion:nil];
}

#pragma mark - UITextFieldDelegate

- (BOOL) textField:(UITextField *)textField
Expand Down Expand Up @@ -177,11 +207,22 @@ - (void)createColorView
[self.scrollView addSubview:self.colorView];
}

- (void)createFeedbackButton
{
self.feedbackButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.feedbackButton setTitle:NSLocalizedString(@"Feedback", @"Settings") forState:UIControlStateNormal];
[self.feedbackButton addTarget:self
action:@selector(feedbackButtonPressed)
forControlEvents:UIControlEventTouchUpInside];

[self.scrollView addSubview:self.feedbackButton];
}

- (void)adjustSubviews
{
self.scrollView.frame = self.view.bounds;

CGFloat currentOriginY = 0.0;
__unused CGFloat currentOriginY = 0.0;
const CGFloat yIndentation = 10.0;

CGRect frame = CGRectZero;
Expand Down Expand Up @@ -224,6 +265,16 @@ - (void)adjustSubviews
}
currentOriginY = CGRectGetMaxY(frame);

{
[self.feedbackButton sizeToFit];
frame = self.feedbackButton.frame;
frame.origin.x = (self.view.frame.size.width - frame.size.width) / 2;
frame.origin.y = self.scrollView.frame.size.height - frame.size.height - yIndentation -
self.scrollView.contentInset.top - self.scrollView.contentInset.bottom;
self.feedbackButton.frame = frame;
}
currentOriginY = CGRectGetMaxY(frame);

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.origin.x, currentOriginY + yIndentation);
}

Expand Down

0 comments on commit 15689d4

Please sign in to comment.