Skip to content

Commit

Permalink
The report view now works correctly on iPad. Changes to the settings …
Browse files Browse the repository at this point in the history
…view.
  • Loading branch information
measuredweighed committed Feb 14, 2014
1 parent e299869 commit e3a3e34
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Diabetik.xcodeproj/project.pbxproj
Expand Up @@ -136,7 +136,7 @@
533F356D17736C5500AD89E2 /* UAIntroductionTooltipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 533F355817736C5500AD89E2 /* UAIntroductionTooltipView.m */; };
533F356E17736C5500AD89E2 /* UARemindersTooltipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 533F355A17736C5500AD89E2 /* UARemindersTooltipView.m */; };
534617531852828E00ED4B6D /* UASettingsTimelineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 534617521852828E00ED4B6D /* UASettingsTimelineViewController.m */; };
5354083917B7B90A008C64A4 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5354083817B7B90A008C64A4 /* StoreKit.framework */; };
5354083917B7B90A008C64A4 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5354083817B7B90A008C64A4 /* StoreKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
53561250185B9E3900438A91 /* UAReminderBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5356124F185B9E3900438A91 /* UAReminderBaseViewController.m */; };
535918A717809663008C16DD /* Diabetik_2_to_1.1.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 535918A617809663008C16DD /* Diabetik_2_to_1.1.xcmappingmodel */; };
537983AF17CD3F5A00032F3A /* UAShortcutButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 537983AE17CD3F5A00032F3A /* UAShortcutButton.m */; };
Expand Down
2 changes: 1 addition & 1 deletion Diabetik/Diabetik-Info.plist
Expand Up @@ -44,7 +44,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2141</string>
<string>2217</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIAppFonts</key>
Expand Down
1 change: 1 addition & 0 deletions Diabetik/UAAppDelegate.m
Expand Up @@ -68,6 +68,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[Appirater setUsesUntilPrompt:5];
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:1];
[Appirater setOpenInAppStore:NO];
[Appirater setDebug:NO];

// Is this a first run experience?
Expand Down
Expand Up @@ -53,7 +53,7 @@ - (void)viewDidLoad
if(!closeButton)
{
closeButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 50.0f, 0.0f, 50.0f, 50.0f)];
[closeButton setImage:[UIImage imageNamed:@"ChartCloseButton.png"] forState:UIControlStateNormal];
[closeButton setImage:[UIImage imageNamed:@"AddEntryModalCloseIconiPad"] forState:UIControlStateNormal];
[closeButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin];
[closeButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeButton];
Expand Down
68 changes: 51 additions & 17 deletions Diabetik/View Controllers/Reporting/UAReportsViewController.m
Expand Up @@ -53,6 +53,8 @@ - (id)initFromDate:(NSDate *)aFromDate toDate:(NSDate *)aToDate;
self = [super initWithNibName:nil bundle:nil];
if(self)
{
self.edgesForExtendedLayout = UIRectEdgeNone;

fromDate = aFromDate;
toDate = aToDate;
reportData = nil;
Expand All @@ -74,8 +76,8 @@ - (void)viewDidLoad
@{@"title": NSLocalizedString(@"Carbohydrate in-take", nil), @"description": NSLocalizedString(@"A stacked bar chart (segmented by morning, afternoon and evening) showing total carbohydrate in-take per day", nil), @"class": [UACarbsChartViewController class]},
@{@"title": NSLocalizedString(@"Healthy Glucose Tally", nil), @"description": NSLocalizedString(@"A pie chart showing the number of healthy glucose readings versus unhealthy over a given period", nil), @"class": [UAScatterChartViewController class]}
];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height)];

scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
Expand Down Expand Up @@ -132,16 +134,7 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

CGFloat x = 0.0f;
for(UIView *view in scrollView.subviews)
{
view.frame = CGRectMake(x + (self.view.bounds.size.width/2.0f - 300.0f/2.0f), self.view.bounds.size.height/2.0f - 151.0f/2.0f, 300.0f, 151.0f);

x += self.view.bounds.size.width;
}

scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*[reports count], self.view.bounds.size.height);
pageControl.frame = CGRectMake(0.0f, self.view.bounds.size.height - 55.0f, self.view.bounds.size.width, 25.0f);
[self layoutReports];

NSInteger reportKey = [[NSUserDefaults standardUserDefaults] integerForKey:kReportsDefaultKey];
if(reportKey < 0) reportKey = 0;
Expand Down Expand Up @@ -233,6 +226,20 @@ - (void)fetchReportData
}
}
}
- (void)layoutReports
{
CGFloat x = 0.0f;
for(UIView *view in scrollView.subviews)
{
view.frame = CGRectMake(x + (self.view.bounds.size.width/2.0f - 300.0f/2.0f), self.view.bounds.size.height/2.0f - 151.0f/2.0f, 300.0f, 151.0f);

x += self.view.bounds.size.width;
}

scrollView.frame = CGRectMake(0.0f, self.topLayoutGuide.length, self.view.bounds.size.width, self.view.bounds.size.height - self.topLayoutGuide.length);
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*[reports count], self.view.bounds.size.height);
pageControl.frame = CGRectMake(0.0f, self.view.bounds.size.height - 55.0f, self.view.bounds.size.width, 25.0f);
}
- (void)didSelectReport:(UIButton *)previewButton
{
[[VKRSAppSoundPlayer sharedInstance] playSound:@"tap-significant"];
Expand Down Expand Up @@ -327,15 +334,42 @@ - (NSUInteger)supportedInterfaceOrientations
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

if(UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
{
if([self.delegate shouldDismissReportsOnRotation:self])
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
{
[self dismissViewControllerAnimated:NO completion:^{
[self.delegate didDismissReportsController:self];
}];
if([self.delegate shouldDismissReportsOnRotation:self])
{
[self dismissViewControllerAnimated:NO completion:^{
[self.delegate didDismissReportsController:self];
}];
}
}
}
else
{
[UIView animateWithDuration:0.1 animations:^{
scrollView.alpha = 0.0f;
pageControl.alpha = 0.0f;
}];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[self layoutReports];
[scrollView setContentOffset:CGPointMake(self.view.bounds.size.width*pageControl.currentPage, 0.0f) animated:NO];

[UIView animateWithDuration:0.1 animations:^{
scrollView.alpha = 1.0f;
pageControl.alpha = 1.0f;
}];
}
}

#pragma mark - UIViewController methods
Expand Down
Expand Up @@ -51,6 +51,7 @@ - (id)initWithFrame:(CGRect)frame andDate:(NSDate *)date

_datePicker = [[UIDatePicker alloc] init];
_datePicker.backgroundColor = [UIColor whiteColor];
[_datePicker setClipsToBounds:YES];
[_datePicker setDatePickerMode:UIDatePickerModeDate];
[_datePicker setDate:date];
[_datePicker setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
Expand All @@ -69,25 +70,21 @@ - (id)initWithFrame:(CGRect)frame andDate:(NSDate *)date
[_containerView addSubview:_datePicker];
[_pickerView addSubview:_containerView];

UIView *pickerMaskView = [[UIImageView alloc] initWithImage:nil];//[UIImage imageNamed:@"ReportDatePickerBackground.png"]];
pickerMaskView.frame = CGRectMake(floorf(self.bounds.size.width/2.0f - 338.0f/2.0f), floorf(self.bounds.size.height/2.0f - 247.0f/2.0f), 338.0f, 247.0f);
pickerMaskView.backgroundColor = [UIColor whiteColor];
pickerMaskView.layer.cornerRadius = 5;
//[self.pickerView addSubview:pickerMaskView];

UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(floorf(pickerFrame.origin.x + 17.0f), floorf(pickerFrame.origin.y + pickerFrame.size.height - (41.0f + 19.0f)), 150.0f, 41.0f)];
[[cancelButton titleLabel] setFont:[UAFont standardMediumFontWithSize:19.0f]];
[cancelButton setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor colorWithRed:115.0f/255.0f green:115.0f/255.0f blue:115.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
[cancelButton setAdjustsImageWhenHighlighted:NO];
[cancelButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
[cancelButton setBackgroundColor:[UIColor whiteColor]];
[self.pickerView addSubview:cancelButton];

UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(floorf(pickerFrame.origin.x + pickerFrame.size.width - 150.0f - 17.0f), floorf(pickerFrame.origin.y + pickerFrame.size.height - (41.0f + 19.0f)), 150.0f, 41.0f)];
[[doneButton titleLabel] setFont:[UAFont standardMediumFontWithSize:19.0f]];
[doneButton setTitleColor:[UIColor colorWithRed:0.0f green:192.0f/255.0f blue:180.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
[doneButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(selectDate) forControlEvents:UIControlEventTouchUpInside];
[doneButton setBackgroundColor:[UIColor whiteColor]];
[self.pickerView addSubview:doneButton];
}
return self;
Expand Down
Expand Up @@ -23,6 +23,8 @@
#import "UASyncController.h"
#import "MBProgressHUD.h"

#import "UITextView+Extension.h"

@interface UASettingsAnalytikViewController ()
@property (nonatomic, strong) UITextField *usernameTextField, *passwordTextField;
@property (nonatomic, strong) UIView *headerView;
Expand Down Expand Up @@ -66,25 +68,48 @@ - (void)viewDidLoad
{
[super viewDidLoad];

self.headerView = [[UIView alloc] initWithFrame:CGRectZero];
self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
//self.headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.headerView.backgroundColor = [UIColor redColor];
self.headerView.backgroundColor = [UIColor clearColor];

self.headerInfoTextView = [[UITextView alloc] initWithFrame:CGRectZero];
self.headerInfoTextView.text = NSLocalizedString(@"Free personal diabetes analytics\n\nFind patterns in your blood sugar, better understand your diabetes and support research.\n\nSignup for an account at http://analytikhq.com", nil);
self.headerInfoTextView.text = NSLocalizedString(@"Analytik is a service that provides free personal diabetes analytics.\n\nFind patterns in your blood sugar, better understand your diabetes and support research.\n\nSignup for an account at http://analytikhq.com", nil);
self.headerInfoTextView.font = [UAFont standardRegularFontWithSize:16.0f];
self.headerInfoTextView.backgroundColor = [UIColor clearColor];
self.headerInfoTextView.editable = NO;
self.headerInfoTextView.scrollEnabled = NO;
self.headerInfoTextView.dataDetectorTypes = UIDataDetectorTypeLink;
[self.headerView addSubview:self.headerInfoTextView];

self.tableView.tableHeaderView = self.headerView;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
NSLog(@"Layout");

UIFont *font = [self.headerInfoTextView font];
int width = self.view.bounds.size.width, height = self.headerInfoTextView.bounds.size.height;

self.headerInfoTextView.contentInset = UIEdgeInsetsMake(0, 11.0f, 0, 11.0f);

NSMutableDictionary *atts = [[NSMutableDictionary alloc] init];
[atts setObject:font forKey:NSFontAttributeName];

self.headerView.frame = CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 125.0f);
self.headerInfoTextView.frame = CGRectMake(16.0f, 0.0f, self.view.bounds.size.width-32.0f, 125.0f);
CGRect rect = [self.headerInfoTextView.text boundingRectWithSize:CGSizeMake(width, height)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:atts
context:nil];


CGRect frame = self.headerInfoTextView.frame;
frame.size.width = self.view.bounds.size.width;
frame.size.height = rect.size.height + 40;
self.headerInfoTextView.frame = CGRectMake(0.0f, 10.0f, frame.size.width, frame.size.height);

self.headerView.frame = CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, self.headerInfoTextView.bounds.size.height);

self.tableView.tableHeaderView = self.headerView;

}
#pragma mark - Logic
Expand Down Expand Up @@ -242,19 +267,12 @@ - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInt
return NSLocalizedString(@"Options", nil);
}
}
else
{
if(section == 0)
{
return NSLocalizedString(@"Credentials", nil);
}
}

