From 5fd89600e2172f5148d8dac9ec7809c07c755d6a Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Fri, 26 Jul 2019 15:48:05 +0200 Subject: new view share --- iOSClient/Nextcloud-Bridging-Header.h | 1 + iOSClient/Share/CCShare.storyboard | 225 ---------- iOSClient/Share/CCShareInfoCMOC.h | 39 -- iOSClient/Share/CCShareInfoCMOC.m | 190 -------- iOSClient/Share/CCShareOC.h | 62 --- iOSClient/Share/CCShareOC.m | 716 ------------------------------ iOSClient/Share/CCSharePermissionOC.h | 41 -- iOSClient/Share/CCSharePermissionOC.m | 205 --------- iOSClient/Share/CCShareUserOC.h | 50 --- iOSClient/Share/CCShareUserOC.m | 268 ----------- iOSClient/Share/NCShare.storyboard | 19 +- iOSClient/Share/NCShare.swift | 39 +- iOSClient/Share/NCShareLinkMenuView.swift | 2 + iOSClient/Share/NCShareNetworking.swift | 15 + iOSClient/Share/NCShareUserMenuView.swift | 2 + 15 files changed, 50 insertions(+), 1824 deletions(-) delete mode 100644 iOSClient/Share/CCShare.storyboard delete mode 100644 iOSClient/Share/CCShareInfoCMOC.h delete mode 100644 iOSClient/Share/CCShareInfoCMOC.m delete mode 100644 iOSClient/Share/CCShareOC.h delete mode 100644 iOSClient/Share/CCShareOC.m delete mode 100644 iOSClient/Share/CCSharePermissionOC.h delete mode 100644 iOSClient/Share/CCSharePermissionOC.m delete mode 100644 iOSClient/Share/CCShareUserOC.h delete mode 100644 iOSClient/Share/CCShareUserOC.m diff --git a/iOSClient/Nextcloud-Bridging-Header.h b/iOSClient/Nextcloud-Bridging-Header.h index b3293bcd1..b4484b697 100644 --- a/iOSClient/Nextcloud-Bridging-Header.h +++ b/iOSClient/Nextcloud-Bridging-Header.h @@ -21,6 +21,7 @@ #import "OCNotifications.h" #import "OCConstants.h" #import "OCNotificationsAction.h" +#import "OCShareUser.h" #import "UtilsFramework.h" #import "NCNetworkingEndToEnd.h" #import "NCRichDocumentTemplate.h" diff --git a/iOSClient/Share/CCShare.storyboard b/iOSClient/Share/CCShare.storyboard deleted file mode 100644 index 6724352eb..000000000 --- a/iOSClient/Share/CCShare.storyboard +++ /dev/null @@ -1,225 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOSClient/Share/CCShareInfoCMOC.h b/iOSClient/Share/CCShareInfoCMOC.h deleted file mode 100644 index 3d11d9fc7..000000000 --- a/iOSClient/Share/CCShareInfoCMOC.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// CCShareInfoCMOC.h -// Nextcloud -// -// Created by Marino Faggiana on 07/03/16. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import - -#import "XLFormViewController.h" -#import "UtilsFramework.h" - -@class tableMetadata; - -@interface CCShareInfoCMOC : XLFormViewController - -@property (nonatomic, weak) IBOutlet UIButton *endButton; - -@property (nonatomic, strong) tableMetadata *metadata; - -- (IBAction)endButtonAction:(id)sender; - -@end diff --git a/iOSClient/Share/CCShareInfoCMOC.m b/iOSClient/Share/CCShareInfoCMOC.m deleted file mode 100644 index b1d73f5f3..000000000 --- a/iOSClient/Share/CCShareInfoCMOC.m +++ /dev/null @@ -1,190 +0,0 @@ -// -// CCShareInfoCMOC.m -// Nextcloud -// -// Created by Marino Faggiana on 07/03/16. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import "CCShareInfoCMOC.h" -#import "XLFormViewController.h" -#import "XLForm.h" -#import "AppDelegate.h" -#import "CCHud.h" -#import "NCBridgeSwift.h" - -@interface CCShareInfoCMOC () -{ - AppDelegate *appDelegate; - CCHud *_hud; -} -@end - -/* -const PERMISSION_CREATE = 4; -const PERMISSION_READ = 1; -const PERMISSION_UPDATE = 2; -const PERMISSION_DELETE = 8; -const PERMISSION_SHARE = 16; -const PERMISSION_ALL = 31; -*/ - -@implementation CCShareInfoCMOC - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super initWithCoder:coder]; - if (self) { - - appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - } - return self; -} - -- (void)initializeForm -{ - XLFormDescriptor *form ; - XLFormSectionDescriptor *section; - XLFormRowDescriptor *row; - - form = [XLFormDescriptor formDescriptor]; - form.rowNavigationOptions = XLFormRowNavigationOptionNone; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"read" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_read_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)]; - - if ([self.metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_connect_you_", nil); - if ([self.metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) row.value = NSLocalizedString(@"_type_resource_external_", nil); - - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - self.form = form; - - form.disabled = YES; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal]; - self.endButton.tintColor = [UIColor blackColor]; - - self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]]; - - [[OCNetworking sharedManager] getSharePermissionsFileWithAccount:appDelegate.activeAccount fileNamePath:[NSString stringWithFormat:@"%@/%@", _metadata.serverUrl, _metadata.fileName] completion:^(NSString *account, NSString *permissions, NSString *message, NSInteger errorCode) { - - [_hud hideHud]; - - if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount] && permissions != nil) { - - NSInteger iPermissions = [permissions integerValue]; - - // ------------------------------------------------------------------ - - XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"]; - XLFormRowDescriptor *rowRead = [self.form formRowWithTag:@"read"]; - XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"]; - XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"]; - XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"]; - - // ------------------------------------------------------------------ - - if ([UtilsFramework isPermissionToCanCreate:iPermissions]) rowCreate.value = @1; - else rowCreate.value = @0; - - if ([UtilsFramework isPermissionToRead:iPermissions]) rowRead.value = @1; - else rowRead.value = @0; - - if ([UtilsFramework isPermissionToCanChange:iPermissions]) rowChange.value = @1; - else rowChange.value = @0; - - if ([UtilsFramework isPermissionToCanDelete:iPermissions]) rowDelete.value = @1; - else rowDelete.value = @0; - - if ([UtilsFramework isPermissionToCanShare:iPermissions]) rowShare.value = @1; - else rowShare.value = @0; - - // ----------------------------------------------------------------- - - [self.tableView reloadData]; - - } else if (errorCode != 0) { - - [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - - [self dismissViewControllerAnimated:YES completion:nil]; - } else { - NSLog(@"[LOG] It has been changed user during networking process, error."); - } - }]; - - [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil]; - - [self initializeForm]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Button ===== -#pragma -------------------------------------------------------------------------------------------- - -- (IBAction)endButtonAction:(id)sender -{ - [self dismissViewControllerAnimated:YES completion:nil]; -} - -@end diff --git a/iOSClient/Share/CCShareOC.h b/iOSClient/Share/CCShareOC.h deleted file mode 100644 index 7d99e4eca..000000000 --- a/iOSClient/Share/CCShareOC.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// CCShareOC.h -// Nextcloud -// -// Created by Marino Faggiana on 13/11/15. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import - -#import "XLFormViewController.h" -#import "CCShareUserOC.h" -#import "CCSharePermissionOC.h" - -@class tableMetadata; - -@protocol CCShareOCDelegate; - -@interface CCShareOC : XLFormViewController - -@property (nonatomic, weak) id delegate; - -@property (nonatomic, weak) IBOutlet UIImageView *fileImageView; -@property (nonatomic, weak) IBOutlet UILabel *labelTitle; -@property (nonatomic, weak) IBOutlet UILabel *labelSharedWithYouBy; -@property (nonatomic, weak) IBOutlet UIButton *endButton; - -@property (nonatomic, strong) NSString *serverUrl; -@property (nonatomic, strong) NSString *shareLink; -@property (nonatomic, strong) NSString *shareUserAndGroup; -@property (nonatomic, strong) tableMetadata *metadata; - -@property (nonatomic, strong) OCSharedDto *itemShareLink; -@property (nonatomic, strong) NSArray *itemsUserAndGroupLink; -@property (nonatomic, strong) NSMutableArray *itemsShareWith; -@property (nonatomic, weak) CCShareUserOC *shareUserOC; -@property (nonatomic, weak) CCSharePermissionOC *sharePermissionOC; - -- (IBAction)endButtonAction:(id)sender; - -@end - -@protocol CCShareOCDelegate - -- (void)readShareServer; - -@end diff --git a/iOSClient/Share/CCShareOC.m b/iOSClient/Share/CCShareOC.m deleted file mode 100644 index d4f1bc0e4..000000000 --- a/iOSClient/Share/CCShareOC.m +++ /dev/null @@ -1,716 +0,0 @@ -// -// CCShareOC.m -// Nextcloud -// -// Created by Marino Faggiana on 13/11/15. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import "CCShareOC.h" -#import "AppDelegate.h" -#import "NCBridgeSwift.h" - -@interface CCShareOC () -{ - AppDelegate *appDelegate; - tableCapabilities *capabilities; -} -@end - -@implementation CCShareOC - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super initWithCoder:coder]; - if (self) { - - appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - self.itemsShareWith = [NSMutableArray new]; - - [self initializeForm]; - } - return self; -} - -- (void)initializeForm -{ - XLFormDescriptor *form ; - XLFormSectionDescriptor *section; - XLFormRowDescriptor *row; - - form = [XLFormDescriptor formDescriptor]; - form.rowNavigationOptions = XLFormRowNavigationOptionNone; - - // Share Link - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_link_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkPermission" rowType:XLFormRowDescriptorTypePicker]; - row.height = 70; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypePassword title:NSLocalizedString(@"_password_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [section addFormRow:row]; - - capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount]; - if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_15_0) { - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"hideDownload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_hide_download_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [section addFormRow:row]; - } - - // Expiration date - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDate" rowType:XLFormRowDescriptorTypeDate title:NSLocalizedString(@"_date_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - row.value = [self tomorrow]; - [row.cellConfigAtConfigure setObject:[self tomorrow] forKey:@"minimumDate"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDateSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_expirationdate_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [section addFormRow:row]; - - // Send Link To - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendLinkTo" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_share_link_button_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"]; - row.action.formSelector = @selector(sendLinkTo:); - [section addFormRow:row]; - - // Sharee - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_title_", nil)]; - [form addFormSection:section]; - section.footerTitle = NSLocalizedString(@"_add_sharee_footer_", nil); - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_sharee_", nil)]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"]; - row.action.formSelector = @selector(shareUserButton:); - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSectionWithTitle:@"" sectionOptions:XLFormSectionOptionCanDelete]; - [form addFormSection:section]; - - self.form = form; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - XLFormRowDescriptor *rowShareLinkPermission = [self.form formRowWithTag:@"shareLinkPermission"]; - if (self.metadata.directory) { - rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_upload_modify_", nil), NSLocalizedString(@"_share_link_upload_", nil)]; - } else { - rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_modify_", nil)]; - } - - [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal]; - self.endButton.tintColor = [UIColor blackColor]; - - if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]]) { - - self.fileImageView.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]]; - - } else { - - if (self.metadata.directory) - self.fileImageView.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement]; - else - self.fileImageView.image = [UIImage imageNamed:self.metadata.iconName]; - - } - - self.labelTitle.text = self.metadata.fileNameView; - self.labelTitle.textColor = [UIColor blackColor]; - - self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0.1 / UIScreen.mainScreen.scale)]; - line.backgroundColor = self.tableView.separatorColor; - line; - }); - - self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - - [self reloadDatasource]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Networking ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission hideDownload:(BOOL)hideDownload -{ - NSString *fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl]; - - [[OCNetworking sharedManager] shareWithAccount:appDelegate.activeAccount fileName:fileName password:password permission:permission hideDownload:hideDownload completion:^(NSString *account, NSString *message, NSInteger errorCode) { - - if (errorCode != 0) { - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - - [self reloadDatasource]; - }]; -} - -- (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl -{ - [[OCNetworking sharedManager] unshareAccount:appDelegate.activeAccount shareID:[share integerValue] completion:^(NSString *account, NSString *message, NSInteger errorCode) { - - if (errorCode != 0) { - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - - [self reloadDatasource]; - }]; -} - -- (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload -{ - [[OCNetworking sharedManager] shareUpdateAccount:appDelegate.activeAccount shareID:[share integerValue] password:password permission:permission expirationTime:expirationTime hideDownload:hideDownload completion:^(NSString *account, NSString *message, NSInteger errorCode) { - - if (errorCode != 0) { - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - - [self reloadDatasource]; - }]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Reload Data ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)reloadDatasource -{ - // bugfix - if (!self.serverUrl || !self.metadata) { - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - [self.delegate readShareServer]; - [self dismissViewControllerAnimated:YES completion:nil]; - }); - - return; - } - - XLFormRowDescriptor *rowShareLinkSwitch = [self.form formRowWithTag:@"shareLinkSwitch"]; - XLFormRowDescriptor *rowShareLinkPermission = [self.form formRowWithTag:@"shareLinkPermission"]; - XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"]; - XLFormRowDescriptor *rowHideDownload = [self.form formRowWithTag:@"hideDownload"]; - XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"]; - XLFormRowDescriptor *rowExpirationDateSwitch = [self.form formRowWithTag:@"expirationDateSwitch"]; - XLFormRowDescriptor *rowSendLinkTo = [self.form formRowWithTag:@"sendLinkTo"]; - XLFormRowDescriptor *rowFindUser = [self.form formRowWithTag:@"findUser"]; - - NSString *path = [CCUtility returnFileNamePathFromFileName:self.metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl]; - - [[OCNetworking sharedManager] readShareWithAccount:appDelegate.activeAccount path:path completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) { - - if (errorCode == 0) { - - [appDelegate.sharesID removeAllObjects]; - - for (OCSharedDto *item in items) { - [appDelegate.sharesID setObject:item forKey:[@(item.idRemoteShared) stringValue]]; - } - - NSArray *result = [[NCManageDatabase sharedInstance] updateShare:appDelegate.sharesID activeUrl:appDelegate.activeUrl account:appDelegate.activeAccount]; - if (result) { - appDelegate.sharesLink = result[0]; - appDelegate.sharesUserAndGroup = result[1]; - } - - self.shareLink = [appDelegate.sharesLink objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]]; - self.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]]; - - self.itemShareLink = [appDelegate.sharesID objectForKey:self.shareLink]; - if ([self.shareUserAndGroup length] > 0) self.itemsUserAndGroupLink = [self.shareUserAndGroup componentsSeparatedByString:@","]; - else self.itemsUserAndGroupLink = nil; - - } else { - - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - - self.form.delegate = nil; - - // Share Link - if ([self.shareLink length] > 0) { - - [rowShareLinkSwitch setValue:@1]; - - rowShareLinkPermission.disabled = @NO; - rowPassword.disabled = @NO; - rowHideDownload.disabled = @NO; - rowExpirationDate.disabled = @NO; - rowExpirationDateSwitch.disabled = @NO; - - rowSendLinkTo.disabled = @NO; - - } else { - - [rowShareLinkSwitch setValue:@0]; - - rowShareLinkPermission.disabled = @YES; - rowPassword.disabled = @YES; - rowHideDownload.disabled = @YES; - rowExpirationDate.disabled = @YES; - rowExpirationDateSwitch.disabled = @YES; - - rowSendLinkTo.disabled = @YES; - } - - // Permission - - if (self.itemShareLink.permissions > 0 && self.itemShareLink.shareType == shareTypeLink) { - switch (self.itemShareLink.permissions) { - case 1: - rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil); - break; - case 3: - rowShareLinkPermission.value = NSLocalizedString(@"_share_link_modify_", nil); - break; - case 4: - rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_", nil); - break; - case 15: - rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_modify_", nil); - break; - default: - break; - } - } else { - rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil); - } - - // Password - if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink) - rowPassword.value = [self.itemShareLink shareWith]; - else - rowPassword.value = @""; - - // Hide Download - if (self.itemShareLink.hideDownload) rowHideDownload.value = @1; - else rowHideDownload.value = @0; - - // Expiration Date - if (self.itemShareLink.expirationDate) { - - rowExpirationDateSwitch.value = @1; - NSDate *expireDate; - - if (self.itemShareLink.expirationDate) expireDate = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate]; - else expireDate = [self tomorrow]; - - rowExpirationDate.value = expireDate; - - } else { - - rowExpirationDateSwitch.value = @0; - rowExpirationDate.value = [self tomorrow]; - } - - // User & Group - XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4]; - [section.formRows removeAllObjects]; - [self.itemsShareWith removeAllObjects]; - - if ([self.itemsUserAndGroupLink count] > 0) { - - for (NSString *idRemoteShared in self.itemsUserAndGroupLink) { - - OCSharedDto *item = [appDelegate.sharesID objectForKey:idRemoteShared]; - - XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:idRemoteShared rowType:XLFormRowDescriptorTypeButton]; - - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"textLabel.textColor"]; - row.action.formSelector = @selector(sharePermissionButton:); - - if (item.shareType == shareTypeGroup) row.title = [item.shareWithDisplayName stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)]; - else row.title = item.shareWithDisplayName; - - //If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it. - if (![item.uidOwner isEqualToString:appDelegate.activeUserID] && ![item.uidFileOwner isEqualToString:appDelegate.activeUserID]) { - row.disabled = @YES; - } - - [section addFormRow:row]; - - // add users - [self.itemsShareWith addObject:item]; - - // shared with you by - if (![item.uidFileOwner isEqualToString:appDelegate.activeUserID]) { - self.labelSharedWithYouBy.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"_shared_with_you_by_", nil), item.displayNameFileOwner]; - } - } - - section.footerTitle = NSLocalizedString(@"_user_sharee_footer_", nil); - - } else { - - section.footerTitle = @""; - } - - // canShare - BOOL canShare = [self.metadata.permissions containsString:k_permission_can_share]; - if (! canShare) { - - rowShareLinkSwitch.disabled = @YES; - rowShareLinkPermission.disabled = @YES; - rowPassword.disabled = @YES; - rowHideDownload.disabled = @YES; - rowExpirationDate.disabled = @YES; - rowExpirationDateSwitch.disabled = @YES; - rowSendLinkTo.disabled = @YES; - rowFindUser.disabled = @YES; - - XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4]; - [section.formRows removeAllObjects]; - } - - self.form.disabled = NO; - - [self.tableView reloadData]; - - self.form.delegate = self; - }]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Change Value & Button ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)sendLinkTo:(XLFormRowDescriptor *)sender -{ - [self deselectFormRow:sender]; - - NSString *sharedLink = self.itemShareLink.token; - NSString *url; - - if ([sharedLink hasPrefix:@"http://"] || [sharedLink hasPrefix:@"https://"]) { - - url = sharedLink; - - } else if (self.itemShareLink.url) { - - url = self.itemShareLink.url; - - } else { - - url = [NSString stringWithFormat:@"%@/%@%@", appDelegate.activeUrl, k_share_link_middle_part_url_after_version_8, sharedLink]; - - } - - NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]]; - NSArray *applicationActivities = nil; - - UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities]; - - activityController.popoverPresentationController.sourceView = self.view; - NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender]; - CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath]; - activityController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y); - - [self presentViewController:activityController animated:YES completion:nil]; -} - -- (void)shareUserButton:(XLFormRowDescriptor *)rowDescriptor -{ - [self deselectFormRow:rowDescriptor]; - - self.shareUserOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareUserOC"]; - self.shareUserOC.metadata = self.metadata; - self.shareUserOC.serverUrl = self.serverUrl; - self.shareUserOC.itemsShareWith = self.itemsShareWith; - self.shareUserOC.isDirectory = self.metadata.directory; - - [self.shareUserOC setModalPresentationStyle:UIModalPresentationFormSheet]; - [self presentViewController:self.shareUserOC animated:YES completion:NULL]; -} - -- (void)sharePermissionButton:(XLFormRowDescriptor *)rowDescriptor -{ - [self deselectFormRow:rowDescriptor]; - - self.sharePermissionOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCSharePermissionOC"]; - self.sharePermissionOC.idRemoteShared = rowDescriptor.tag; - self.sharePermissionOC.metadata = self.metadata; - self.sharePermissionOC.serverUrl = self.serverUrl; - - [self.sharePermissionOC setModalPresentationStyle:UIModalPresentationFormSheet]; - [self presentViewController:self.sharePermissionOC animated:YES completion:NULL]; -} - -- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue -{ - [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue]; - - //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink]; - - if ([rowDescriptor.tag isEqualToString:@"shareLinkSwitch"]) { - - if ([[rowDescriptor.value valueData] boolValue] == YES) { - - if (capabilities.isFilesSharingPublicPasswordEnforced == YES) { - - __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_enforce_password_protection_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; - [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.secureTextEntry = true; - [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; - }]; - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { - [self reloadDatasource]; - }]; - UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - NSString *password = alertController.textFields.firstObject.text; - XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"]; - rowPassword.value = password; - [self share:self.metadata serverUrl:self.serverUrl password:password permission:1 hideDownload:false]; - [self disableForm]; - }]; - - okAction.enabled = NO; - - [alertController addAction:cancelAction]; - [alertController addAction:okAction]; - - [self presentViewController:alertController animated:YES completion:nil]; - - } else { - - [self share:self.metadata serverUrl:self.serverUrl password:@"" permission:1 hideDownload:false]; - [self disableForm]; - } - - } else { - - // unshare - [self unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl]; - [self disableForm]; - } - } - - if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) { - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:[self getShareLinkPermission:newValue] hideDownload:false]; - [self disableForm]; - } - - if ([rowDescriptor.tag isEqualToString:@"hideDownload"]) { - - BOOL hideDownload = [newValue boolValue]; - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:0 hideDownload:hideDownload]; - [self disableForm]; - } - - if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) { - - // remove expiration date - if ([[rowDescriptor.value valueData] boolValue] == NO) { - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:@"" permission:0 hideDownload:false]; - [self disableForm]; - - } else { - - // new date - XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"]; - NSString *expirationDate = [self convertDateInServerFormat:rowExpirationDate.value]; - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false]; - [self disableForm]; - } - } -} - -- (void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath -{ - long long idRemoteShared = [formRow.tag longLongValue]; - - if ([formRow.rowType isEqualToString:@"button"] && idRemoteShared > 0) { - - [self unShare:formRow.tag metadata:self.metadata serverUrl:self.serverUrl]; - [self disableForm]; - } -} - -- (void)beginEditing:(XLFormRowDescriptor *)rowDescriptor -{ - [super beginEditing:rowDescriptor]; - - if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) { - - self.endButton.enabled = NO; - } -} - -- (void)endEditing:(XLFormRowDescriptor *)rowDescriptor -{ - [super endEditing:rowDescriptor]; - - //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink]; - - if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) { - - NSDate *old = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate]; - NSDate *new = rowDescriptor.value; - - if ([old compare:new] != NSOrderedSame) { - - NSString *expirationDate = [self convertDateInServerFormat:rowDescriptor.value]; - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false]; - [self disableForm]; - } - - self.endButton.enabled = YES; - } - - if ([rowDescriptor.tag isEqualToString:@"password"]) { - - NSString *password = rowDescriptor.value; - - // Public Password Enforced Test - if (capabilities.isFilesSharingPublicPasswordEnforced == YES && password == nil) { - - [appDelegate messageNotification:@"_share_link_" description:@"_password_obligatory_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError]; - - [self reloadDatasource]; - - } else { - - // if the password is not changed or is 0 lenght - if ([[self.itemShareLink shareWith] isEqualToString:password]) { - - [self reloadDatasource]; - - } else { - - if (password == nil) - password = @""; - - if (self.shareLink) { - - [self updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:password expirationTime:nil permission:0 hideDownload:false]; - [self disableForm]; - } - } - } - } -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Button ===== -#pragma -------------------------------------------------------------------------------------------- - -- (IBAction)endButtonAction:(id)sender -{ - [self.tableView endEditing:YES]; - - [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD]; - - [self.delegate readShareServer]; - - [self dismissViewControllerAnimated:YES completion:nil]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Utility ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)minCharTextFieldDidChange:(UITextField *)sender -{ - UIAlertController *alertController = (UIAlertController *)self.presentedViewController; - - if (alertController) { - UITextField *password = alertController.textFields.firstObject; - UIAlertAction *okAction = alertController.actions.lastObject; - okAction.enabled = password.text.length >= 8; - } -} - --(void)disableForm -{ - self.form.disabled = YES; - [self.tableView endEditing:YES]; - [self.tableView reloadData]; -} - -- (NSString *)convertDateInServerFormat:(NSDate *)date { - - NSDateFormatter *dateFormatter = [NSDateFormatter new]; - - [dateFormatter setDateFormat:@"YYYY-MM-dd"]; - - return [dateFormatter stringFromDate:date]; -} - --(NSDate *)tomorrow -{ - NSDate *now = [NSDate date]; - int daysToAdd = 1; - return [now dateByAddingTimeInterval:60*60*24*daysToAdd]; -} - -- (NSInteger)getShareLinkPermission:(NSString *)value -{ - if ([value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) { - return 1; - } else if ([value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) { - return 3; - } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) { - return 4; - } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) { - return 15; - } else { - return 1; - } -} - -@end diff --git a/iOSClient/Share/CCSharePermissionOC.h b/iOSClient/Share/CCSharePermissionOC.h deleted file mode 100644 index 73cafd0ee..000000000 --- a/iOSClient/Share/CCSharePermissionOC.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// CCSharePermissionOC.h -// Nextcloud -// -// Created by Marino Faggiana on 07/03/16. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import - -#import "XLFormViewController.h" -#import "OCShareUser.h" -#import "UtilsFramework.h" - -@class tableMetadata; - -@interface CCSharePermissionOC : XLFormViewController - -@property (nonatomic, weak) IBOutlet UIButton *endButton; -@property (nonatomic, strong) NSString *idRemoteShared; -@property (nonatomic, strong) tableMetadata *metadata; -@property (nonatomic, strong) NSString *serverUrl; - -- (IBAction)endButtonAction:(id)sender; - -@end diff --git a/iOSClient/Share/CCSharePermissionOC.m b/iOSClient/Share/CCSharePermissionOC.m deleted file mode 100644 index 1615b9ee9..000000000 --- a/iOSClient/Share/CCSharePermissionOC.m +++ /dev/null @@ -1,205 +0,0 @@ -// -// CCSharePermissionOC.m -// Nextcloud -// -// Created by Marino Faggiana on 07/03/16. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import "CCSharePermissionOC.h" -#import "AppDelegate.h" -#import "NCBridgeSwift.h" - -@interface CCSharePermissionOC () -{ - AppDelegate *appDelegate; - OCSharedDto *shareDto; -} -@end - -@implementation CCSharePermissionOC - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super initWithCoder:coder]; - if (self) { - - appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - } - return self; -} - -- (void)initializeForm -{ - XLFormDescriptor *form ; - XLFormSectionDescriptor *section; - XLFormRowDescriptor *row; - - form = [XLFormDescriptor formDescriptor]; - form.rowNavigationOptions = XLFormRowNavigationOptionNone; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"edit" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_edit_", nil)]; - if ([UtilsFramework isAnyPermissionToEdit:shareDto.permissions]) row.value = @1; - else row.value = @0; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - if (shareDto.isDirectory) { - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)]; - row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"]; - if ([UtilsFramework isPermissionToCanCreate:shareDto.permissions]) row.value = @1; - else row.value = @0; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)]; - row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"]; - if ([UtilsFramework isPermissionToCanChange:shareDto.permissions]) row.value = @1; - else row.value = @0; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)]; - row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"]; - if ([UtilsFramework isPermissionToCanDelete:shareDto.permissions]) row.value = @1; - else row.value = @0; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - } - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)]; - if ([UtilsFramework isPermissionToCanShare:shareDto.permissions]) row.value = @1; - else row.value = @0; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"]; - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharepath" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_path_", nil)]; - row.value = self.metadata.fileNameView; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)]; - if (shareDto.shareType == shareTypeUser) row.value = NSLocalizedString(@"_share_permission_typeuser_", nil); - if (shareDto.shareType == shareTypeGroup) row.value = NSLocalizedString(@"_share_permission_typegroup_", nil); - if (shareDto.shareType == shareTypeLink) row.value = NSLocalizedString(@"_share_permission_typepubliclink_", nil); - if (shareDto.shareType == shareTypeRemote) row.value = NSLocalizedString(@"_share_permission_typefederated_", nil); - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareowner" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_owner_", nil)]; - row.value = shareDto.displayNameOwner; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharedate" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_date_", nil)]; - NSDate *date = [NSDate dateWithTimeIntervalSince1970:shareDto.sharedDate]; - row.value = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharemail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_email_", nil)]; - if (shareDto.mailSend == 0) row.value = NSLocalizedString(@"_no_", nil); - if (shareDto.mailSend == 1) row.value = NSLocalizedString(@"_yes_", nil); - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"]; - [section addFormRow:row]; - - self.form = form; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal]; - self.endButton.tintColor = [UIColor blackColor]; - - self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - shareDto = [appDelegate.sharesID objectForKey:self.idRemoteShared]; - - [self initializeForm]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Networking ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload -{ - [[OCNetworking sharedManager] shareUpdateAccount:appDelegate.activeAccount shareID:[share integerValue] password:password permission:permission expirationTime:expirationTime hideDownload:hideDownload completion:^(NSString *account, NSString *message, NSInteger errorCode) { - - if (errorCode != 0) { - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - - [self dismissViewControllerAnimated:YES completion:nil]; - }]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Button ===== -#pragma -------------------------------------------------------------------------------------------- - -- (IBAction)endButtonAction:(id)sender -{ - NSInteger permission; - - XLFormRowDescriptor *rowEdit = [self.form formRowWithTag:@"edit"]; - XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"]; - XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"]; - XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"]; - XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"]; - - if ([rowEdit.value boolValue] == 0) - permission = [UtilsFramework getPermissionsValueByCanEdit:NO andCanCreate:NO andCanChange:NO andCanDelete:NO andCanShare:[rowShare.value boolValue] andIsFolder:shareDto.isDirectory]; - else - permission = [UtilsFramework getPermissionsValueByCanEdit:[rowEdit.value boolValue] andCanCreate:[rowCreate.value boolValue] andCanChange:[rowChange.value boolValue] andCanDelete:[rowDelete.value boolValue] andCanShare:[rowShare.value boolValue] andIsFolder:shareDto.isDirectory]; - - if (permission != shareDto.permissions) { - [self updateShare:self.idRemoteShared metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:permission hideDownload:false]; - } else { - [self dismissViewControllerAnimated:YES completion:nil]; - } -} - -@end diff --git a/iOSClient/Share/CCShareUserOC.h b/iOSClient/Share/CCShareUserOC.h deleted file mode 100644 index 5f770c50d..000000000 --- a/iOSClient/Share/CCShareUserOC.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// CCShareUserOC.h -// Nextcloud -// -// Created by Marino Faggiana on 30/11/15. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import - -#import "XLFormViewController.h" -#import "OCShareUser.h" -#import "OCConstants.h" - -@class tableMetadata; - -@interface CCShareUserOC : XLFormViewController - -@property (nonatomic, weak) IBOutlet UIButton *endButton; - -@property (nonatomic, strong) NSMutableArray *selectedItems; -@property (nonatomic, strong) NSArray *itemsShareWith; -@property (nonatomic, strong) NSMutableArray *users; -@property (nonatomic, strong) NSString *directUser; -@property (nonatomic, strong) tableMetadata *metadata; -@property (nonatomic, strong) NSString *serverUrl; - -@property BOOL isDirectory; -@property NSInteger shareType; - -- (IBAction)endButtonAction:(id)sender; - -- (void)reloadUserAndGroup:(NSArray *)items; - -@end diff --git a/iOSClient/Share/CCShareUserOC.m b/iOSClient/Share/CCShareUserOC.m deleted file mode 100644 index e3c125a3b..000000000 --- a/iOSClient/Share/CCShareUserOC.m +++ /dev/null @@ -1,268 +0,0 @@ -// -// CCShareUserOC.m -// Nextcloud -// -// Created by Marino Faggiana on 30/11/15. -// Copyright (c) 2017 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#import "CCShareUserOC.h" -#import "AppDelegate.h" -#import "NCBridgeSwift.h" - -@interface CCShareUserOC () -{ - AppDelegate *appDelegate; -} -@end - -@implementation CCShareUserOC - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super initWithCoder:coder]; - if (self) { - - appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - - self.directUser = @""; - - [self initializeForm]; - } - return self; -} - -- (void)initializeForm -{ - XLFormDescriptor *form ; - XLFormSectionDescriptor *section; - XLFormRowDescriptor *row; - - form = [XLFormDescriptor formDescriptor]; - form.rowNavigationOptions = XLFormRowNavigationOptionNone; - form.assignFirstResponderOnShow = NO; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_find_sharee_title_", nil)]; - [form addFormSection:section]; - section.footerTitle = NSLocalizedString(@"_find_sharee_footer_", nil); - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeAccount]; - [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_find_sharee_", nil) forKey:@"textField.placeholder"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"]; - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_direct_sharee_title_", nil)]; - [form addFormSection:section]; - section.footerTitle = NSLocalizedString(@"_direct_sharee_footer_", nil); - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"directUser" rowType:XLFormRowDescriptorTypeAccount]; - [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_direct_sharee_", nil) forKey:@"textField.placeholder"]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"]; - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_type_title_", nil)]; - [form addFormSection:section]; - - row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareType" rowType:XLFormRowDescriptorTypePicker]; - row.selectorOptions = @[NSLocalizedString(@"_share_type_user_", nil), NSLocalizedString(@"_share_type_group_", nil), NSLocalizedString(@"_share_type_remote_", nil)]; - row.value = NSLocalizedString(@"_share_type_user_", nil); - self.shareType = shareTypeUser; - row.height = 100; - [section addFormRow:row]; - - section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - - self.form = form; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.selectedItems = [[NSMutableArray alloc] init]; - - self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView; - - [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal]; - self.endButton.tintColor = [UIColor blackColor]; - - self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Networking ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl -{ - NSString *fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl]; - - [[OCNetworking sharedManager] shareUserGroupWithAccount:appDelegate.activeAccount userOrGroup:user fileName:fileName permission:permission shareeType:shareeType completion:^(NSString *account, NSString *message, NSInteger errorCode) { - - if (errorCode != 0) { - [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - }]; -} - -- (void)getUserAndGroup:(NSString *)find -{ - [[OCNetworking sharedManager] getUserGroupWithAccount:appDelegate.activeAccount searchString:find completion:^(NSString *account, NSArray *item, NSString *message, NSInteger errorCode) { - - if (errorCode == 0) { - [self reloadUserAndGroup:item]; - } else { - [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode]; - } - }]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Button ===== -#pragma -------------------------------------------------------------------------------------------- - -- (IBAction)endButtonAction:(id)sender -{ - NSInteger permission; - - if (self.isDirectory) permission = k_max_folder_share_permission; - else permission = k_max_file_share_permission; - - // start share of select users - for (NSString *num in self.selectedItems) { - - // fix #166 Crashlytics - if (self.users.count > 0 && [num integerValue] < self.users.count) { - - OCShareUser *item = [self.users objectAtIndex:[num integerValue]]; - [self shareUserAndGroup:item.name shareeType:item.shareeType permission:permission metadata:self.metadata serverUrl:self.serverUrl]; - } - } - - // add manual user - if ([self.directUser isEqual:[NSNull null]] == NO && [self.directUser length] > 0 && [self.directUser isEqualToString:appDelegate.activeUser] == NO) { - [self shareUserAndGroup:self.directUser shareeType:self.shareType permission:permission metadata:self.metadata serverUrl:self.serverUrl]; - } - - [self dismissViewControllerAnimated:YES completion:nil]; -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Change Value ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue -{ - [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue]; - - if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) { - - if ([newValue boolValue] == YES) - [self.selectedItems addObject:rowDescriptor.tag]; - if ([newValue boolValue] == NO) - [self.selectedItems removeObject:rowDescriptor.tag]; - } - - if ([rowDescriptor.tag isEqualToString:@"directUser"]) { - - self.directUser = newValue; - } - - if ([rowDescriptor.tag isEqualToString:@"shareType"]){ - - if ([newValue isEqualToString:NSLocalizedString(@"_share_type_user_", nil)]) - self.shareType = shareTypeUser; - if ([newValue isEqualToString:NSLocalizedString(@"_share_type_group_", nil)]) - self.shareType = shareTypeGroup; - if ([newValue isEqualToString:NSLocalizedString(@"_share_type_remote_", nil)]) - self.shareType = shareTypeRemote; - } -} - -- (void)endEditing:(XLFormRowDescriptor *)rowDescriptor -{ - [super endEditing:rowDescriptor]; - - if ([rowDescriptor.tag isEqualToString:@"findUser"]) { - - rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; - - if ([rowDescriptor.value length] > 1) - [self getUserAndGroup:rowDescriptor.value]; - } -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Delegate ===== -#pragma -------------------------------------------------------------------------------------------- - -- (void)reloadUserAndGroup:(NSArray *)items -{ - self.users = [[NSMutableArray alloc] initWithArray:items]; - - self.form.delegate = nil; - - // remove the select users and i - for (OCShareUser *user in items) { - - for (OCSharedDto *item in self.itemsShareWith) - if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0))) - [self.users removeObject:user]; - - if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:appDelegate.activeUser]) - [self.users removeObject:user]; - } - - XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1]; - [section.formRows removeAllObjects]; - - for (OCShareUser *item in self.users) { - - NSInteger num = [self.users indexOfObject:item]; - - NSString *title; - - if (item.shareeType == 1) { - if (item.displayName) - title = [item.displayName stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)]; - else - title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)]; - } else { - if (item.displayName) - title = item.displayName; - else - title = item.name; - } - - XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title]; - [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"]; - [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"self.tintColor"]; - - [section addFormRow:row]; - } - - [self.tableView reloadData]; - - self.form.delegate = self; -} - -@end diff --git a/iOSClient/Share/NCShare.storyboard b/iOSClient/Share/NCShare.storyboard index 46bb8b1c2..20203df84 100644 --- a/iOSClient/Share/NCShare.storyboard +++ b/iOSClient/Share/NCShare.storyboard @@ -71,22 +71,17 @@ - + + + + - @@ -129,17 +124,15 @@ - - + - @@ -162,7 +155,6 @@ - @@ -176,7 +168,6 @@ - diff --git a/iOSClient/Share/NCShare.swift b/iOSClient/Share/NCShare.swift index 0557f9af1..8a68e73d1 100644 --- a/iOSClient/Share/NCShare.swift +++ b/iOSClient/Share/NCShare.swift @@ -28,7 +28,6 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint! @IBOutlet weak var searchField: UITextField! - @IBOutlet weak var returnSearchButton: UIButton! @IBOutlet weak var shareLinkImage: UIImageView! @IBOutlet weak var shareLinkLabel: UILabel! @IBOutlet weak var buttonCopy: UIButton! @@ -50,7 +49,6 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "") - returnSearchButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "arrowRight"), width: 100, height: 100, color: UIColor.gray), for: .normal) shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "") shareLinkImage.image = NCShareCommon.sharedInstance.createLinkAvatar() buttonCopy.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareCopy"), width: 100, height: 100, color: UIColor.gray), for: .normal) @@ -77,6 +75,28 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel shareUserMenuView = nil } + @objc func reloadData() { + let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!) + if shares.firstShareLink == nil { + buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareAdd"), width: 100, height: 100, color: UIColor.gray), for: .normal) + buttonCopy.isHidden = true + } else { + buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMenu"), width: 100, height: 100, color: UIColor.gray), for: .normal) + buttonCopy.isHidden = false + } + tableView.reloadData() + } + + // MARK: - IBAction + + @IBAction func searchFieldDidEndOnExit(textField: UITextField) { + + guard let searchString = textField.text else { return } + + let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self.view, delegate: self) + networking.getUserAndGroup(searchString: searchString) + } + @IBAction func touchUpInsideButtonCopy(_ sender: Any) { let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!) tapCopy(with: shares.firstShareLink, sender: sender) @@ -133,19 +153,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel } } - @objc func reloadData() { - let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!) - if shares.firstShareLink == nil { - buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareAdd"), width: 100, height: 100, color: UIColor.gray), for: .normal) - buttonCopy.isHidden = true - } else { - buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMenu"), width: 100, height: 100, color: UIColor.gray), for: .normal) - buttonCopy.isHidden = false - } - tableView.reloadData() - } + /// MARK: - NCShareNetworkingDelegate - // NCShareNetworkingDelegate func readShareCompleted(errorCode: Int) { NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadDataNCShare"), object: nil, userInfo: nil) } @@ -157,6 +166,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel func unShareCompleted() { } func updateShareWithError(idRemoteShared: Int) { } + + func getUserAndGroup(items: [OCShareUser]?) { } } // MARK: - UITableViewDelegate diff --git a/iOSClient/Share/NCShareLinkMenuView.swift b/iOSClient/Share/NCShareLinkMenuView.swift index 041bdf24d..ce83208d1 100644 --- a/iOSClient/Share/NCShareLinkMenuView.swift +++ b/iOSClient/Share/NCShareLinkMenuView.swift @@ -266,6 +266,8 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin reloadData(idRemoteShared: idRemoteShared) } + func getUserAndGroup(items: [OCShareUser]?) { } + // MARK: - Delegate calendar func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index 5e8168937..37cfd35f2 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -101,6 +101,20 @@ class NCShareNetworking: NSObject { } }) } + + func getUserAndGroup(searchString: String) { + NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0) + OCNetworking.sharedManager()?.getUserGroup(withAccount: account, search: searchString, completion: { (account, items, message, errorCode) in + NCUtility.sharedInstance.stopActivityIndicator() + if errorCode == 0 { + let itemsOCShareUser = items as! [OCShareUser] + self.delegate?.getUserAndGroup(items: itemsOCShareUser) + } else { + self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode) + self.delegate?.getUserAndGroup(items: nil) + } + }) + } } protocol NCShareNetworkingDelegate { @@ -108,4 +122,5 @@ protocol NCShareNetworkingDelegate { func shareCompleted(errorCode: Int) func unShareCompleted() func updateShareWithError(idRemoteShared: Int) + func getUserAndGroup(items: [OCShareUser]?) } diff --git a/iOSClient/Share/NCShareUserMenuView.swift b/iOSClient/Share/NCShareUserMenuView.swift index 683a68199..1a36f2b25 100644 --- a/iOSClient/Share/NCShareUserMenuView.swift +++ b/iOSClient/Share/NCShareUserMenuView.swift @@ -202,6 +202,8 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin reloadData(idRemoteShared: idRemoteShared) } + func getUserAndGroup(items: [OCShareUser]?) { } + // MARK: - Delegate calendar func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { -- cgit v1.2.3