Skip to content

Commit

Permalink
Merge branch 'release/4.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnavarrom committed Dec 17, 2018
2 parents f95975f + a3d663c commit f544dd1
Show file tree
Hide file tree
Showing 127 changed files with 7,614 additions and 2,209 deletions.
128 changes: 122 additions & 6 deletions MEGA.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

84 changes: 30 additions & 54 deletions iMEGA/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
#import "NSFileManager+MNZCategory.h"
#import "NSString+MNZCategory.h"
#import "NSURL+MNZCategory.h"
#import "UIApplication+MNZCategory.h"
#import "UIImage+MNZCategory.h"
#import "UIImage+GKContact.h"
#import "UIApplication+MNZCategory.h"
#import "UITextField+MNZCategory.h"

#import "BrowserViewController.h"
#import "CallViewController.h"
Expand Down Expand Up @@ -978,6 +979,10 @@ - (void)showEncryptedLinkAlert:(NSString *)encryptedLinkURLString {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:AMLocalizedString(@"decryptionKeyAlertTitle", nil) message:AMLocalizedString(@"decryptionKeyAlertMessage", nil) preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = AMLocalizedString(@"decryptionKey", nil);
[textField addTarget:self action:@selector(alertTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
textField.shouldReturnCompletion = ^BOOL(UITextField *textField) {
return !textField.text.mnz_isEmpty;
};
}];
[alertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[MEGASdkManager sharedMEGASdk] decryptPasswordProtectedLink:encryptedLinkURLString password:alertController.textFields.firstObject.text delegate:delegate];
Expand Down Expand Up @@ -1337,17 +1342,7 @@ - (void)presentNode {
uint64_t handle = [MEGASdk handleForBase64Handle:self.nodeToPresentBase64Handle];
MEGANode *node = [[MEGASdkManager sharedMEGASdk] nodeForHandle:handle];
if (node) {
UINavigationController *navigationController;
if ([[MEGASdkManager sharedMEGASdk] accessLevelForNode:node] != MEGAShareTypeAccessOwner) { // node from inshare
self.mainTBC.selectedIndex = SHARES;
SharedItemsViewController *sharedItemsVC = self.mainTBC.childViewControllers[SHARES].childViewControllers[0];
[sharedItemsVC selectSegment:0]; // Incoming
} else {
self.mainTBC.selectedIndex = CLOUD;
}
navigationController = [self.mainTBC.childViewControllers objectAtIndex:self.mainTBC.selectedIndex];

[self presentNode:node inNavigationController:navigationController];
[node navigateToParentAndPresent];
} else {
if ([SAMKeychain passwordForService:@"MEGA" account:@"sessionV3"]) {
UIAlertController *theContentIsNotAvailableAlertController = [UIAlertController alertControllerWithTitle:AMLocalizedString(@"theContentIsNotAvailableForThisAccount", @"") message:nil preferredStyle:UIAlertControllerStyleAlert];
Expand Down Expand Up @@ -1393,45 +1388,6 @@ - (void)presentNode {
self.nodeToPresentBase64Handle = nil;
}

- (void)presentNode:(MEGANode *)node inNavigationController:(UINavigationController *)navigationController {
[navigationController popToRootViewControllerAnimated:NO];

NSArray *parentTreeArray = node.mnz_parentTreeArray;
for (MEGANode *node in parentTreeArray) {
CloudDriveViewController *cloudDriveVC = [[UIStoryboard storyboardWithName:@"Cloud" bundle:nil] instantiateViewControllerWithIdentifier:@"CloudDriveID"];
cloudDriveVC.parentNode = node;
[navigationController pushViewController:cloudDriveVC animated:NO];
}

switch (node.type) {
case MEGANodeTypeFolder:
case MEGANodeTypeRubbish: {
CloudDriveViewController *cloudDriveVC = [[UIStoryboard storyboardWithName:@"Cloud" bundle:nil] instantiateViewControllerWithIdentifier:@"CloudDriveID"];
cloudDriveVC.parentNode = node;
[navigationController pushViewController:cloudDriveVC animated:NO];
break;
}

case MEGANodeTypeFile: {
if (node.name.mnz_isImagePathExtension || node.name.mnz_isVideoPathExtension) {
MEGANode *parentNode = [[MEGASdkManager sharedMEGASdk] nodeForHandle:node.parentHandle];
MEGANodeList *nodeList = [[MEGASdkManager sharedMEGASdk] childrenForParent:parentNode];
NSMutableArray<MEGANode *> *mediaNodesArray = [nodeList mnz_mediaNodesMutableArrayFromNodeList];

MEGAPhotoBrowserViewController *photoBrowserVC = [MEGAPhotoBrowserViewController photoBrowserWithMediaNodes:mediaNodesArray api:[MEGASdkManager sharedMEGASdk] displayMode:DisplayModeCloudDrive presentingNode:node preferredIndex:0];

[navigationController presentViewController:photoBrowserVC animated:YES completion:nil];
} else {
[node mnz_openNodeInNavigationController:navigationController folderLink:NO];
}
break;
}

default:
break;
}
}

- (void)migrateLocalCachesLocation {
NSString *cachesPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
NSError *error;
Expand Down Expand Up @@ -1592,6 +1548,14 @@ - (void)showChooseAccountType {
self.urlType = URLTypeDefault;
}

- (void)alertTextFieldDidChange:(UITextField *)textField {
UIAlertController *alertController = (UIAlertController *)UIApplication.mnz_visibleViewController;
if (alertController) {
UIAlertAction *rightButtonAction = alertController.actions.firstObject;
rightButtonAction.enabled = !textField.text.mnz_isEmpty;
}
}

#pragma mark - Battery changed

- (void)batteryChanged:(NSNotification *)notification {
Expand Down Expand Up @@ -2295,16 +2259,23 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
masterKeyLoggedInAlertController = [UIAlertController alertControllerWithTitle:AMLocalizedString(@"passwordReset", @"Headline of the password reset recovery procedure") message:AMLocalizedString(@"pleaseEnterYourRecoveryKey", @"A message shown to explain that the user has to input (type or paste) their recovery key to continue with the reset password process.") preferredStyle:UIAlertControllerStyleAlert];
[masterKeyLoggedInAlertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = AMLocalizedString(@"recoveryKey", @"Label for any 'Recovery Key' button, link, text, title, etc. Preserve uppercase - (String as short as possible). The Recovery Key is the new name for the account 'Master Key', and can unlock (recover) the account if the user forgets their password.");
[textField addTarget:self action:@selector(alertTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
textField.shouldReturnCompletion = ^BOOL(UITextField *textField) {
return !textField.text.mnz_isEmpty;
};
}];
}

[masterKeyLoggedInAlertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:nil]];
[masterKeyLoggedInAlertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UIAlertAction *okAlertAction = [UIAlertAction actionWithTitle:AMLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *masterKey = masterKeyLoggedInAlertController.textFields.count ? masterKeyLoggedInAlertController.textFields[0].text : [[MEGASdkManager sharedMEGASdk] masterKey];
[self presentChangeViewType:ChangeTypeResetPassword email:self.emailOfNewSignUpLink masterKey:masterKey link:self.recoveryLink];
self.emailOfNewSignUpLink = nil;
self.recoveryLink = nil;
}]];
}];
okAlertAction.enabled = NO;
[masterKeyLoggedInAlertController addAction:okAlertAction];

[masterKeyLoggedInAlertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:nil]];

self.emailOfNewSignUpLink = request.email;
self.recoveryLink = request.link;
Expand Down Expand Up @@ -2615,6 +2586,11 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:

[transfer mnz_parseAppData];

if ([transfer.appData containsString:@">localIdentifier"]) {
NSString *localIdentifier = [transfer.appData mnz_stringBetweenString:@">localIdentifier=" andString:@""];
[[Helper uploadingNodes] removeObject:localIdentifier];
}

[Helper startPendingUploadTransferIfNeeded];
}

