Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into iWeek-LocalAuthentication
  • Loading branch information
alexp84 committed Jan 25, 2016
2 parents bd3f7a4 + ad8231e commit 592711b
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 132 deletions.
15 changes: 13 additions & 2 deletions AlfrescoApp/App Delegate/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#import <HockeySDK/HockeySDK.h>

@import MediaPlayer;

static NSString * const kMDMMissingRequiredKeysKey = @"MDMMissingKeysKey";

@interface AppDelegate()
Expand Down Expand Up @@ -208,8 +210,11 @@ - (void)applicationWillResignActive:(UIApplication *)application
[[AccountManager sharedManager] saveAccountsToKeychain];
}


-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
#else
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
#endif
{
// default is to support all orientations
UIInterfaceOrientationMask supportedOrientations = UIInterfaceOrientationMaskAll;
Expand All @@ -233,6 +238,12 @@ -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedI
supportedOrientations = [presentedController supportedInterfaceOrientations];
}
}
else if ([modalViewController isKindOfClass:[MPMoviePlayerViewController class]])
{
MPMoviePlaybackState playbackState = [(MPMoviePlayerViewController *)modalViewController moviePlayer].playbackState;

supportedOrientations = (playbackState == MPMoviePlaybackStateStopped || playbackState == MPMoviePlaybackStatePaused) ? supportedOrientations : UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
if ([modalViewController conformsToProtocol:@protocol(ModalRotation)])
Expand Down
57 changes: 45 additions & 12 deletions AlfrescoApp/Model/Managers/AppConfigurationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (id)init

self.embeddedConfigService = [[AlfrescoConfigService alloc] initWithDictionary:parameters];
self.noAccountConfigService = [[AlfrescoConfigService alloc] initWithDictionary:noAccountParameters];
if([AccountManager sharedManager].allAccounts.count > 0)
if(([AccountManager sharedManager].allAccounts.count > 0) || ([AccountManager sharedManager].selectedAccount != nil))
{
self.currentConfigService = self.embeddedConfigService;
}
Expand Down Expand Up @@ -211,7 +211,6 @@ - (AlfrescoConfigService *)configurationServiceForAccount:(UserAccount *)account
NSDictionary *parameters = @{kAlfrescoConfigServiceParameterFolder: accountConfigurationFolderPath,
kAlfrescoConfigServiceParameterFileName: kAlfrescoEmbeddedConfigurationFileName};
returnService = [[AlfrescoConfigService alloc] initWithDictionary:parameters];
returnService.session = self.session;
}
else
{
Expand Down Expand Up @@ -267,11 +266,34 @@ - (void)sessionReceived:(NSNotification *)notification
{
id<AlfrescoSession> session = notification.object;
self.session = session;

self.currentConfigService = [self configurationServiceForAccount:[AccountManager sharedManager].selectedAccount];
self.currentConfigService.session = session;

[self.currentConfigService retrieveDefaultProfileWithCompletionBlock:^(AlfrescoProfileConfig *defaultProfile, NSError *defaultProfileError) {
if (defaultProfileError)
{
AlfrescoLogError(@"Error retrieving the default profile. Error: %@", defaultProfileError.localizedDescription);

if (defaultProfileError.code == kAlfrescoErrorCodeRequestedNodeNotFound) // The requested node wasn't found
{
// If the node is not found on the server, delete configuration.json from user's folder.
UserAccount *account = [AccountManager sharedManager].selectedAccount;
NSString *accountSpecificFolderPath = [self accountSpecificConfigurationFolderPath:account];
accountSpecificFolderPath = [accountSpecificFolderPath stringByAppendingPathComponent:kAlfrescoEmbeddedConfigurationFileName];

if ([[NSFileManager defaultManager] fileExistsAtPath:accountSpecificFolderPath])
{
NSError *removeConfigurationError;
BOOL fileRemovedSuccessfully = [[NSFileManager defaultManager] removeItemAtPath:accountSpecificFolderPath error:&removeConfigurationError];

if (fileRemovedSuccessfully)
{
MainMenuLocalConfigurationBuilder *localBuilder = [[MainMenuLocalConfigurationBuilder alloc] initWithAccount:account session:session];
[[NSNotificationCenter defaultCenter] postNotificationName:kAlfrescoConfigFileDidUpdateNotification object:localBuilder userInfo:@{kAppConfigurationUserCanEditMainMenuKey : @YES}];
}
}
}
}
else
{
Expand All @@ -297,15 +319,23 @@ - (void)sessionReceived:(NSNotification *)notification
// Attempt to download and select the default profile
AlfrescoConfigService *configService = [[AlfrescoConfigService alloc] initWithSession:session];
// define a success block
void (^profileSuccessfullySelectedBlock)(AlfrescoProfileConfig *profile) = ^(AlfrescoProfileConfig *selectedProfile) {
void (^profileSuccessfullySelectedBlock)(AlfrescoProfileConfig *profile, BOOL isEmbeddedConfig) = ^(AlfrescoProfileConfig *selectedProfile, BOOL isEmbeddedConfig) {
self.currentConfigService = configService;
self.selectedProfile = selectedProfile;
self.currentConfigAccountIdentifier = account.accountIdentifier;
account.selectedProfileIdentifier = selectedProfile.identifier;
account.selectedProfileName = selectedProfile.label;

MainMenuRemoteConfigurationBuilder *remoteBuilder = [[MainMenuRemoteConfigurationBuilder alloc] initWithAccount:account session:session];
[[NSNotificationCenter defaultCenter] postNotificationName:kAlfrescoConfigFileDidUpdateNotification object:remoteBuilder userInfo:@{kAppConfigurationUserCanEditMainMenuKey : @NO}];
MainMenuConfigurationBuilder *builder;
if(isEmbeddedConfig)
{
builder = [[MainMenuLocalConfigurationBuilder alloc] initWithAccount:account session:session];
}
else
{
builder = [[MainMenuRemoteConfigurationBuilder alloc] initWithAccount:account session:session];
}
[[NSNotificationCenter defaultCenter] postNotificationName:kAlfrescoConfigFileDidUpdateNotification object:builder userInfo:@{kAppConfigurationUserCanEditMainMenuKey : [NSNumber numberWithBool:isEmbeddedConfig]}];
};

NSString *selectedProfileIdentifier = account.selectedProfileIdentifier;
Expand All @@ -332,20 +362,20 @@ - (void)sessionReceived:(NSNotification *)notification
}
else
{
profileSuccessfullySelectedBlock(defaultProfile);
profileSuccessfullySelectedBlock(defaultProfile, YES);
}
}];
}
}
else
{
profileSuccessfullySelectedBlock(defaultServerProfile);
profileSuccessfullySelectedBlock(defaultServerProfile, NO);
}
}];
}
else
{
profileSuccessfullySelectedBlock(identifierProfile);
profileSuccessfullySelectedBlock(identifierProfile, NO);
}
}];
}
Expand All @@ -368,14 +398,14 @@ - (void)sessionReceived:(NSNotification *)notification
}
else
{
profileSuccessfullySelectedBlock(defaultProfile);
profileSuccessfullySelectedBlock(defaultProfile, YES);
}
}];
}
}
else
{
profileSuccessfullySelectedBlock(defaultServerProfile);
profileSuccessfullySelectedBlock(defaultServerProfile, NO);
}
}];
}
Expand All @@ -402,6 +432,7 @@ - (void)accountRemoved:(NSNotification *)notification
- (void)noMoreAccounts:(NSNotification *)notification
{
self.currentConfigService = self.noAccountConfigService;
[AppConfigurationManager resetInstanceAndReturnManager];
[[NSNotificationCenter defaultCenter] postNotificationName:kAlfrescoConfigFileDidUpdateNotification object:nil userInfo:nil];
}

