CCShareUserOC.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. [self.view setTintColor:COLOR_BRAND];
  78. self.view.backgroundColor = COLOR_NAVIGATIONBAR_SHARE;
  79. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  80. self.endButton.tintColor = COLOR_NAVIGATIONBAR_TEXT;
  81. }
  82. #pragma --------------------------------------------------------------------------------------------
  83. #pragma mark ===== Button =====
  84. #pragma --------------------------------------------------------------------------------------------
  85. - (IBAction)endButtonAction:(id)sender
  86. {
  87. NSInteger permission;
  88. if (self.isDirectory) permission = k_max_folder_share_permission;
  89. else permission = k_max_file_share_permission;
  90. // start share of select users
  91. for (NSString *num in self.selectedItems) {
  92. OCShareUser *item = [self.users objectAtIndex:[num integerValue]];
  93. [self.delegate shareUserAndGroup:item.name shareeType:item.shareeType permission:permission];
  94. }
  95. // start share with a user if not be i
  96. if ([self.directUser isEqual:[NSNull null]] == NO) {
  97. if ([self.directUser length] > 0 && [self.directUser isEqualToString:app.activeUser] == NO) {
  98. // User/Group/Federate
  99. [self.delegate shareUserAndGroup:self.directUser shareeType:self.shareType permission:permission];
  100. }
  101. }
  102. [self dismissViewControllerAnimated:YES completion:nil];
  103. }
  104. #pragma --------------------------------------------------------------------------------------------
  105. #pragma mark ===== Change Value =====
  106. #pragma --------------------------------------------------------------------------------------------
  107. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  108. {
  109. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  110. if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) {
  111. if ([newValue boolValue] == YES)
  112. [self.selectedItems addObject:rowDescriptor.tag];
  113. if ([newValue boolValue] == NO)
  114. [self.selectedItems removeObject:rowDescriptor.tag];
  115. }
  116. if ([rowDescriptor.tag isEqualToString:@"directUser"]) {
  117. self.directUser = newValue;
  118. }
  119. if ([rowDescriptor.tag isEqualToString:@"shareType"]){
  120. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_user_", nil)])
  121. self.shareType = shareTypeUser;
  122. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_group_", nil)])
  123. self.shareType = shareTypeGroup;
  124. if ([newValue isEqualToString:NSLocalizedString(@"_share_type_remote_", nil)])
  125. self.shareType = shareTypeRemote;
  126. }
  127. }
  128. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  129. {
  130. [super endEditing:rowDescriptor];
  131. if ([rowDescriptor.tag isEqualToString:@"findUser"]) {
  132. rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  133. if ([rowDescriptor.value length] > 1)
  134. [self.delegate getUserAndGroup:rowDescriptor.value];
  135. }
  136. }
  137. #pragma --------------------------------------------------------------------------------------------
  138. #pragma mark ===== Delegate =====
  139. #pragma --------------------------------------------------------------------------------------------
  140. - (void)reloadUserAndGroup:(NSArray *)items
  141. {
  142. self.users = [[NSMutableArray alloc] initWithArray:items];
  143. self.form.delegate = nil;
  144. // remove the select users and i
  145. for (OCShareUser *user in items) {
  146. for (OCSharedDto *item in self.itemsShareWith)
  147. if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0)))
  148. [self.users removeObject:user];
  149. if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:app.activeUser])
  150. [self.users removeObject:user];
  151. }
  152. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1];
  153. [section.formRows removeAllObjects];
  154. for (OCShareUser *item in self.users) {
  155. NSInteger num = [self.users indexOfObject:item];
  156. NSString *title;
  157. if (item.shareeType == 1) title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  158. else title = item.name;
  159. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  160. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  161. [row.cellConfig setObject:COLOR_BRAND forKey:@"self.tintColor"];
  162. [section addFormRow:row];
  163. }
  164. [self.tableView reloadData];
  165. self.form.delegate = self;
  166. }
  167. @end