2
0

Fix some UI issues, mostly with alerts.

[FIXED]     Schedule all UI-changing methods on the main thread.  Fixes
            some UI bugs.
[FIXED]     Attempt to calculate password for deleted element.
[FIXED]     MP-6: Close open alert when switching sites.
[FIXED]     MP-7: Remind user to change site's password when creating a
            new site.
This commit is contained in:
Maarten Billemont 2012-03-11 11:14:28 +01:00
parent fa3680f9c4
commit 0c536ef640
5 changed files with 95 additions and 78 deletions

View File

@ -57,6 +57,11 @@
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions> <AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction

View File

@ -19,6 +19,6 @@
@property (nonatomic, assign) NSTimeInterval lastUsed; @property (nonatomic, assign) NSTimeInterval lastUsed;
@property (nonatomic, retain, readonly) id content; @property (nonatomic, retain, readonly) id content;
- (void)use; - (int16_t)use;
@end @end

View File

@ -17,10 +17,10 @@
@dynamic uses; @dynamic uses;
@dynamic lastUsed; @dynamic lastUsed;
- (void)use { - (int16_t)use {
++self.uses;
self.lastUsed = [[NSDate date] timeIntervalSinceReferenceDate]; self.lastUsed = [[NSDate date] timeIntervalSinceReferenceDate];
return ++self.uses;
} }
- (id)content { - (id)content {

View File

@ -27,7 +27,7 @@
[MPiOSConfig get]; [MPiOSConfig get];
#ifdef DEBUG #ifdef DEBUG
[PearlLogger get].autoprintLevel = PearlLogLevelTrace; [PearlLogger get].autoprintLevel = PearlLogLevelDebug;
[NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)]; [NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)];
#endif #endif
} }

View File

