From e6d21e1c1d891eb50b08b79851497912846261b7 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Mon, 13 Oct 2014 21:56:46 -0400 Subject: [PATCH] Add new question cells and fix sizing issue with store cells. [FIXED] Cell sizing of autosized the store cells. [IMPROVED] Add new question rows as soon as the last question row is used. --- .gitmodules | 6 ++++ External/Pearl | 2 +- External/jrswizzle | 1 + External/uicolor-utilities | 1 + .../ObjC/iOS/MPAnswersViewController.h | 2 +- .../ObjC/iOS/MPAnswersViewController.m | 22 +++++++++++-- MasterPassword/ObjC/iOS/MPAvatarCell.m | 10 +++++- .../ObjC/iOS/MPStoreViewController.m | 13 +++++--- .../ObjC/iOS/MPUsersViewController.h | 1 + .../ObjC/iOS/MPUsersViewController.m | 6 ++++ .../project.pbxproj | 10 +++--- MasterPassword/ObjC/iOS/Storyboard.storyboard | 32 +++++++++++-------- 12 files changed, 78 insertions(+), 28 deletions(-) create mode 160000 External/jrswizzle create mode 160000 External/uicolor-utilities diff --git a/.gitmodules b/.gitmodules index fb1fda92..fee07128 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,9 @@ [submodule "External/AttributedMarkdown"] path = External/AttributedMarkdown url = https://github.com/dreamwieber/AttributedMarkdown.git +[submodule "External/uicolor-utilities"] + path = External/uicolor-utilities + url = git://github.com/lhunath/uicolor-utilities.git +[submodule "External/jrswizzle"] + path = External/jrswizzle + url = git://github.com/jonmarimba/jrswizzle.git diff --git a/External/Pearl b/External/Pearl index c51961c1..1fbb8558 160000 --- a/External/Pearl +++ b/External/Pearl @@ -1 +1 @@ -Subproject commit c51961c161f571572fa1c83d84923e0f2f4b46ad +Subproject commit 1fbb8558f02c2fa36cf244ef1c085b33bad21843 diff --git a/External/jrswizzle b/External/jrswizzle new file mode 160000 index 00000000..98d18aee --- /dev/null +++ b/External/jrswizzle @@ -0,0 +1 @@ +Subproject commit 98d18aee73329321c320a2df85bacdb9f08a34a6 diff --git a/External/uicolor-utilities b/External/uicolor-utilities new file mode 160000 index 00000000..ae96212a --- /dev/null +++ b/External/uicolor-utilities @@ -0,0 +1 @@ +Subproject commit ae96212a4903a2b9e1df1e3542c9962f0d64a74b diff --git a/MasterPassword/ObjC/iOS/MPAnswersViewController.h b/MasterPassword/ObjC/iOS/MPAnswersViewController.h index 367039c4..19254684 100644 --- a/MasterPassword/ObjC/iOS/MPAnswersViewController.h +++ b/MasterPassword/ObjC/iOS/MPAnswersViewController.h @@ -41,6 +41,6 @@ @property(nonatomic) IBOutlet UITextField *questionField; @property(nonatomic) IBOutlet UITextField *answerField; -- (void)setQuestion:(MPSiteQuestionEntity *)question forSite:(MPSiteEntity *)site; +- (void)setQuestion:(MPSiteQuestionEntity *)question forSite:(MPSiteEntity *)site inVC:(MPAnswersViewController *)VC; @end diff --git a/MasterPassword/ObjC/iOS/MPAnswersViewController.m b/MasterPassword/ObjC/iOS/MPAnswersViewController.m index a7ac3ec0..a5d79095 100644 --- a/MasterPassword/ObjC/iOS/MPAnswersViewController.m +++ b/MasterPassword/ObjC/iOS/MPAnswersViewController.m @@ -118,7 +118,7 @@ MPSiteQuestionEntity *question = nil; if ([site.questions count] > indexPath.item) question = site.questions[indexPath.item]; - [cell setQuestion:question forSite:site]; + [cell setQuestion:question forSite:site inVC:self]; return cell; } @@ -217,6 +217,17 @@ } ); } +- (void)didAddQuestion:(MPSiteQuestionEntity *)question toSite:(MPSiteEntity *)site { + + NSUInteger newQuestionRow = [site.questions count]; + PearlMainQueue( ^{ + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:newQuestionRow inSection:1] ] + withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + } ); +} + @end @implementation MPGlobalAnswersCell @@ -247,14 +258,16 @@ @implementation MPAnswersQuestionCell { NSManagedObjectID *_siteOID; NSManagedObjectID *_questionOID; + __weak MPAnswersViewController *_answersVC; } #pragma mark - State -- (void)setQuestion:(MPSiteQuestionEntity *)question forSite:(MPSiteEntity *)site { +- (void)setQuestion:(MPSiteQuestionEntity *)question forSite:(MPSiteEntity *)site inVC:(MPAnswersViewController *)answersVC { _siteOID = site.objectID; _questionOID = question.objectID; + _answersVC = answersVC; [self updateAnswerForQuestion:question ofSite:site]; } @@ -272,9 +285,11 @@ NSString *keyword = textField.text; [MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) { + BOOL didAddQuestionObject = NO; MPSiteEntity *site = [MPSiteEntity existingObjectWithID:_siteOID inContext:context]; MPSiteQuestionEntity *question = [MPSiteQuestionEntity existingObjectWithID:_questionOID inContext:context]; if (!question) { + didAddQuestionObject = YES; [site addQuestionsObject:question = [MPSiteQuestionEntity insertNewObjectInContext:context]]; question.site = site; } @@ -291,6 +306,9 @@ _questionOID = question.objectID; [self updateAnswerForQuestion:question ofSite:site]; + + if (didAddQuestionObject) + [_answersVC didAddQuestion:question toSite:site]; } }]; } diff --git a/MasterPassword/ObjC/iOS/MPAvatarCell.m b/MasterPassword/ObjC/iOS/MPAvatarCell.m index 5a32aa56..47acf2aa 100644 --- a/MasterPassword/ObjC/iOS/MPAvatarCell.m +++ b/MasterPassword/ObjC/iOS/MPAvatarCell.m @@ -30,6 +30,7 @@ const long MPAvatarAdd = 10000; @property(strong, nonatomic) IBOutlet NSLayoutConstraint *avatarSizeConstraint; @property(strong, nonatomic) IBOutlet NSLayoutConstraint *avatarToTopConstraint; @property(strong, nonatomic) IBOutlet NSLayoutConstraint *avatarRaisedConstraint; +@property(strong, nonatomic) IBOutlet NSLayoutConstraint *keyboardHeightConstraint; @end @@ -66,6 +67,12 @@ const long MPAvatarAdd = 10000; [self observeKeyPath:@"highlighted" withBlock:^(id from, id to, NSKeyValueChange cause, MPAvatarCell *_self) { [_self updateAnimated:_self.superview != nil]; }]; + PearlAddNotificationObserver( UIKeyboardWillShowNotification, nil, [NSOperationQueue mainQueue], + ^(MPAvatarCell *self, NSNotification *note) { + CGRect keyboardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGFloat keyboardHeight = CGRectGetHeight( self.window.screen.bounds ) - CGRectGetMinY( keyboardRect ); + [self.keyboardHeightConstraint updateConstant:keyboardHeight]; + } ); CABasicAnimation *toShadowOpacityAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; toShadowOpacityAnimation.toValue = @0.2f; @@ -99,6 +106,7 @@ const long MPAvatarAdd = 10000; - (void)dealloc { [self removeKeyPathObservers]; + PearlRemoveNotificationObservers(); } #pragma mark - Properties @@ -264,7 +272,7 @@ const long MPAvatarAdd = 10000; case MPAvatarModeRaisedAndMinimized: { [self.avatarSizeConstraint updateConstant:36]; [self.avatarRaisedConstraint updatePriority:UILayoutPriorityDefaultLow]; - [self.avatarToTopConstraint updatePriority:UILayoutPriorityDefaultHigh]; + [self.avatarToTopConstraint updatePriority:UILayoutPriorityDefaultHigh + 2]; [self.nameToCenterConstraint updatePriority:UILayoutPriorityDefaultHigh]; self.nameContainer.alpha = 0; self.nameContainer.backgroundColor = [UIColor blackColor]; diff --git a/MasterPassword/ObjC/iOS/MPStoreViewController.m b/MasterPassword/ObjC/iOS/MPStoreViewController.m index 91789e5f..43aa1f66 100644 --- a/MasterPassword/ObjC/iOS/MPStoreViewController.m +++ b/MasterPassword/ObjC/iOS/MPStoreViewController.m @@ -89,9 +89,14 @@ PearlEnum( MPDevelopmentFuelConsumption, MPStoreProductCell *cell = (MPStoreProductCell *)[super tableView:tableView cellForRowAtIndexPath:indexPath]; if (cell.contentView.translatesAutoresizingMaskIntoConstraints) { cell.contentView.translatesAutoresizingMaskIntoConstraints = NO; - [cell addConstraint: - [NSLayoutConstraint constraintWithItem:cell attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual - toItem:cell.contentView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]]; + [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) @@ -119,7 +124,7 @@ PearlEnum( MPDevelopmentFuelConsumption, [cell layoutIfNeeded]; [cell layoutIfNeeded]; - dbg_return_tr( cell.contentView.bounds.size.height, @ ); + dbg_return_tr( cell.contentView.bounds.size.height, @, indexPath ); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/MasterPassword/ObjC/iOS/MPUsersViewController.h b/MasterPassword/ObjC/iOS/MPUsersViewController.h index 1c3de39e..be5a3d02 100644 --- a/MasterPassword/ObjC/iOS/MPUsersViewController.h +++ b/MasterPassword/ObjC/iOS/MPUsersViewController.h @@ -34,6 +34,7 @@ @property(weak, nonatomic) IBOutlet UIView *thanksTipContainer; @property(weak, nonatomic) IBOutlet UIButton *nextAvatarButton; @property(weak, nonatomic) IBOutlet UIButton *previousAvatarButton; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *keyboardHeightConstraint; @property(assign, nonatomic, readonly) BOOL active; diff --git a/MasterPassword/ObjC/iOS/MPUsersViewController.m b/MasterPassword/ObjC/iOS/MPUsersViewController.m index 898a3424..c6cf6069 100644 --- a/MasterPassword/ObjC/iOS/MPUsersViewController.m +++ b/MasterPassword/ObjC/iOS/MPUsersViewController.m @@ -649,6 +649,12 @@ referenceSizeForFooterInSection:(NSInteger)section { self.userSelectionContainer.alpha = 1; }]; } ); + PearlAddNotificationObserver( UIKeyboardWillShowNotification, nil, [NSOperationQueue mainQueue], + ^(MPUsersViewController *self, NSNotification *note) { + CGRect keyboardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGFloat keyboardHeight = CGRectGetHeight( self.view.window.screen.bounds ) - CGRectGetMinY( keyboardRect ); + [self.keyboardHeightConstraint updateConstant:keyboardHeight]; + } ); NSManagedObjectContext *mainContext = [MPiOSAppDelegate managedObjectContextForMainThreadIfReady]; [UIView animateWithDuration:0.3f animations:^{ diff --git a/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj b/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj index 03970b90..09747633 100644 --- a/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj +++ b/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj @@ -2599,8 +2599,6 @@ DAFE45FC15039823003ABA7C /* Pearl-Crypto */, DAFE460715039823003ABA7C /* Pearl-UIKit */, DAC77CB1148291A600BCF976 /* Pearl-Prefix.pch */, - DACA29751705E2BD002C6C22 /* jrswizzle */, - DACA29B41705E2DE002C6C22 /* uicolor-utilities */, ); path = Pearl; sourceTree = ""; @@ -2612,6 +2610,8 @@ DA32D03719D111EB004F3F0E /* KCOrderedAccessorFix */, DAA141181922FED80032B392 /* iOS */, DAFC5662172C57EC00CB5CC5 /* InAppSettingsKit */, + DACA29751705E2BD002C6C22 /* jrswizzle */, + DACA29B41705E2DE002C6C22 /* uicolor-utilities */, DAC77CAF148291A600BCF976 /* Pearl */, ); name = External; @@ -2653,8 +2653,7 @@ DACA29771705E2BD002C6C22 /* JRSwizzle.h */, DACA298C1705E2BD002C6C22 /* JRSwizzle.m */, ); - name = jrswizzle; - path = External/jrswizzle; + path = jrswizzle; sourceTree = ""; }; DACA29B41705E2DE002C6C22 /* uicolor-utilities */ = { @@ -2665,8 +2664,7 @@ DACA29BA1705E2DE002C6C22 /* UIColor+Expanded.m */, DACA29BB1705E2DE002C6C22 /* UIColor+HSV.m */, ); - name = "uicolor-utilities"; - path = "External/uicolor-utilities"; + path = "uicolor-utilities"; sourceTree = ""; }; DAFC5662172C57EC00CB5CC5 /* InAppSettingsKit */ = { diff --git a/MasterPassword/ObjC/iOS/Storyboard.storyboard b/MasterPassword/ObjC/iOS/Storyboard.storyboard index 2e2b8bf5..1a1aa4cd 100644 --- a/MasterPassword/ObjC/iOS/Storyboard.storyboard +++ b/MasterPassword/ObjC/iOS/Storyboard.storyboard @@ -133,7 +133,6 @@ - @@ -173,10 +172,10 @@ - + - - + + @@ -184,7 +183,7 @@ - + - + @@ -218,16 +217,18 @@ + - + + @@ -460,9 +461,11 @@ - + + + @@ -470,6 +473,7 @@ + @@ -486,9 +490,9 @@ - + - + @@ -506,6 +510,7 @@ + @@ -2809,7 +2814,7 @@ See - + @@ -2823,12 +2828,13 @@ See