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];
dispatch_async(dispatch_get_main_queue(), ^{
if (animated) if (animated)
[UIView animateWithDuration:0.3f animations:^{ [UIView animateWithDuration:0.3f animations:^{
[self updateWasAnimated:animated]; [self updateWasAnimated:animated];
}]; }];
else else
[self updateWasAnimated:animated]; [self updateWasAnimated:animated];
});
} }
- (void)updateWasAnimated:(BOOL)animated { - (void)updateWasAnimated:(BOOL)animated {
@ -180,6 +172,8 @@
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];
self.contentField.text = @"";
if (self.activeElement.name && ![self.activeElement isDeleted])
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSString *description = [self.activeElement description]; NSString *description = [self.activeElement description];
@ -201,6 +195,7 @@
- (void)setHelpHidden:(BOOL)hidden animated:(BOOL)animated { - (void)setHelpHidden:(BOOL)hidden animated:(BOOL)animated {
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:animated? 0.3f: 0 animations:^{ [UIView animateWithDuration:animated? 0.3f: 0 animations:^{
if (hidden) { if (hidden) {
self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, self.view.bounds.size.height - 44); self.contentContainer.frame = CGRectSetHeight(self.contentContainer.frame, self.view.bounds.size.height - 44);
@ -212,6 +207,7 @@
[MPiOSConfig get].helpHidden = [NSNumber numberWithBool:NO]; [MPiOSConfig get].helpHidden = [NSNumber numberWithBool:NO];
} }
}]; }];
});
} }
- (void)setHelpChapter:(NSString *)chapter { - (void)setHelpChapter:(NSString *)chapter {
@ -220,6 +216,7 @@
[TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointHelpChapter, chapter]]; [TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointHelpChapter, chapter]];
#endif #endif
dispatch_async(dispatch_get_main_queue(), ^{
[self.helpView loadRequest: [self.helpView loadRequest:
[NSURLRequest requestWithURL: [NSURLRequest requestWithURL:
[NSURL URLWithString:[NSString stringWithFormat:@"#%@", chapter] relativeToURL: [NSURL URLWithString:[NSString stringWithFormat:@"#%@", chapter] relativeToURL:
@ -229,10 +226,12 @@
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 {
dispatch_async(dispatch_get_main_queue(), ^{
self.contentTipBody.text = message; self.contentTipBody.text = message;
icon.hidden = NO; icon.hidden = NO;
@ -251,10 +250,12 @@
}); });
} }
}]; }];
});
} }
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
dispatch_async(dispatch_get_main_queue(), ^{
self.alertTitle.text = title; self.alertTitle.text = title;
NSRange scrollRange = NSMakeRange(self.alertBody.text.length, message.length); NSRange scrollRange = NSMakeRange(self.alertBody.text.length, message.length);
if ([self.alertBody.text length]) if ([self.alertBody.text length])
@ -266,6 +267,7 @@
[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,6 +335,7 @@
[UIView animateWithDuration:0.3f animations:^{ [UIView animateWithDuration:0.3f animations:^{
self.alertContainer.alpha = 0; self.alertContainer.alpha = 0;
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
if (finished)
self.alertBody.text = nil; self.alertBody.text = nil;
}]; }];
@ -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;