Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #206: added "Reload App Icon..." cell to AccountsViewController > Manage Apps #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AppSales.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
7F709D3D13BC98860008DBAD /* AppSalesAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppSalesAppDelegate.m; sourceTree = "<group>"; };
7F709D4013BC98860008DBAD /* AppSales.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AppSales.xcdatamodel; sourceTree = "<group>"; };
7F709D4513BC98860008DBAD /* AccountsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AccountsViewController.h; sourceTree = "<group>"; };
7F709D4613BC98860008DBAD /* AccountsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AccountsViewController.m; sourceTree = "<group>"; };
7F709D4613BC98860008DBAD /* AccountsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = AccountsViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
7F709D6113BCB64E0008DBAD /* FieldEditorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FieldEditorViewController.h; sourceTree = "<group>"; };
7F709D6213BCB64F0008DBAD /* FieldEditorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FieldEditorViewController.m; sourceTree = "<group>"; };
7F709D6A13BCC3C80008DBAD /* SSKeychain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSKeychain.h; sourceTree = "<group>"; };
Expand Down
19 changes: 18 additions & 1 deletion Classes/AccountsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "KKPasscodeLock.h"
#import "ZipFile.h"
#import "ZipWriteStream.h"
#import "IconManager.h"

#define kAddNewAccountEditorIdentifier @"AddNewAccountEditorIdentifier"
#define kEditAccountEditorIdentifier @"EditAccountEditorIdentifier"
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Classes/AppIconView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions Classes/IconManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#define kIconManagerDownloadedIconNotificationAppID @"appID"
#define IconManagerDownloadedIconNotification @"IconManagerDownloadedIconNotification"
#define kIconManagerClearedIconNotificationAppID @"appID"
#define IconManagerClearedIconNotification @"IconManagerClearedIconNotification"

@interface IconManager : NSObject {

Expand All @@ -22,5 +24,6 @@
+ (id)sharedManager;
- (NSString *)iconDirectory;
- (UIImage *)iconForAppID:(NSString *)appID;
- (void)clearIconForAppID:(NSString *)appID;

@end
10 changes: 10 additions & 0 deletions Classes/IconManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down