CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. //
  2. // CCManageAutoUpload.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/09/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCManageAutoUpload.h"
  24. #import "NCAutoUpload.h"
  25. #import "AppDelegate.h"
  26. #import "NCBridgeSwift.h"
  27. @interface CCManageAutoUpload () <NCSelectDelegate>
  28. {
  29. AppDelegate *appDelegate;
  30. }
  31. @end
  32. @implementation CCManageAutoUpload
  33. - (void)initializeForm
  34. {
  35. XLFormDescriptor *form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_autoupload_", nil)];
  36. XLFormSectionDescriptor *section;
  37. XLFormRowDescriptor *row;
  38. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  39. // Auto Upload
  40. section = [XLFormSectionDescriptor formSection];
  41. [form addFormSection:section];
  42. section.footerTitle = NSLocalizedString(@"_autoupload_description_", nil);
  43. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_", nil)];
  44. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  45. if (tableAccount.autoUpload) row.value = @1;
  46. else row.value = @0;
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  49. [section addFormRow:row];
  50. // Auto Upload Directory
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. // Lock active YES/NO
  54. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadDirectory" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_select_folder_", nil)];
  55. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  56. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  57. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folderAutomaticUpload"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  60. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  61. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  62. row.action.formSelector = @selector(selectAutomaticUploadFolder);
  63. [section addFormRow:row];
  64. // Auto Upload Photo
  65. section = [XLFormSectionDescriptor formSection];
  66. [form addFormSection:section];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadImage" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_photos_", nil)];
  68. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  69. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  70. if (tableAccount.autoUploadImage) row.value = @1;
  71. else row.value = @0;
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  73. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  74. [section addFormRow:row];
  75. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  76. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  77. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  78. if (tableAccount.autoUploadWWAnPhoto) row.value = @1;
  79. else row.value = @0;
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  82. [section addFormRow:row];
  83. // Auto Upload Video
  84. section = [XLFormSectionDescriptor formSection];
  85. [form addFormSection:section];
  86. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_videos_", nil)];
  87. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  88. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  89. if (tableAccount.autoUploadVideo) row.value = @1;
  90. else row.value = @0;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  93. [section addFormRow:row];
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
  95. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  96. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  97. if (tableAccount.autoUploadWWAnVideo) row.value = @1;
  98. else row.value = @0;
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  101. [section addFormRow:row];
  102. // Delete asset
  103. section = [XLFormSectionDescriptor formSection];
  104. [form addFormSection:section];
  105. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removePhotoCameraRoll" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_remove_photo_CameraRoll_", nil)];
  106. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  107. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  108. if (tableAccount.autoUploadDeleteAssetLocalIdentifier) row.value = @1;
  109. else row.value = @0;
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  112. [section addFormRow:row];
  113. // Auto Upload Background
  114. section = [XLFormSectionDescriptor formSection];
  115. [form addFormSection:section];
  116. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadBackground" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_background_", nil)];
  117. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  118. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  119. if (tableAccount.autoUploadBackground) row.value = @1;
  120. else row.value = @0;
  121. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  122. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  123. [section addFormRow:row];
  124. // Auto Upload Full
  125. section = [XLFormSectionDescriptor formSection];
  126. [form addFormSection:section];
  127. NSString *title = NSLocalizedString(@"_autoupload_fullphotos_", nil);
  128. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFull" rowType:XLFormRowDescriptorTypeBooleanSwitch title:title];
  129. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  130. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  131. row.value = 0;
  132. if (tableAccount.autoUploadFull) row.value = @1;
  133. else row.value = @0;
  134. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  135. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  136. [section addFormRow:row];
  137. // Auto Upload create subfolder
  138. section = [XLFormSectionDescriptor formSection];
  139. [form addFormSection:section];
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
  141. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  142. row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  143. if (tableAccount.autoUploadCreateSubfolder) row.value = @1;
  144. else row.value = @0;
  145. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  146. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  147. [section addFormRow:row];
  148. // Auto Upload file name
  149. section = [XLFormSectionDescriptor formSection];
  150. [form addFormSection:section];
  151. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFileName" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_autoupload_filenamemask_", nil)];
  152. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  153. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  154. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  155. row.action.viewControllerClass = [NCManageAutoUploadFileName class];
  156. [section addFormRow:row];
  157. // end
  158. section = [XLFormSectionDescriptor formSection];
  159. [form addFormSection:section];
  160. self.tableView.showsVerticalScrollIndicator = NO;
  161. self.form = form;
  162. }
  163. - (void)viewDidLoad
  164. {
  165. [super viewDidLoad];
  166. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  167. // changeTheming
  168. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  169. [self changeTheming];
  170. }
  171. - (void)viewWillAppear:(BOOL)animated
  172. {
  173. [super viewWillAppear:animated];
  174. // Request permission for camera roll access
  175. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  176. switch (status) {
  177. case PHAuthorizationStatusRestricted:
  178. NSLog(@"[LOG] user can't grant access to camera roll");
  179. break;
  180. case PHAuthorizationStatusDenied:
  181. NSLog(@"[LOG] user denied access to camera roll");
  182. break;
  183. default:
  184. break;
  185. }
  186. }];
  187. }
  188. - (void)changeTheming
  189. {
  190. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  191. [self initializeForm];
  192. [self reloadForm];
  193. }
  194. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  195. {
  196. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  197. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  198. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  199. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  200. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  201. // Default
  202. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:nil];
  203. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:nil activeUrl:appDelegate.activeUrl];
  204. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  205. if (account.autoUploadImage == NO && account.autoUploadVideo == NO) {
  206. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  207. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  208. }
  209. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  210. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  211. });
  212. } else {
  213. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  214. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  215. // remove
  216. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  217. }
  218. [self reloadForm];
  219. }
  220. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  221. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  222. }
  223. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  224. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  225. BOOL isLocationIsEnabled = NO;
  226. [[NCAutoUpload sharedInstance] checkIfLocationIsEnabled];
  227. if(isLocationIsEnabled == YES) {
  228. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  229. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  230. [alertController addAction:okAction];
  231. [self presentViewController:alertController animated:YES completion:nil];
  232. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  233. } else {
  234. [self reloadForm];
  235. }
  236. } else {
  237. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  238. [[CCManageLocation sharedInstance] stopSignificantChangeUpdates];
  239. }
  240. }
  241. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  242. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  243. [[NCAutoUpload sharedInstance] setupAutoUploadFull];
  244. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  245. } else {
  246. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  247. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  248. }
  249. }
  250. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  251. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  252. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  253. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  254. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  255. });
  256. }
  257. }
  258. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  259. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  260. }
  261. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  262. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  263. if ([[rowDescriptor.value valueData] boolValue] == YES){
  264. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  265. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  266. });
  267. }
  268. }
  269. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  270. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  271. }
  272. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  273. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  274. }
  275. }
  276. - (void)done:(XLFormRowDescriptor *)sender
  277. {
  278. [self dismissViewControllerAnimated:YES completion:nil];
  279. }
  280. - (void)reloadForm
  281. {
  282. self.form.delegate = nil;
  283. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  284. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  285. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  286. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  287. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  288. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  289. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  290. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  291. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  292. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  293. // - STATUS ---------------------
  294. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  295. if (tableAccount.autoUpload)
  296. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  297. if (tableAccount.autoUploadImage)
  298. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  299. if (tableAccount.autoUploadWWAnPhoto)
  300. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  301. if (tableAccount.autoUploadVideo)
  302. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  303. if (tableAccount.autoUploadWWAnVideo)
  304. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  305. if (tableAccount.autoUploadDeleteAssetLocalIdentifier)
  306. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  307. if (tableAccount.autoUploadBackground)
  308. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  309. if (tableAccount.autoUploadFull)
  310. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  311. if (tableAccount.autoUploadCreateSubfolder)
  312. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  313. // - HIDDEN --------------------------------------------------------------------------
  314. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  315. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  316. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  317. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  318. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  319. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  320. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  321. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  322. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  323. // -----------------------------------------------------------------------------------
  324. [self.tableView reloadData];
  325. self.form.delegate = self;
  326. }
  327. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  328. {
  329. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  330. NSString *sectionName;
  331. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl], [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName]];
  332. switch (section)
  333. {
  334. case 0:
  335. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  336. break;
  337. case 1:
  338. if (tableAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath activeUrl:appDelegate.activeUrl]];
  339. else sectionName = @"";
  340. break;
  341. case 4:
  342. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  343. else sectionName = @"";
  344. break;
  345. case 5:
  346. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  347. else sectionName = @"";
  348. break;
  349. case 6:
  350. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  351. else sectionName = @"";
  352. break;
  353. case 7:
  354. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  355. else sectionName = @"";
  356. break;
  357. case 8:
  358. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  359. else sectionName = @"";
  360. break;
  361. }
  362. return sectionName;
  363. }
  364. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  365. {
  366. if (serverUrl != nil) {
  367. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  368. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:k_dismissAfterSecond type:messageTypeError errorCode:0];
  369. return;
  370. }
  371. // Clear data (old) Auto Upload
  372. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:[[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl] account:appDelegate.activeAccount];
  373. // Settings new folder Automatatic upload
  374. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:[CCUtility getLastPathFromServerUrl:serverUrl activeUrl:appDelegate.activeUrl]];
  375. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:[CCUtility deletingLastPathComponentFromServerUrl:serverUrl] activeUrl:appDelegate.activeUrl];
  376. // Clear data new Auto Upload
  377. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  378. }
  379. }
  380. - (void)selectAutomaticUploadFolder
  381. {
  382. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  383. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  384. viewController.delegate = self;
  385. viewController.hideButtonCreateFolder = false;
  386. viewController.selectFile = false;
  387. viewController.includeDirectoryE2EEncryption = false;
  388. viewController.includeImages = false;
  389. viewController.type = @"";
  390. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  391. viewController.layoutViewSelect = k_layout_view_move;
  392. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  393. [self presentViewController:navigationController animated:YES completion:^{
  394. [self.tableView reloadData];
  395. }];
  396. }
  397. @end