@ -109,17 +109,7 @@
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:[NSOperationQueue mainQueue] [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) { usingBlock:^(NSNotification *note) {
if (![MPAppDelegate get].key) { self.activeElement = nil;
self.activeElement = nil;
[self updateAnimated:NO];
}
}];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
if (![MPAppDelegate get].key) {
self.activeElement = nil;
[self updateAnimated:NO];
}
}]; }];
self.alertBody.text = nil; self.alertBody.text = nil;
@ -154,12 +144,14 @@
[[MPAppDelegate get] saveContext]; [[MPAppDelegate get] saveContext];
if (animated) dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.3f animations:^{ if (animated)
[UIView animateWithDuration:0.3f animations:^{
[self updateWasAnimated:animated];
}];
else
[self updateWasAnimated:animated]; [self updateWasAnimated:animated];
}]; });
else
[self updateWasAnimated:animated];
} }
- (void)updateWasAnimated:(BOOL)animated { - (void)updateWasAnimated:(BOOL)animated {
@ -180,13 +172,15 @@
if ([self.activeElement isKindOfClass:[MPElementGeneratedEntity class]]) if ([self.activeElement isKindOfClass:[MPElementGeneratedEntity class]])
self.passwordCounter.text = [NSString stringWithFormat:@"%u", ((MPElementGeneratedEntity *) self.activeElement).counter]; self.passwordCounter.text = [NSString stringWithFormat:@"%u", ((MPElementGeneratedEntity *) self.activeElement).counter];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ self.contentField.text = @"";
NSString *description = [self.activeElement description]; if (self.activeElement.name && ![self.activeElement isDeleted])
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSString *description = [self.activeElement description];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
self.contentField.text = description; self.contentField.text = description;
});
}); });
});
} }
- (BOOL)isHelpVisible { - (BOOL)isHelpVisible {
@ -201,17 +195,19 @@
- (void)setHelpHidden:(BOOL)hidden animated:(BOOL)animated { - (void)setHelpHidden:(BOOL)hidden animated:(BOOL)animated {
[UIView animateWithDuration:animated? 0.3f: 0 animations:^{ dispatch_async(dispatch_get_main_queue(), ^{
if (hidden) { [UIView animateWithDuration:animated? 0.3f: 0 animations:^{
self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, self.view.bounds.size.height - 44); if (hidden) {
self.helpContainer.frame = CGRectSetY(self.helpContainer.frame, self.view.bounds.size.height); self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, self.view.bounds.size.height - 44);
[MPiOSConfig get].helpHidden = [NSNumber numberWithBool:YES]; self.helpContainer.frame = CGRectSetY(self.helpContainer.frame, self.view.bounds.size.height);
} else { [MPiOSConfig get].helpHidden = [NSNumber numberWithBool:YES];
self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, 175); } else {
self.helpContainer.frame = CGRectSetY(self.helpContainer.frame, 216); self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, 175);
[MPiOSConfig get].helpHidden = [NSNumber numberWithBool:NO]; self.helpContainer.frame = CGRectSetY(self.helpContainer.frame, 216);
} [MPiOSConfig get].helpHidden = [NSNumber numberWithBool:NO];
}]; }
}];
});
} }
- (void)setHelpChapter:(NSString *)chapter { - (void)setHelpChapter:(NSString *)chapter {
@ -220,52 +216,58 @@
[TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointHelpChapter, chapter]]; [TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointHelpChapter, chapter]];
#endif #endif
[self.helpView loadRequest: dispatch_async(dispatch_get_main_queue(), ^{
[NSURLRequest requestWithURL: [self.helpView loadRequest:
[NSURL URLWithString:[NSString stringWithFormat:@"#%@", chapter] relativeToURL: [NSURLRequest requestWithURL:
[[NSBundle mainBundle] URLForResource:@"help" withExtension:@"html"]]]]; [NSURL URLWithString:[NSString stringWithFormat:@"#%@", chapter] relativeToURL:
[[NSBundle mainBundle] URLForResource:@"help" withExtension:@"html"]]]];
NSString *error = [self.helpView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setClass('%@');", NSString *error = [self.helpView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setClass('%@');",
ClassNameFromMPElementType(self.activeElement.type)]]; ClassNameFromMPElementType(self.activeElement.type)]];
if (error.length) if (error.length)
err(@"setClass: %@", error); err(@"setClass: %@", error);
});
} }
- (void)showContentTip:(NSString *)message withIcon:(UIImageView *)icon { - (void)showContentTip:(NSString *)message withIcon:(UIImageView *)icon {
self.contentTipBody.text = message; dispatch_async(dispatch_get_main_queue(), ^{
self.contentTipBody.text = message;
icon.hidden = NO; icon.hidden = NO;
[UIView animateWithDuration:0.2f animations:^{ [UIView animateWithDuration:0.2f animations:^{
self.contentTipContainer.alpha = 1; self.contentTipContainer.alpha = 1;
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
if (finished) { if (finished) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC); dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:0.2f animations:^{ [UIView animateWithDuration:0.2f animations:^{
self.contentTipContainer.alpha = 0; self.contentTipContainer.alpha = 0;
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
if (finished) if (finished)
icon.hidden = YES; icon.hidden = YES;
}]; }];
}); });
} }
}]; }];
});
} }
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
self.alertTitle.text = title; dispatch_async(dispatch_get_main_queue(), ^{
NSRange scrollRange = NSMakeRange(self.alertBody.text.length, message.length); self.alertTitle.text = title;
if ([self.alertBody.text length]) NSRange scrollRange = NSMakeRange(self.alertBody.text.length, message.length);
self.alertBody.text = [NSString stringWithFormat:@"%@\n\n---\n\n%@", self.alertBody.text, message]; if ([self.alertBody.text length])
else self.alertBody.text = [NSString stringWithFormat:@"%@\n\n---\n\n%@", self.alertBody.text, message];
self.alertBody.text = message; else
[self.alertBody scrollRangeToVisible:scrollRange]; self.alertBody.text = message;
[self.alertBody scrollRangeToVisible:scrollRange];
[UIView animateWithDuration:0.2f animations:^{ [UIView animateWithDuration:0.2f animations:^{
self.alertContainer.alpha = 1; self.alertContainer.alpha = 1;
}]; }];
});
} }
#pragma mark - Protocols #pragma mark - Protocols
@ -333,7 +335,8 @@
[UIView animateWithDuration:0.3f animations:^{ [UIView animateWithDuration:0.3f animations:^{
self.alertContainer.alpha = 0; self.alertContainer.alpha = 0;
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
self.alertBody.text = nil; if (finished)
self.alertBody.text = nil;
}]; }];
#ifdef TESTFLIGHT #ifdef TESTFLIGHT
@ -429,9 +432,18 @@
- (void)didSelectElement:(MPElementEntity *)element { - (void)didSelectElement:(MPElementEntity *)element {
[self closeAlert];
if (element) { if (element) {
self.activeElement = element; self.activeElement = element;
[self.activeElement use]; if ([self.activeElement use] == 1)
[self showAlertWithTitle:@"New Site" message:
l(@"You've just created a password for %@.\n\n"
@"IMPORTANT:\n"
@"Don't forget to set or change the password for your account at %@ to the password above. "
@"It's best to do this right away. If you forget it, may get confusing later on "
@"to remember what password you need to use for logging into the site.",
self.activeElement.name, self.activeElement.name)];
[self.searchDisplayController setActive:NO animated:YES]; [self.searchDisplayController setActive:NO animated:YES];
self.searchDisplayController.searchBar.text = self.activeElement.name; self.searchDisplayController.searchBar.text = self.activeElement.name;