final improvement

This commit is contained in:
opa334 2022-09-12 20:52:04 +02:00
parent d10c4cd52d
commit 3a8891991e
2 changed files with 21 additions and 10 deletions

View File

@ -4,6 +4,7 @@
{ {
UIImage* _placeholderIcon; UIImage* _placeholderIcon;
NSArray* _cachedAppPaths; NSArray* _cachedAppPaths;
NSMutableDictionary* _cachedIcons;
} }
@end @end

View File

@ -20,6 +20,7 @@
{ {
[self loadCachedAppPaths]; [self loadCachedAppPaths];
_placeholderIcon = [UIImage _applicationIconImageForBundleIdentifier:@"com.apple.WebSheet" format:10 scale:[UIScreen mainScreen].scale]; _placeholderIcon = [UIImage _applicationIconImageForBundleIdentifier:@"com.apple.WebSheet" format:10 scale:[UIScreen mainScreen].scale];
_cachedIcons = [NSMutableDictionary new];
} }
return self; return self;
} }
@ -132,22 +133,31 @@
// Configure the cell... // Configure the cell...
cell.textLabel.text = [[TSApplicationsManager sharedInstance] displayNameForAppPath:appPath]; cell.textLabel.text = [[TSApplicationsManager sharedInstance] displayNameForAppPath:appPath];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ • %@", appVersion, appId]; cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ • %@", appVersion, appId];
cell.imageView.image = _placeholderIcon;
cell.imageView.layer.borderWidth = 0.2; cell.imageView.layer.borderWidth = 0.2;
cell.imageView.layer.borderColor = [UIColor blackColor].CGColor; cell.imageView.layer.borderColor = [UIColor blackColor].CGColor;
cell.imageView.layer.cornerRadius = 13.8; cell.imageView.layer.cornerRadius = 13.8;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ UIImage* cachedIcon = _cachedIcons[appId];
if(cachedIcon)
{ {
//usleep(1000 * 5000); // (test delay for debugging) cell.imageView.image = cachedIcon;
UIImage* iconImage = [UIImage _applicationIconImageForBundleIdentifier:appId format:10 scale:[UIScreen mainScreen].scale]; }
dispatch_async(dispatch_get_main_queue(), ^{ else
if([tableView.indexPathsForVisibleRows containsObject:indexPath]) {
{ cell.imageView.image = _placeholderIcon;
cell.imageView.image = iconImage; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
} {
//usleep(1000 * 5000); // (test delay for debugging)
UIImage* iconImage = [UIImage _applicationIconImageForBundleIdentifier:appId format:10 scale:[UIScreen mainScreen].scale];
_cachedIcons[appId] = iconImage;
dispatch_async(dispatch_get_main_queue(), ^{
if([tableView.indexPathsForVisibleRows containsObject:indexPath])
{
cell.imageView.image = iconImage;
}
});
}); });
}); }
cell.preservesSuperviewLayoutMargins = NO; cell.preservesSuperviewLayoutMargins = NO;
cell.separatorInset = UIEdgeInsetsZero; cell.separatorInset = UIEdgeInsetsZero;