Expand Down Expand Up @@ -449,11 +480,13 @@ - (void)setupConfigurationFileFromBundleIfRequiredWithCompletionBlock:(void (^)(
AlfrescoFileManager *fileManager = [AlfrescoFileManager sharedManager];

// File location to the configuration file
NSString *completeDestinationPath = ([AccountManager sharedManager].allAccounts.count > 0) ? [self filePathForEmbeddedConfigurationFile] : [self filePathForNoAccountsConfigurationFile];
BOOL areThereAccounts = ([AccountManager sharedManager].allAccounts.count > 0) || ([AccountManager sharedManager].selectedAccount != nil);

NSString *completeDestinationPath = areThereAccounts ? [self filePathForEmbeddedConfigurationFile] : [self filePathForNoAccountsConfigurationFile];

if (![fileManager fileExistsAtPath:completeDestinationPath])
{
NSString *configFileName = ([AccountManager sharedManager].allAccounts.count > 0) ? kAlfrescoEmbeddedConfigurationFileName : kAlfrescoNoAccountConfigurationFileName;
NSString *configFileName = areThereAccounts ? kAlfrescoEmbeddedConfigurationFileName : kAlfrescoNoAccountConfigurationFileName;

NSString *fileLocationInBundle = [[NSBundle mainBundle] pathForResource:configFileName.stringByDeletingPathExtension ofType:configFileName.pathExtension];
NSError *copyError = nil;
Expand Down
4 changes: 1 addition & 3 deletions AlfrescoApp/Model/Managers/SyncHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ - (void)updateLocalSyncInfoWithRemoteInfo:(NSDictionary *)syncNodesInfo
}
}
[self.syncCoreDataHelper saveContextForManagedObjectContext:managedContext];
[managedContext performBlock:^{
[managedContext reset];
}];
[managedContext reset];
}
}

