CCShareUserOC.m 8.6 KB

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