CCShareUserOC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // CCShareUserOC.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 30/11/15.
  6. // Copyright (c) 2014 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. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCShareUserOC ()
  31. @end
  32. @implementation CCShareUserOC
  33. - (instancetype)initWithCoder:(NSCoder *)coder
  34. {
  35. self = [super initWithCoder:coder];
  36. if (self) {
  37. self.directUser = @"";
  38. [self initializeForm];
  39. }
  40. return self;
  41. }
  42. - (void)initializeForm
  43. {
  44. XLFormDescriptor *form ;
  45. XLFormSectionDescriptor *section;
  46. XLFormRowDescriptor *row;
  47. form = [XLFormDescriptor formDescriptor];
  48. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  49. form.assignFirstResponderOnShow = NO;
  50. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_find_sharee_title_", nil)];
  51. [form addFormSection:section];
  52. section.footerTitle = NSLocalizedString(@"_find_sharee_footer_", nil);
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeAccount];
  54. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_find_sharee_", nil) forKey:@"textField.placeholder"];
  55. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  56. [section addFormRow:row];
  57. section = [XLFormSectionDescriptor formSection];
  58. [form addFormSection:section];
  59. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_direct_sharee_title_", nil)];
  60. [form addFormSection:section];
  61. section.footerTitle = NSLocalizedString(@"_direct_sharee_footer_", nil);
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"directUser" rowType:XLFormRowDescriptorTypeAccount];
  63. [row.cellConfigAtConfigure setObject:NSLocalizedString(@"_direct_sharee_", nil) forKey:@"textField.placeholder"];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  65. [section addFormRow:row];
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_type_title_", nil)];
  67. [form addFormSection:section];
  68. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareType" rowType:XLFormRowDescriptorTypePicker];
  69. row.selectorOptions = @[NSLocalizedString(@"_share_type_user_", nil), NSLocalizedString(@"_share_type_group_", nil), NSLocalizedString(@"_share_type_remote_", nil)];
  70. row.value = NSLocalizedString(@"_share_type_user_", nil);
  71. self.shareType = shareTypeUser;
  72. row.height = 100;
  73. [section addFormRow:row];
  74. section = [XLFormSectionDescriptor formSection];
  75. [form addFormSection:section];
  76. self.form = form;
  77. }
  78. - (void)viewDidLoad
  79. {
  80. [super viewDidLoad];
  81. self.selectedItems = [[NSMutableArray alloc] init];
  82. [self.view setTintColor:[NCColorBrand sharedInstance].brand];
  83. self.view.backgroundColor = [NCColorBrand sharedInstance].navigationBarShare;
  84. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  85. self.endButton.tintColor = [NCColorBrand sharedInstance].navigationBarText;
  86. self.tableView.backgroundColor = [NCColorBrand sharedInstance].tableBackground;
  87. }
  88. #pragma --------------------------------------------------------------------------------------------
  89. #pragma mark ===== Button =====
  90. #pragma --------------------------------------------------------------------------------------------
  91. - (IBAction)endButtonAction:(id)sender
  92. {
  93. NSInteger permission;
  94. if (self.isDirectory) permission = k_max_folder_share_permission;
  95. else permission = k_max_file_share_permission;
  96. // start share of select users
  97. for (NSString *num in self.selectedItems) {
  98. OCShareUser *item = [self.users objectAtIndex:[num integerValue]];
  99. [self.delegate shareUserAndGroup:item.name shareeType:item.shareeType permission:permission];
  100. }
  101. // start share with a user if not be i
  102. if ([self.directUser isEqual:[NSNull null]] == NO) {
  103. if ([self.directUser length] > 0 && [self.directUser isEqualToString:app.activeUser] == NO) {
  104. // User/Group/Federate
  105. [self.delegate shareUserAndGroup:self.directUser shareeType:self.shareType permission:permission];
  106. }
  107. }
  108. [self dismissViewControllerAnimated:YES completion:nil];
  109. }
  110. #pragma --------------------------------------------------------------------------------------------
  111. #pragma mark ===== Change Value =====
  112. #pragma --------------------------------------------------------------------------------------------
  113. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  114. {
  115. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  116. if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) {
  117. if ([newValue boolValue] == YES)
  118. [self.selectedItems addObject:rowDescriptor.tag];
  119. if ([newValue boolValue] == NO)
  120. [self.selectedItems removeObject:rowDescriptor.tag];
  121. }
  122. if ([rowDescriptor.tag isEqualToString:@"directUser"]) {
  123. self.directUser = newValue;
  124. }
  125. if ([rowDescriptor.tag isEqualToString:@"shareType"]){
  126. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_user_", nil)])
  127. self.shareType = shareTypeUser;
  128. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_group_", nil)])
  129. self.shareType = shareTypeGroup;
  130. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_remote_", nil)])
  131. self.shareType = shareTypeRemote;
  132. }
  133. }
  134. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  135. {
  136. [super endEditing:rowDescriptor];
  137. if ([rowDescriptor.tag isEqualToString:@"findUser"]) {
  138. rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  139. if ([rowDescriptor.value length] > 1)
  140. [self.delegate getUserAndGroup:rowDescriptor.value];
  141. }
  142. }
  143. #pragma --------------------------------------------------------------------------------------------
  144. #pragma mark ===== Delegate =====
  145. #pragma --------------------------------------------------------------------------------------------
  146. - (void)reloadUserAndGroup:(NSArray *)items
  147. {
  148. self.users = [[NSMutableArray alloc] initWithArray:items];
  149. self.form.delegate = nil;
  150. // remove the select users and i
  151. for (OCShareUser *user in items) {
  152. for (OCSharedDto *item in self.itemsShareWith)
  153. if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0)))
  154. [self.users removeObject:user];
  155. if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:app.activeUser])
  156. [self.users removeObject:user];
  157. }
  158. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1];
  159. [section.formRows removeAllObjects];
  160. for (OCShareUser *item in self.users) {
  161. NSInteger num = [self.users indexOfObject:item];
  162. NSString *title;
  163. if (item.shareeType == 1) title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  164. else title = item.name;
  165. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  166. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  167. [row.cellConfig setObject:[NCColorBrand sharedInstance].brand forKey:@"self.tintColor"];
  168. [section addFormRow:row];
  169. }
  170. [self.tableView reloadData];
  171. self.form.delegate = self;
  172. }
  173. @end