Expand Down
83 changes: 41 additions & 42 deletions AlfrescoApp/Model/Managers/SyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,7 @@ - (void)syncNodes:(NSArray *)nodes includeExistingSyncNodes:(BOOL)includeExistin
{
[self deleteUnWantedSyncedNodes:nodes inManagedObjectContext:privateManagedObjectContext completionBlock:^(BOOL completed) {
[self.syncCoreDataHelper saveContextForManagedObjectContext:privateManagedObjectContext];
[privateManagedObjectContext performBlock:^{
[privateManagedObjectContext reset];
}];
[privateManagedObjectContext reset];
syncInfoandContent();
}];
}
Expand Down Expand Up @@ -663,30 +661,32 @@ - (void)deleteUnWantedSyncedNodes:(NSArray *)nodes inManagedObjectContext:(NSMan
AlfrescoNode *localNode = [NSKeyedUnarchiver unarchiveObjectWithData:nodeInfo.node];
// check if there is any problem with removing the node from local sync

[self checkForObstaclesInRemovingDownloadForNode:localNode inManagedObjectContext:managedContext completionBlock:^(BOOL encounteredObstacle) {

totalChecksForObstacles--;

if (encounteredObstacle == NO)
{
// if no problem with removing the node from local sync then delete the node from local sync nodes
[self.syncHelper deleteNodeFromSync:localNode inAccountWithId:self.selectedAccountIdentifier inManagedObjectContext:managedContext];
}
else
{
// if any problem encountered then set isRemovedFromSyncHasLocalChanges flag to YES so its not on deleted until its changes are synced to server
nodeInfo.isRemovedFromSyncHasLocalChanges = [NSNumber numberWithBool:YES];
nodeInfo.parentNode = nil;
}

if (totalChecksForObstacles == 0)
{
if (completionBlock != NULL)
dispatch_async(dispatch_get_main_queue(), ^{
[self checkForObstaclesInRemovingDownloadForNode:localNode inManagedObjectContext:managedContext completionBlock:^(BOOL encounteredObstacle) {

totalChecksForObstacles--;

if (encounteredObstacle == NO)
{
completionBlock(YES);
// if no problem with removing the node from local sync then delete the node from local sync nodes
[self.syncHelper deleteNodeFromSync:localNode inAccountWithId:self.selectedAccountIdentifier inManagedObjectContext:managedContext];
}
}
}];
else
{
// if any problem encountered then set isRemovedFromSyncHasLocalChanges flag to YES so its not on deleted until its changes are synced to server
nodeInfo.isRemovedFromSyncHasLocalChanges = [NSNumber numberWithBool:YES];
nodeInfo.parentNode = nil;
}

if (totalChecksForObstacles == 0)
{
if (completionBlock != NULL)
{
completionBlock(YES);
}
}
}];
});
}
}
else
Expand Down Expand Up @@ -1231,7 +1231,6 @@ - (void)updateSessionIfNeeded:(id<AlfrescoSession>)session
}
}


