Skip to content

Commit

Permalink
final improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Sep 12, 2022
1 parent d10c4cd commit 3a88919
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions Store/TSAppTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
UIImage* _placeholderIcon;
NSArray* _cachedAppPaths;
NSMutableDictionary* _cachedIcons;
}

@end
30 changes: 20 additions & 10 deletions Store/TSAppTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (instancetype)init
{
[self loadCachedAppPaths];
_placeholderIcon = [UIImage _applicationIconImageForBundleIdentifier:@"com.apple.WebSheet" format:10 scale:[UIScreen mainScreen].scale];
_cachedIcons = [NSMutableDictionary new];
}
return self;
}
Expand Down Expand Up @@ -132,22 +133,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
// Configure the cell...
cell.textLabel.text = [[TSApplicationsManager sharedInstance] displayNameForAppPath:appPath];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@", appVersion, appId];
cell.imageView.image = _placeholderIcon;
cell.imageView.layer.borderWidth = 0.2;
cell.imageView.layer.borderColor = [UIColor blackColor].CGColor;
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)
UIImage* iconImage = [UIImage _applicationIconImageForBundleIdentifier:appId format:10 scale:[UIScreen mainScreen].scale];
dispatch_async(dispatch_get_main_queue(), ^{
if([tableView.indexPathsForVisibleRows containsObject:indexPath])
{
cell.imageView.image = iconImage;
}
cell.imageView.image = cachedIcon;
}
else
{
cell.imageView.image = _placeholderIcon;
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.separatorInset = UIEdgeInsetsZero;
Expand Down

0 comments on commit 3a88919

Please sign in to comment.