return @"";
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
if(self.isLoggedIn && section == 0)
{
return 40.0f;
}
Expand Down
Expand Up @@ -19,9 +19,11 @@
//

#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>

#import "UABaseViewController.h"
#import "UARemindersViewController.h"
#import "UAMediaController.h"

@interface UASettingsViewController : UABaseTableViewController <UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate>
@interface UASettingsViewController : UABaseTableViewController <UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate>
@end
66 changes: 53 additions & 13 deletions Diabetik/View Controllers/Settings/UASettingsViewController.m
Expand Up @@ -19,6 +19,7 @@
//

#import "UAAppDelegate.h"
#import "Appirater.h"

#import "UASettingsViewController.h"
#import "UASettingsEntryViewController.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSIntege
}
else if(section == 2)
{
return 2;
return 4;
}

return 3;
Expand Down Expand Up @@ -170,14 +171,6 @@ - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(
}
else if(indexPath.section == 1)
{
/*
if(indexPath.row == 0)
{
cell.imageView.image = [UIImage imageNamed:@"iCloudSmallIcon"];
cell.textLabel.text = NSLocalizedString(@"iCloud settings", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
*/
if(indexPath.row == 0)
{
cell.imageView.image = [UIImage imageNamed:@"diabetikSmallIcon"];
Expand All @@ -200,11 +193,21 @@ - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(
else if(indexPath.section == 2)
{
if(indexPath.row == 0)
{
cell.textLabel.text = NSLocalizedString(@"Need help? Contact support!", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else if(indexPath.row == 1)
{
cell.textLabel.text = [NSString stringWithFormat:@"%@ 😊", NSLocalizedString(@"Rate Diabetik in the App Store", nil)];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else if(indexPath.row == 2)
{
cell.textLabel.text = NSLocalizedString(@"Credits", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(indexPath.row == 1)
else if(indexPath.row == 3)
{
cell.textLabel.text = NSLocalizedString(@"Licenses", @"An option to view third-party software licenses used throughout the application");
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Expand Down Expand Up @@ -264,10 +267,30 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath
}
else if(indexPath.section == 2)
{
[aTableView deselectRowAtIndexPath:indexPath animated:YES];

if(indexPath.row == 0)
{
[aTableView deselectRowAtIndexPath:indexPath animated:YES];

if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setMailComposeDelegate:self];
[mailController setModalPresentationStyle:UIModalPresentationFormSheet];
[mailController setSubject:@"Diabetik Support"];
[mailController setToRecipients:@[@"support@diabetikapp.com"]];
[mailController setMessageBody:[NSString stringWithFormat:@"%@\n\n", NSLocalizedString(@"I need help with Diabetik! Here's the problem:", @"A default message shown to users when contacting support for help")] isHTML:NO];
if(mailController)
{
[self presentViewController:mailController animated:YES completion:nil];
}
}
}
else if(indexPath.row == 1)
{
[Appirater rateApp];
}
else if(indexPath.row == 2)
{
UAAppDelegate *appDelegate = (UAAppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *targetVC = appDelegate.viewController;

Expand All @@ -276,7 +299,7 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath
[modalView setContentView:introductionView];
[modalView present];
}
else if(indexPath.row == 1)
else if(indexPath.row == 3)
{
UASettingsLicensesViewController *vc = [[UASettingsLicensesViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
Expand All @@ -300,4 +323,21 @@ - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSInde
return YES;
}

#pragma mark - MFMailComposeViewDelegate methods
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Support email sent", nil)
message:NSLocalizedString(@"We've received your support request and will try to reply as soon as possible", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Okay", nil)
otherButtonTitles:nil];
[alertView show];
}

[self dismissViewControllerAnimated:YES completion:nil];
}
@end

0 comments on commit e3a3e34

Please sign in to comment.