- (void)cancelSyncForDocumentWithIdentifier:(NSString *)documentIdentifier
{
[self cancelSyncForDocumentWithIdentifier:documentIdentifier inAccountWithId:self.selectedAccountIdentifier];
Expand Down Expand Up @@ -1483,6 +1482,7 @@ - (void)updateFolderSizes:(BOOL)updateFolderSizes andCheckIfAnyFileModifiedLocal
}
}
}
[privateManagedObjectContext reset];
privateManagedObjectContext = nil;
}
}
Expand All @@ -1501,26 +1501,24 @@ - (void)statusChanged:(NSNotification *)notification
if ([propertyChanged isEqualToString:kSyncTotalSize])
{
SyncNodeInfo *nodeInfo = [self.syncCoreDataHelper nodeInfoForObjectWithNodeId:nodeStatus.nodeId inAccountWithId:self.selectedAccountIdentifier inManagedObjectContext:privateManagedObjectContext];

SyncNodeInfo *parentNodeInfo = nodeInfo.parentNode;
if(nodeInfo)
if (parentNodeInfo)
{
if (parentNodeInfo)
AlfrescoNode *parentNode = [NSKeyedUnarchiver unarchiveObjectWithData:parentNodeInfo.node];
SyncNodeStatus *parentNodeStatus = [self syncStatusForNodeWithId:[self.syncHelper syncIdentifierForNode:parentNode]];

NSDictionary *change = [info objectForKey:kSyncStatusChangeKey];
parentNodeStatus.totalSize += nodeStatus.totalSize - [[change valueForKey:NSKeyValueChangeOldKey] longLongValue];
}
else
{
// if parent folder is nil - update total size for account
SyncNodeStatus *accountSyncStatus = [self.syncHelper syncNodeStatusObjectForNodeWithId:self.selectedAccountIdentifier inSyncNodesStatus:self.syncNodesStatus];
if (nodeStatus != accountSyncStatus)
{
AlfrescoNode *parentNode = [NSKeyedUnarchiver unarchiveObjectWithData:parentNodeInfo.node];
SyncNodeStatus *parentNodeStatus = [self syncStatusForNodeWithId:[self.syncHelper syncIdentifierForNode:parentNode]];

NSDictionary *change = [info objectForKey:kSyncStatusChangeKey];
parentNodeStatus.totalSize += nodeStatus.totalSize - [[change valueForKey:NSKeyValueChangeOldKey] longLongValue];
}
else
{
// if parent folder is nil - update total size for account
SyncNodeStatus *accountSyncStatus = [self.syncHelper syncNodeStatusObjectForNodeWithId:self.selectedAccountIdentifier inSyncNodesStatus:self.syncNodesStatus];
if (nodeStatus != accountSyncStatus)
{
NSDictionary *change = [info objectForKey:kSyncStatusChangeKey];
accountSyncStatus.totalSize += nodeStatus.totalSize - [[change valueForKey:NSKeyValueChangeOldKey] longLongValue];
}
accountSyncStatus.totalSize += nodeStatus.totalSize - [[change valueForKey:NSKeyValueChangeOldKey] longLongValue];
}
}
}
Expand Down Expand Up @@ -1566,6 +1564,7 @@ - (void)statusChanged:(NSNotification *)notification
}
}

[privateManagedObjectContext reset];
privateManagedObjectContext = nil;
}

Expand Down
Loading

0 comments on commit 592711b

Please sign in to comment.