Expand Down
1 change: 1 addition & 0 deletions iMEGA/Categories/MEGANode+MNZCategory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

@interface MEGANode (MNZCategory) <UITextFieldDelegate>

- (void)navigateToParentAndPresent;
- (void)mnz_openNodeInNavigationController:(UINavigationController *)navigationController folderLink:(BOOL)isFolderLink;
- (UIViewController *)mnz_viewControllerForNodeInFolderLink:(BOOL)isFolderLink;

Expand Down
84 changes: 68 additions & 16 deletions iMEGA/Categories/MEGANode+MNZCategory.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,72 @@
#import "NSFileManager+MNZCategory.h"
#import "NSString+MNZCategory.h"
#import "UIApplication+MNZCategory.h"
#import "UITextField+MNZCategory.h"

#import "BrowserViewController.h"
#import "CloudDriveViewController.h"
#import "LoginViewController.h"
#import "MainTabBarController.h"
#import "MEGAAVViewController.h"
#import "MEGANavigationController.h"
#import "MEGAPhotoBrowserViewController.h"
#import "MEGAQLPreviewController.h"
#import "MyAccountHallViewController.h"
#import "PreviewDocumentViewController.h"
#import "MEGAQLPreviewController.h"
#import "SharedItemsViewController.h"

@implementation MEGANode (MNZCategory)

