2
0

Move a few batches of UI work into the main thread.

This commit is contained in:
Maarten Billemont 2016-07-21 09:59:37 -04:00
parent fa588f8fe2
commit 1977a423a5

View File

@ -91,13 +91,15 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) {
[MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) { [MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserInContext:context]; MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserInContext:context];
if (![MPAlgorithmDefault tryMigrateUser:activeUser inContext:context]) if (![MPAlgorithmDefault tryMigrateUser:activeUser inContext:context])
[self performSegueWithIdentifier:@"message" sender: PearlMainQueue(^{
[MPMessage messageWithTitle:@"You have sites that can be upgraded." text: [self performSegueWithIdentifier:@"message" sender:
@"Upgrading a site allows it to take advantage of the latest improvements in the Master Password algorithm.\n\n" [MPMessage messageWithTitle:@"You have sites that can be upgraded." text:
"When you upgrade a site, a new and stronger password will be generated for it. To upgrade a site, first log into the site, navigate to your account preferences where you can change the site's password. Make sure you fill in any \"current password\" fields on the website first, then press the upgrade button here to get your new site password.\n\n" @"Upgrading a site allows it to take advantage of the latest improvements in the Master Password algorithm.\n\n"
"You can then update your site's account with the new and stronger password.\n\n" "When you upgrade a site, a new and stronger password will be generated for it. To upgrade a site, first log into the site, navigate to your account preferences where you can change the site's password. Make sure you fill in any \"current password\" fields on the website first, then press the upgrade button here to get your new site password.\n\n"
"The upgrade button can be found in the site's settings and looks like this:" "You can then update your site's account with the new and stronger password.\n\n"
info:YES]]; "The upgrade button can be found in the site's settings and looks like this:"
info:YES]];
});
[context saveToStore]; [context saveToStore];
}]; }];
} }
@ -417,36 +419,38 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) {
if (![self.fetchedResultsController performFetch:&error]) if (![self.fetchedResultsController performFetch:&error])
err( @"Couldn't fetch sites: %@", [error fullDescription] ); err( @"Couldn't fetch sites: %@", [error fullDescription] );
@try { PearlMainQueue(^{
[self.passwordCollectionView performBatchUpdates:^{ @try {
[self fetchedItemsDidUpdate]; [self.passwordCollectionView performBatchUpdates:^{
[self fetchedItemsDidUpdate];
NSInteger fromSections = self.passwordCollectionView.numberOfSections; NSInteger fromSections = self.passwordCollectionView.numberOfSections;
NSInteger toSections = [self numberOfSectionsInCollectionView:self.passwordCollectionView]; NSInteger toSections = [self numberOfSectionsInCollectionView:self.passwordCollectionView];
for (NSInteger section = 0; section < MAX( toSections, fromSections ); ++section) { for (NSInteger section = 0; section < MAX( toSections, fromSections ); ++section) {
if (section >= fromSections) if (section >= fromSections)
[self.passwordCollectionView insertSections:[NSIndexSet indexSetWithIndex:section]]; [self.passwordCollectionView insertSections:[NSIndexSet indexSetWithIndex:section]];
else if (section >= toSections) else if (section >= toSections)
[self.passwordCollectionView deleteSections:[NSIndexSet indexSetWithIndex:section]]; [self.passwordCollectionView deleteSections:[NSIndexSet indexSetWithIndex:section]];
else if (section < [oldSections count]) else if (section < [oldSections count])
[self.passwordCollectionView reloadItemsFromArray:oldSections[section] [self.passwordCollectionView reloadItemsFromArray:oldSections[section]
toArray:[[self.fetchedResultsController sections][section] objects] toArray:[[self.fetchedResultsController sections][section] objects]
inSection:section]; inSection:section];
else else
[self.passwordCollectionView reloadSections:[NSIndexSet indexSetWithIndex:section]]; [self.passwordCollectionView reloadSections:[NSIndexSet indexSetWithIndex:section]];
} }
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
if (finished) if (finished)
[self.passwordCollectionView setContentOffset:CGPointMake( 0, -self.passwordCollectionView.contentInset.top ) [self.passwordCollectionView setContentOffset:CGPointMake( 0, -self.passwordCollectionView.contentInset.top )
animated:YES]; animated:YES];
for (MPPasswordCell *cell in self.passwordCollectionView.visibleCells) for (MPPasswordCell *cell in self.passwordCollectionView.visibleCells)
[cell setFuzzyGroups:_fuzzyGroups]; [cell setFuzzyGroups:_fuzzyGroups];
}]; }];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
wrn( @"While updating password cells: %@", [exception fullDescription] ); wrn( @"While updating password cells: %@", [exception fullDescription] );
[self.passwordCollectionView reloadData]; [self.passwordCollectionView reloadData];
} }
});
}]; }];
} }