CCShareUserOC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // CCShareUserOC.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 30/11/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCShareUserOC.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCShareUserOC ()
  27. @end
  28. @implementation CCShareUserOC
  29. - (instancetype)initWithCoder:(NSCoder *)coder
  30. {
  31. self = [super initWithCoder:coder];
  32. if (self) {
  33. self.directUser = @"";
  34. [self initializeForm];
  35. }
  36. return self;
  37. }
  38. - (void)initializeForm
  39. {
  40. XLFormDescriptor *form ;
  41. XLFormSectionDescriptor *section;
  42. XLFormRowDescriptor *row;
  43. form = [XLFormDescriptor formDescriptor];
  44. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  45. form.assignFirstResponderOnShow = NO;
  46. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_find_sharee_title_", nil)];
  47. [form addFormSection:section];
  48. section.footerTitle = NSLocalizedString(@"_find_sharee_footer_", nil);
  49. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeAccount];
  50. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_find_sharee_", nil) forKey:@"textField.placeholder"];
  51. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  52. [section addFormRow:row];
  53. section = [XLFormSectionDescriptor formSection];
  54. [form addFormSection:section];
  55. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_direct_sharee_title_", nil)];
  56. [form addFormSection:section];
  57. section.footerTitle = NSLocalizedString(@"_direct_sharee_footer_", nil);
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"directUser" rowType:XLFormRowDescriptorTypeAccount];
  59. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_direct_sharee_", nil) forKey:@"textField.placeholder"];
  60. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  61. [section addFormRow:row];
  62. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_type_title_", nil)];
  63. [form addFormSection:section];
  64. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareType" rowType:XLFormRowDescriptorTypePicker];
  65. row.selectorOptions = @[NSLocalizedString(@"_share_type_user_", nil), NSLocalizedString(@"_share_type_group_", nil), NSLocalizedString(@"_share_type_remote_", nil)];
  66. row.value = NSLocalizedString(@"_share_type_user_", nil);
  67. self.shareType = shareTypeUser;
  68. row.height = 100;
  69. [section addFormRow:row];
  70. section = [XLFormSectionDescriptor formSection];
  71. [form addFormSection:section];
  72. self.form = form;
  73. }
  74. - (void)viewDidLoad
  75. {
  76. [super viewDidLoad];
  77. self.selectedItems = [[NSMutableArray alloc] init];
  78. self.view.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  79. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  80. self.endButton.tintColor = [NCBrandColor sharedInstance].brand;
  81. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  82. }
  83. #pragma --------------------------------------------------------------------------------------------
  84. #pragma mark ===== Button =====
  85. #pragma --------------------------------------------------------------------------------------------
  86. - (IBAction)endButtonAction:(id)sender
  87. {
  88. NSInteger permission;
  89. if (self.isDirectory) permission = k_max_folder_share_permission;
  90. else permission = k_max_file_share_permission;
  91. // start share of select users
  92. for (NSString *num in self.selectedItems) {
  93. OCShareUser *item = [self.users objectAtIndex:[num integerValue]];
  94. [self.delegate shareUserAndGroup:item.name shareeType:item.shareeType permission:permission];
  95. }
  96. // start share with a user if not be i
  97. if ([self.directUser isEqual:[NSNull null]] == NO) {
  98. if ([self.directUser length] > 0 && [self.directUser isEqualToString:app.activeUser] == NO) {
  99. // User/Group/Federate
  100. [self.delegate shareUserAndGroup:self.directUser shareeType:self.shareType permission:permission];
  101. }
  102. }
  103. [self dismissViewControllerAnimated:YES completion:nil];
  104. }
  105. #pragma --------------------------------------------------------------------------------------------
  106. #pragma mark ===== Change Value =====
  107. #pragma --------------------------------------------------------------------------------------------
  108. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  109. {
  110. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  111. if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) {
  112. if ([newValue boolValue] == YES)
  113. [self.selectedItems addObject:rowDescriptor.tag];
  114. if ([newValue boolValue] == NO)
  115. [self.selectedItems removeObject:rowDescriptor.tag];
  116. }
  117. if ([rowDescriptor.tag isEqualToString:@"directUser"]) {
  118. self.directUser = newValue;
  119. }
  120. if ([rowDescriptor.tag isEqualToString:@"shareType"]){
  121. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_user_", nil)])
  122. self.shareType = shareTypeUser;
  123. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_group_", nil)])
  124. self.shareType = shareTypeGroup;
  125. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_remote_", nil)])
  126. self.shareType = shareTypeRemote;
  127. }
  128. }
  129. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  130. {
  131. [super endEditing:rowDescriptor];
  132. if ([rowDescriptor.tag isEqualToString:@"findUser"]) {
  133. rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  134. if ([rowDescriptor.value length] > 1)
  135. [self.delegate getUserAndGroup:rowDescriptor.value];
  136. }
  137. }
  138. #pragma --------------------------------------------------------------------------------------------
  139. #pragma mark ===== Delegate =====
  140. #pragma --------------------------------------------------------------------------------------------
  141. - (void)reloadUserAndGroup:(NSArray *)items
  142. {
  143. self.users = [[NSMutableArray alloc] initWithArray:items];
  144. self.form.delegate = nil;
  145. // remove the select users and i
  146. for (OCShareUser *user in items) {
  147. for (OCSharedDto *item in self.itemsShareWith)
  148. if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0)))
  149. [self.users removeObject:user];
  150. if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:app.activeUser])
  151. [self.users removeObject:user];
  152. }
  153. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1];
  154. [section.formRows removeAllObjects];
  155. for (OCShareUser *item in self.users) {
  156. NSInteger num = [self.users indexOfObject:item];
  157. NSString *title;
  158. if (item.shareeType == 1) title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  159. else title = item.name;
  160. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  161. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  162. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"self.tintColor"];
  163. [section addFormRow:row];
  164. }
  165. [self.tableView reloadData];
  166. self.form.delegate = self;
  167. }
  168. @end