- (void)navigateToParentAndPresent {
MainTabBarController *mainTBC = (MainTabBarController *) UIApplication.sharedApplication.delegate.window.rootViewController;

if ([[MEGASdkManager sharedMEGASdk] accessLevelForNode:self] != MEGAShareTypeAccessOwner) { // Node from inshare
mainTBC.selectedIndex = SHARES;
SharedItemsViewController *sharedItemsVC = mainTBC.childViewControllers[SHARES].childViewControllers.firstObject;
[sharedItemsVC selectSegment:0]; // Incoming
} else {
mainTBC.selectedIndex = CLOUD;
}

UINavigationController *navigationController = [mainTBC.childViewControllers objectAtIndex:mainTBC.selectedIndex];
[navigationController popToRootViewControllerAnimated:NO];

NSArray *parentTreeArray = self.mnz_parentTreeArray;
for (MEGANode *node in parentTreeArray) {
CloudDriveViewController *cloudDriveVC = [[UIStoryboard storyboardWithName:@"Cloud" bundle:nil] instantiateViewControllerWithIdentifier:@"CloudDriveID"];
cloudDriveVC.parentNode = node;
[navigationController pushViewController:cloudDriveVC animated:NO];
}

switch (self.type) {
case MEGANodeTypeFolder:
case MEGANodeTypeRubbish: {
CloudDriveViewController *cloudDriveVC = [[UIStoryboard storyboardWithName:@"Cloud" bundle:nil] instantiateViewControllerWithIdentifier:@"CloudDriveID"];
cloudDriveVC.parentNode = self;
[navigationController pushViewController:cloudDriveVC animated:NO];
break;
}

case MEGANodeTypeFile: {
if (self.name.mnz_isImagePathExtension || self.name.mnz_isVideoPathExtension) {
MEGANode *parentNode = [[MEGASdkManager sharedMEGASdk] nodeForHandle:self.parentHandle];
MEGANodeList *nodeList = [[MEGASdkManager sharedMEGASdk] childrenForParent:parentNode];
NSMutableArray<MEGANode *> *mediaNodesArray = [nodeList mnz_mediaNodesMutableArrayFromNodeList];

MEGAPhotoBrowserViewController *photoBrowserVC = [MEGAPhotoBrowserViewController photoBrowserWithMediaNodes:mediaNodesArray api:[MEGASdkManager sharedMEGASdk] displayMode:DisplayModeCloudDrive presentingNode:self preferredIndex:0];

[navigationController presentViewController:photoBrowserVC animated:YES completion:nil];
} else {
[self mnz_openNodeInNavigationController:navigationController folderLink:NO];
}
break;
}

default:
break;
}
}

