CCShareUserOC.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 = YES;
  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:XLFormRowDescriptorTypeName];
  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:XLFormRowDescriptorTypeName];
  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 formSection];
  62. [form addFormSection:section];
  63. self.form = form;
  64. }
  65. - (void)viewDidLoad
  66. {
  67. [super viewDidLoad];
  68. self.selectedItems = [[NSMutableArray alloc] init];
  69. // Color
  70. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  71. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  72. // Done
  73. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  74. self.endButton.tintColor = [COLOR_BRAND colorWithAlphaComponent:0.8];
  75. [self.view setTintColor:COLOR_BRAND];
  76. }
  77. #pragma --------------------------------------------------------------------------------------------
  78. #pragma mark ===== Button =====
  79. #pragma --------------------------------------------------------------------------------------------
  80. - (IBAction)endButtonAction:(id)sender
  81. {
  82. NSInteger permission;
  83. if (self.isDirectory) permission = k_max_folder_share_permission;
  84. else permission = k_max_file_share_permission;
  85. // start share of select users
  86. for (NSString *num in self.selectedItems) {
  87. OCShareUser *item = [self.users objectAtIndex:[num integerValue]];
  88. [self.delegate shareUserAndGroup:item.name shareeType:item.shareeType permission:permission];
  89. }
  90. // start share with a user if not be i
  91. if ([self.directUser isEqual:[NSNull null]] == NO) {
  92. if ([self.directUser length] > 0 && [self.directUser isEqualToString:app.activeUser] == NO) {
  93. [self.delegate shareUserAndGroup:self.directUser shareeType:0 permission:permission];
  94. }
  95. }
  96. [self dismissViewControllerAnimated:YES completion:nil];
  97. }
  98. #pragma --------------------------------------------------------------------------------------------
  99. #pragma mark ===== Change Value =====
  100. #pragma --------------------------------------------------------------------------------------------
  101. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  102. {
  103. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  104. if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeBooleanCheck]) {
  105. if ([newValue boolValue] == YES)
  106. [self.selectedItems addObject:rowDescriptor.tag];
  107. if ([newValue boolValue] == NO)
  108. [self.selectedItems removeObject:rowDescriptor.tag];
  109. }
  110. if ([rowDescriptor.tag isEqualToString:@"directUser"]) {
  111. self.directUser = newValue;
  112. }
  113. }
  114. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  115. {
  116. [super endEditing:rowDescriptor];
  117. if ([rowDescriptor.tag isEqualToString:@"findUser"]) {
  118. rowDescriptor.value = [rowDescriptor.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  119. if ([rowDescriptor.value length] > 1)
  120. [self.delegate getUserAndGroup:rowDescriptor.value];
  121. }
  122. }
  123. #pragma --------------------------------------------------------------------------------------------
  124. #pragma mark ===== Delegate =====
  125. #pragma --------------------------------------------------------------------------------------------
  126. - (void)reloadUserAndGroup:(NSArray *)items
  127. {
  128. self.users = [[NSMutableArray alloc] initWithArray:items];
  129. self.form.delegate = nil;
  130. // remove the select users and i
  131. for (OCShareUser *user in items) {
  132. for (OCSharedDto *item in self.itemsShareWith)
  133. if ([item.shareWith isEqualToString:user.name] && ((item.shareType == shareTypeGroup && user.shareeType == 1) || (item.shareType != shareTypeGroup && user.shareeType == 0)))
  134. [self.users removeObject:user];
  135. if ([self.itemsShareWith containsObject:user.name] || [user.name isEqualToString:app.activeUser])
  136. [self.users removeObject:user];
  137. }
  138. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:1];
  139. [section.formRows removeAllObjects];
  140. for (OCShareUser *item in self.users) {
  141. NSInteger num = [self.users indexOfObject:item];
  142. NSString *title;
  143. if (item.shareeType == 1) title = [item.name stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  144. else title = item.name;
  145. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:[@(num) stringValue] rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  146. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  147. [row.cellConfig setObject:COLOR_BRAND forKey:@"self.tintColor"];
  148. [section addFormRow:row];
  149. }
  150. [self.tableView reloadData];
  151. self.form.delegate = self;
  152. }
  153. @end