From 54f2c5b7be4f5570c40a1941f87abbf84142227a Mon Sep 17 00:00:00 2001 From: tylinux Date: Mon, 12 Sep 2022 15:06:07 +0800 Subject: [PATCH] Let App list show icon and version --- Store/TSAppTableViewController.m | 24 +++++++++++++++++++----- Store/TSApplicationsManager.h | 1 + Store/TSApplicationsManager.m | 5 +++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Store/TSAppTableViewController.m b/Store/TSAppTableViewController.m index cb466e8..ba96855 100644 --- a/Store/TSAppTableViewController.m +++ b/Store/TSAppTableViewController.m @@ -2,6 +2,10 @@ #import "TSApplicationsManager.h" +@interface UIImage () ++ (UIImage *)_applicationIconImageForBundleIdentifier:(NSString *)id format:(NSInteger)format scale:(double)scale; +@end + @implementation TSAppTableViewController - (void)reloadTable @@ -15,7 +19,6 @@ - (void)loadView { [super loadView]; - [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"ApplicationCell"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTable) name:@"ApplicationsChanged" @@ -81,16 +84,27 @@ } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApplicationCell" forIndexPath:indexPath]; - + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ApplicationCell"]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ApplicationCell"]; + } + NSString* appPath = [[TSApplicationsManager sharedInstance] installedAppPaths][indexPath.row]; - + NSString* appId = [[TSApplicationsManager sharedInstance] appIdForAppPath:appPath]; + NSString* appVersion = [[TSApplicationsManager sharedInstance] versionStringForAppPath:appPath]; + // Configure the cell... cell.textLabel.text = [[TSApplicationsManager sharedInstance] displayNameForAppPath:appPath]; - + cell.detailTextLabel.text = appVersion; + cell.imageView.image = [UIImage _applicationIconImageForBundleIdentifier:appId format:10 scale:2.0]; + return cell; } +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return 80.0f; +} + - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if(editingStyle == UITableViewCellEditingStyleDelete) diff --git a/Store/TSApplicationsManager.h b/Store/TSApplicationsManager.h index ac37385..8b84227 100644 --- a/Store/TSApplicationsManager.h +++ b/Store/TSApplicationsManager.h @@ -12,6 +12,7 @@ - (NSDictionary*)infoDictionaryForAppPath:(NSString*)appPath; - (NSString*)appIdForAppPath:(NSString*)appPath; - (NSString*)displayNameForAppPath:(NSString*)appPath; +- (NSString*)versionStringForAppPath:(NSString*)appPath; - (NSError*)errorForCode:(int)code; - (int)installIpa:(NSString*)pathToIpa force:(BOOL)force log:(NSString**)logOut; diff --git a/Store/TSApplicationsManager.m b/Store/TSApplicationsManager.m index 9ac0f79..2ae492f 100644 --- a/Store/TSApplicationsManager.m +++ b/Store/TSApplicationsManager.m @@ -57,6 +57,11 @@ return displayName; } +- (NSString*)versionStringForAppPath:(NSString*)appPath +{ + return [self infoDictionaryForAppPath:appPath][@"CFBundleShortVersionString"]; +} + - (NSError*)errorForCode:(int)code { NSString* errorDescription = @"Unknown Error";