From 225e932fe70b2ece329e618fffe9557b6ab353f2 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 14 Jan 2016 10:03:30 -0500 Subject: [PATCH] Enable In-App purchase of TouchID feature and improved auto-height calculation of preferences and store table cells. --- MasterPassword/ObjC/MPAppDelegate_InApp.m | 2 +- MasterPassword/ObjC/MPEntities.m | 3 +- .../ObjC/iOS/MPPreferencesViewController.m | 15 +- .../ObjC/iOS/MPStoreViewController.m | 30 ++-- MasterPassword/ObjC/iOS/Storyboard.storyboard | 132 +++++++++--------- 5 files changed, 94 insertions(+), 88 deletions(-) diff --git a/MasterPassword/ObjC/MPAppDelegate_InApp.m b/MasterPassword/ObjC/MPAppDelegate_InApp.m index 9e50bd08..822ff2b7 100644 --- a/MasterPassword/ObjC/MPAppDelegate_InApp.m +++ b/MasterPassword/ObjC/MPAppDelegate_InApp.m @@ -36,7 +36,7 @@ PearlAssociatedObjectProperty( NSMutableArray*, ProductObservers, productObserve - (void)reloadProducts { SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: - [[NSSet alloc] initWithObjects:MPProductGenerateLogins, MPProductGenerateAnswers, MPProductFuel, nil]]; + [[NSSet alloc] initWithObjects:MPProductGenerateLogins, MPProductGenerateAnswers, MPProductTouchID, MPProductFuel, nil]]; productsRequest.delegate = self; [productsRequest start]; } diff --git a/MasterPassword/ObjC/MPEntities.m b/MasterPassword/ObjC/MPEntities.m index 6beba92a..fe4e2d22 100644 --- a/MasterPassword/ObjC/MPEntities.m +++ b/MasterPassword/ObjC/MPEntities.m @@ -9,6 +9,7 @@ #import "MPEntities.h" #import "MPAppDelegate_Shared.h" #import "MPAppDelegate_Key.h" +#import "MPAppDelegate_InApp.h" @implementation NSManagedObjectContext(MP) @@ -287,7 +288,7 @@ - (BOOL)touchID { - return [self.touchID_ boolValue]; + return [self.touchID_ boolValue] && ![[MPAppDelegate_Shared get] isFeatureUnlocked:MPProductTouchID]; } - (void)setTouchID:(BOOL)aTouchID { diff --git a/MasterPassword/ObjC/iOS/MPPreferencesViewController.m b/MasterPassword/ObjC/iOS/MPPreferencesViewController.m index 17958aaf..337d2da3 100644 --- a/MasterPassword/ObjC/iOS/MPPreferencesViewController.m +++ b/MasterPassword/ObjC/iOS/MPPreferencesViewController.m @@ -12,7 +12,7 @@ #import "MPAppDelegate_Store.h" #import "UIColor+Expanded.h" #import "MPPasswordsViewController.h" -#import "MPCoachmarkViewController.h" +#import "MPAppDelegate_InApp.h" @interface MPPreferencesViewController() @@ -25,6 +25,10 @@ [super viewDidLoad]; self.view.backgroundColor = [UIColor clearColor]; + + self.tableView.rowHeight = UITableViewAutomaticDimension; + self.tableView.estimatedRowHeight = 100; + self.tableView.contentInset = UIEdgeInsetsMake( 64, 0, 49, 0 ); } - (void)viewWillAppear:(BOOL)animated { @@ -35,8 +39,6 @@ if (![[NSUserDefaults standardUserDefaults] synchronize]) wrn( @"Couldn't synchronize after preferences appearance." ); - self.tableView.contentInset = UIEdgeInsetsMake( 64, 0, 49, 0 ); - [self reload]; } @@ -48,7 +50,7 @@ self.avatarImage.image = [UIImage imageNamed:strf( @"avatar-%lu", (unsigned long)activeUser.avatar )]; self.savePasswordSwitch.on = activeUser.saveKey; self.touchIDSwitch.on = activeUser.touchID; - self.touchIDSwitch.enabled = self.savePasswordSwitch.on; + self.touchIDSwitch.enabled = self.savePasswordSwitch.on && ![[MPiOSAppDelegate get] isFeatureUnlocked:MPProductTouchID]; } #pragma mark - UITableViewDelegate @@ -64,6 +66,11 @@ return cell; } +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + + return UITableViewAutomaticDimension; +} + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; diff --git a/MasterPassword/ObjC/iOS/MPStoreViewController.m b/MasterPassword/ObjC/iOS/MPStoreViewController.m index 3c1e136c..972c0d7b 100644 --- a/MasterPassword/ObjC/iOS/MPStoreViewController.m +++ b/MasterPassword/ObjC/iOS/MPStoreViewController.m @@ -51,6 +51,8 @@ PearlEnum( MPDevelopmentFuelConsumption, self.tableView.tableHeaderView = [UIView new]; self.tableView.tableFooterView = [UIView new]; + self.tableView.rowHeight = UITableViewAutomaticDimension; + self.tableView.estimatedRowHeight = 400; self.view.backgroundColor = [UIColor clearColor]; } @@ -89,17 +91,17 @@ PearlEnum( MPDevelopmentFuelConsumption, - (MPStoreProductCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MPStoreProductCell *cell = (MPStoreProductCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; - if (cell.contentView.translatesAutoresizingMaskIntoConstraints) { - cell.contentView.translatesAutoresizingMaskIntoConstraints = NO; - [cell addConstraints:@[ - [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual - toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:0], - [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual - toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1 constant:0], - [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual - toItem:cell.contentView attribute:NSLayoutAttributeLeft multiplier:1 constant:0], - ]]; - } +// if (cell.contentView.translatesAutoresizingMaskIntoConstraints) { +// cell.contentView.translatesAutoresizingMaskIntoConstraints = NO; +// [cell addConstraints:@[ +// [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual +// toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:0], +// [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual +// toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1 constant:0], +// [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual +// toItem:cell.contentView attribute:NSLayoutAttributeLeft multiplier:1 constant:0], +// ]]; +// } if (indexPath.section == 0) cell.selectionStyle = [[MPiOSAppDelegate get] isFeatureUnlocked:[self productForCell:cell].productIdentifier]? @@ -122,11 +124,7 @@ PearlEnum( MPDevelopmentFuelConsumption, - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; - [cell layoutIfNeeded]; - [cell layoutIfNeeded]; - - dbg_return_tr( cell.contentView.bounds.size.height, @, indexPath ); + return UITableViewAutomaticDimension; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/MasterPassword/ObjC/iOS/Storyboard.storyboard b/MasterPassword/ObjC/iOS/Storyboard.storyboard index aeaa733f..565f130e 100644 --- a/MasterPassword/ObjC/iOS/Storyboard.storyboard +++ b/MasterPassword/ObjC/iOS/Storyboard.storyboard @@ -689,7 +689,7 @@ - + @@ -698,21 +698,21 @@ - - + + - + - - - + + - + - - - + + - + - - - + + - + -