- (void)mnz_openNodeInNavigationController:(UINavigationController *)navigationController folderLink:(BOOL)isFolderLink {
UIViewController *viewController = [self mnz_viewControllerForNodeInFolderLink:isFolderLink];
if (viewController) {
Expand Down Expand Up @@ -211,9 +265,18 @@ - (void)mnz_renameNodeInViewController:(UIViewController *)viewController comple
UIAlertController *renameAlertController = [UIAlertController alertControllerWithTitle:AMLocalizedString(@"rename", @"Title for the action that allows you to rename a file or folder") message:AMLocalizedString(@"renameNodeMessage", @"Hint text to suggest that the user have to write the new name for the file or folder") preferredStyle:UIAlertControllerStyleAlert];

[renameAlertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.delegate = self;
textField.text = self.name;
[textField addTarget:self action:@selector(renameAlertTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
textField.shouldReturnCompletion = ^BOOL(UITextField *textField) {
BOOL shouldReturn = YES;
UIAlertController *renameAlertController = (UIAlertController *)UIApplication.mnz_visibleViewController;
if (renameAlertController) {
UIAlertAction *rightButtonAction = renameAlertController.actions.lastObject;
shouldReturn = rightButtonAction.enabled;
}

return shouldReturn;
};
}];

[renameAlertController addAction:[UIAlertAction actionWithTitle:AMLocalizedString(@"cancel", @"Button title to cancel something") style:UIAlertActionStyleCancel handler:nil]];
Expand Down Expand Up @@ -764,40 +827,29 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
return shouldChangeCharacters;
}

- (void)renameAlertTextFieldDidChange:(UITextField *)sender {
- (void)renameAlertTextFieldDidChange:(UITextField *)textField {
UIAlertController *renameAlertController = (UIAlertController *)UIApplication.mnz_visibleViewController;
if (renameAlertController) {
UITextField *textField = renameAlertController.textFields.firstObject;
UIAlertAction *rightButtonAction = renameAlertController.actions.lastObject;
BOOL enableRightButton = NO;

NSString *newName = textField.text;
NSString *nodeNameString = self.name;

if (self.isFile || self.isFolder) {
BOOL containsInvalidChars = [sender.text rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"|*/:<>?\"\\"]].length;
BOOL containsInvalidChars = textField.text.mnz_containsInvalidChars;
if ([newName isEqualToString:@""] || [newName isEqualToString:nodeNameString] || newName.mnz_isEmpty || containsInvalidChars) {
enableRightButton = NO;
} else {
enableRightButton = YES;
}
sender.textColor = containsInvalidChars ? UIColor.mnz_redMain : UIColor.darkTextColor;
textField.textColor = containsInvalidChars ? UIColor.mnz_redMain : UIColor.darkTextColor;
}

rightButtonAction.enabled = enableRightButton;
}
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
UIAlertController *renameAlertController = (UIAlertController *)UIApplication.mnz_visibleViewController;
if (renameAlertController) {
UIAlertAction *rightButtonAction = renameAlertController.actions.lastObject;
return rightButtonAction.enabled;
}

return YES;
}

- (void)mnz_copyToGalleryFromTemporaryPath:(NSString *)path {
if (self.name.mnz_isVideoPathExtension) {
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path)) {
Expand Down
6 changes: 6 additions & 0 deletions iMEGA/Categories/MEGATransferList+MNZCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@interface MEGATransferList (MNZCategory)

- (NSArray *)mnz_transfersArrayFromTranferList;

@end
17 changes: 17 additions & 0 deletions iMEGA/Categories/MEGATransferList+MNZCategory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#import "MEGATransferList+MNZCategory.h"

@implementation MEGATransferList (MNZCategory)

- (NSArray *)mnz_transfersArrayFromTranferList {
NSUInteger transferListCount = self.size.unsignedIntegerValue;
NSMutableArray *transfersMutableArray = [[NSMutableArray alloc] initWithCapacity:transferListCount];
for (NSUInteger i = 0; i < transferListCount; i++) {
MEGATransfer *transfer = [self transferAtIndex:i];
[transfersMutableArray addObject:transfer];
}

return transfersMutableArray;
}

@end
11 changes: 11 additions & 0 deletions iMEGA/Categories/MEGAUserAlertList+MNZCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

NS_ASSUME_NONNULL_BEGIN

@interface MEGAUserAlertList (MNZCategory)

@property (nonatomic, readonly) NSArray<MEGAUserAlert *> *mnz_userAlertsArray;
@property (nonatomic, readonly) NSUInteger mnz_unseenCount;

@end

NS_ASSUME_NONNULL_END
34 changes: 34 additions & 0 deletions iMEGA/Categories/MEGAUserAlertList+MNZCategory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#import "MEGAUserAlertList+MNZCategory.h"

#import "MEGAUserAlert.h"

@implementation MEGAUserAlertList (MNZCategory)

- (NSArray<MEGAUserAlert *> *)mnz_userAlertsArray {
NSInteger userAlertListCount = self.size;

NSMutableArray<MEGAUserAlert *> *userAlertsArray = [[NSMutableArray<MEGAUserAlert *> alloc] initWithCapacity:userAlertListCount];
for (NSUInteger i = 0; i < userAlertListCount; i++) {
MEGAUserAlert *userAlert = [self usertAlertAtIndex:i];
[userAlertsArray insertObject:userAlert atIndex:0];
}

return [userAlertsArray copy];
}

- (NSUInteger)mnz_unseenCount {
NSUInteger unseenCount = 0;

NSInteger userAlertListCount = self.size;
for (NSUInteger i = 0; i < userAlertListCount; i++) {
MEGAUserAlert *userAlert = [self usertAlertAtIndex:i];
if (!userAlert.isSeen) {
unseenCount++;
}
}

return unseenCount;
}

@end
5 changes: 5 additions & 0 deletions iMEGA/Categories/NSString+MNZCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef NS_ENUM(NSInteger, MEGAChatMessageEndCallReason);
- (NSString *)mnz_appDataToSaveInPhotosApp;
- (NSString *)mnz_appDataToAttachToChatID:(uint64_t)chatId;
- (NSString *)mnz_appDataToSaveCoordinates:(NSString *)coordinates;
- (NSString *)mnz_appDataToLocalIdentifier:(NSString *)localIdentifier;

#pragma mark - Utils

Expand All @@ -33,6 +34,8 @@ typedef NS_ENUM(NSInteger, MEGAChatMessageEndCallReason);

- (BOOL)mnz_isEmpty;

- (BOOL)mnz_containsInvalidChars;

- (NSString *)mnz_removeWebclientFormatters;

+ (NSString *)mnz_stringFromTimeInterval:(NSTimeInterval)interval;
Expand All @@ -51,6 +54,8 @@ typedef NS_ENUM(NSInteger, MEGAChatMessageEndCallReason);

- (NSString *)mnz_relativeLocalPath;

+ (NSString *)mnz_lastGreenStringFromMinutes:(NSInteger)minutes;

#pragma mark - File names and extensions

+ (NSString *)mnz_fileNameWithDate:(NSDate *)date;
Expand Down
Loading

0 comments on commit f544dd1

Please sign in to comment.