diff --git a/AppSales.xcodeproj/project.pbxproj b/AppSales.xcodeproj/project.pbxproj index 4eb82bd6..f3c22be7 100644 --- a/AppSales.xcodeproj/project.pbxproj +++ b/AppSales.xcodeproj/project.pbxproj @@ -717,7 +717,7 @@ 7F709D3D13BC98860008DBAD /* AppSalesAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppSalesAppDelegate.m; sourceTree = ""; }; 7F709D4013BC98860008DBAD /* AppSales.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AppSales.xcdatamodel; sourceTree = ""; }; 7F709D4513BC98860008DBAD /* AccountsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AccountsViewController.h; sourceTree = ""; }; - 7F709D4613BC98860008DBAD /* AccountsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccountsViewController.m; sourceTree = ""; }; + 7F709D4613BC98860008DBAD /* AccountsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AccountsViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 7F709D6113BCB64E0008DBAD /* FieldEditorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FieldEditorViewController.h; sourceTree = ""; }; 7F709D6213BCB64F0008DBAD /* FieldEditorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FieldEditorViewController.m; sourceTree = ""; }; 7F709D6A13BCC3C80008DBAD /* SSKeychain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSKeychain.h; sourceTree = ""; }; diff --git a/Classes/AccountsViewController.m b/Classes/AccountsViewController.m index ca4e02b5..d7a97775 100644 --- a/Classes/AccountsViewController.m +++ b/Classes/AccountsViewController.m @@ -23,6 +23,7 @@ #import "KKPasscodeLock.h" #import "ZipFile.h" #import "ZipWriteStream.h" +#import "IconManager.h" #define kAddNewAccountEditorIdentifier @"AddNewAccountEditorIdentifier" #define kEditAccountEditorIdentifier @"EditAccountEditorIdentifier" @@ -67,6 +68,8 @@ - (void)viewDidLoad [[ReportDownloadCoordinator sharedReportDownloadCoordinator] addObserver:self forKeyPath:@"isBusy" options:NSKeyValueObservingOptionNew context:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iconCleared:) name:IconManagerClearedIconNotification object:nil]; + [self reloadAccounts]; } @@ -329,7 +332,8 @@ - (void)editAccount:(ASAccount *)account for (Product *product in allProducts) { FieldSpecifier *productNameField = [FieldSpecifier textFieldWithKey:[NSString stringWithFormat:@"product.name.%@", product.productID] title:NSLocalizedString(@"Name", nil) defaultValue:[product displayName]]; FieldSpecifier *hideProductField = [FieldSpecifier switchFieldWithKey:[NSString stringWithFormat:@"product.hidden.%@", product.productID] title:NSLocalizedString(@"Hide in Dashboard", nil) defaultValue:[product.hidden boolValue]]; - FieldSectionSpecifier *productSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObjects:productNameField, hideProductField, nil] title:nil description:nil]; + FieldSpecifier *reloadProductInfoField = [FieldSpecifier buttonFieldWithKey:[NSString stringWithFormat:@"product.reload.%@", product.productID] title:NSLocalizedString(@"Reload App Icon...", nil)]; + FieldSectionSpecifier *productSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObjects:productNameField, hideProductField, reloadProductInfoField, nil] title:nil description:nil]; FieldSpecifier *showInAppStoreField = [FieldSpecifier buttonFieldWithKey:[NSString stringWithFormat:@"product.appstore.%@", product.productID] title:NSLocalizedString(@"Show in App Store...", nil)]; NSString *productFooter = [NSString stringWithFormat:@"Current version: %@\nApple ID: %@", ((product.currentVersion) ? product.currentVersion : @"N/A"), product.productID]; FieldSectionSpecifier *showInAppStoreSection = [FieldSectionSpecifier sectionWithFields:[NSArray arrayWithObject:showInAppStoreField] title:nil description:productFooter]; @@ -538,6 +542,10 @@ - (void)fieldEditor:(FieldEditorViewController *)editor pressedButtonWithKey:(NS NSString *productID = [key substringFromIndex:[@"product.appstore." length]]; NSString *appStoreURLString = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@", productID]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreURLString]]; + } else if ([key hasPrefix:@"product.reload."]) { + NSString *productID = [key substringFromIndex:[@"product.reload." length]]; + IconManager *iconManager = [IconManager sharedManager]; + [iconManager clearIconForAppID:productID]; } else if ([key isEqualToString:kDeleteAccountButton]) { UIAlertView *confirmDeleteAlert = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete Account?", nil) message:NSLocalizedString(@"Do you really want to delete this account and all of its data?", nil) @@ -718,6 +726,15 @@ - (void)didSettingsChanged:(KKPasscodeSettingsViewController*)viewController [settingsViewController.tableView reloadData]; } +- (void)iconCleared:(NSNotification *)notification +{ + NSString *productID = [[notification userInfo] objectForKey:kIconManagerClearedIconNotificationAppID]; + if (productID) { + // reload Icon + [[IconManager sharedManager] iconForAppID:productID]; + } +} + #pragma mark - - (void)saveContext diff --git a/Classes/AppIconView.m b/Classes/AppIconView.m index 2fd81a8e..b972d754 100644 --- a/Classes/AppIconView.m +++ b/Classes/AppIconView.m @@ -18,6 +18,7 @@ - (void)setProductID:(NSString *)newProductID if ([newProductID isEqualToString:productID]) return; if (!productID) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iconDownloaded:) name:IconManagerDownloadedIconNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iconCleared:) name:IconManagerClearedIconNotification object:nil]; } [newProductID retain]; @@ -37,6 +38,12 @@ - (void)iconDownloaded:(NSNotification *)notification self.image = [[IconManager sharedManager] iconForAppID:productID]; } } +- (void)iconCleared:(NSNotification *)notification +{ + if ([[[notification userInfo] objectForKey:kIconManagerClearedIconNotificationAppID] isEqualToString:self.productID]) { + self.image = [UIImage imageNamed:@"GenericApp.png"]; + } +} - (void)dealloc { diff --git a/Classes/IconManager.h b/Classes/IconManager.h index eaa499a3..06d08b55 100644 --- a/Classes/IconManager.h +++ b/Classes/IconManager.h @@ -10,6 +10,8 @@ #define kIconManagerDownloadedIconNotificationAppID @"appID" #define IconManagerDownloadedIconNotification @"IconManagerDownloadedIconNotification" +#define kIconManagerClearedIconNotificationAppID @"appID" +#define IconManagerClearedIconNotification @"IconManagerClearedIconNotification" @interface IconManager : NSObject { @@ -22,5 +24,6 @@ + (id)sharedManager; - (NSString *)iconDirectory; - (UIImage *)iconForAppID:(NSString *)appID; +- (void)clearIconForAppID:(NSString *)appID; @end diff --git a/Classes/IconManager.m b/Classes/IconManager.m index 1e86da62..f60834ce 100644 --- a/Classes/IconManager.m +++ b/Classes/IconManager.m @@ -111,6 +111,16 @@ - (void)dequeueDownload }); } +- (void)clearIconForAppID:(NSString *)appID +{ + dispatch_async(dispatch_get_main_queue(), ^ { + NSString *iconPath = [[self iconDirectory] stringByAppendingPathComponent:appID]; + [[NSFileManager defaultManager] removeItemAtPath:iconPath error:NULL]; + [iconCache removeObjectForKey:appID]; + [[NSNotificationCenter defaultCenter] postNotificationName:IconManagerClearedIconNotification object:self userInfo:[NSDictionary dictionaryWithObject:appID forKey:kIconManagerClearedIconNotificationAppID]]; + }); +} + - (void)dealloc { dispatch_release(queue);