CCManageAutoUpload.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 formDescriptor];
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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.backgroundCell;
  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. self.title = NSLocalizedString(@"_settings_autoupload_", nil);
  167. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  168. // changeTheming
  169. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  170. [self changeTheming];
  171. }
  172. - (void)viewWillAppear:(BOOL)animated
  173. {
  174. [super viewWillAppear:animated];
  175. // Request permission for camera roll access
  176. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  177. switch (status) {
  178. case PHAuthorizationStatusRestricted:
  179. NSLog(@"[LOG] user can't grant access to camera roll");
  180. break;
  181. case PHAuthorizationStatusDenied:
  182. NSLog(@"[LOG] user denied access to camera roll");
  183. break;
  184. default:
  185. break;
  186. }
  187. }];
  188. }
  189. - (void)changeTheming
  190. {
  191. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  192. [self initializeForm];
  193. [self reloadForm];
  194. }
  195. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  196. {
  197. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  198. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  199. if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
  200. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  201. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:YES];
  202. // Default
  203. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:nil];
  204. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:nil activeUrl:appDelegate.activeUrl];
  205. // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
  206. if (account.autoUploadImage == NO && account.autoUploadVideo == NO) {
  207. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:YES];
  208. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:YES];
  209. }
  210. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  211. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  212. });
  213. } else {
  214. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUpload" state:NO];
  215. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  216. // remove
  217. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  218. }
  219. [self reloadForm];
  220. }
  221. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  222. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadDeleteAssetLocalIdentifier" state:[[rowDescriptor.value valueData] boolValue]];
  223. }
  224. if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
  225. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  226. BOOL isLocationIsEnabled = NO;
  227. [[NCAutoUpload sharedInstance] checkIfLocationIsEnabled];
  228. if(isLocationIsEnabled == YES) {
  229. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  230. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  231. [alertController addAction:okAction];
  232. [self presentViewController:alertController animated:YES completion:nil];
  233. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
  234. } else {
  235. [self reloadForm];
  236. }
  237. } else {
  238. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
  239. [[CCManageLocation sharedInstance] stopSignificantChangeUpdates];
  240. }
  241. }
  242. if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
  243. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  244. [[NCAutoUpload sharedInstance] setupAutoUploadFull];
  245. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
  246. } else {
  247. [[NCManageDatabase sharedInstance] clearMetadatasUploadWithAccount:appDelegate.activeAccount];
  248. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadFull" state:NO];
  249. }
  250. }
  251. if ([rowDescriptor.tag isEqualToString:@"autoUploadImage"]) {
  252. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadImage" state:[[rowDescriptor.value valueData] boolValue]];
  253. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  254. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  255. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  256. });
  257. }
  258. }
  259. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
  260. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
  261. }
  262. if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
  263. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
  264. if ([[rowDescriptor.value valueData] boolValue] == YES){
  265. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  266. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  267. });
  268. }
  269. }
  270. if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
  271. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
  272. }
  273. if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
  274. [[NCManageDatabase sharedInstance] setAccountAutoUploadProperty:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
  275. }
  276. }
  277. - (void)done:(XLFormRowDescriptor *)sender
  278. {
  279. [self dismissViewControllerAnimated:YES completion:nil];
  280. }
  281. - (void)reloadForm
  282. {
  283. self.form.delegate = nil;
  284. XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
  285. XLFormRowDescriptor *rowAutoUploadImage = [self.form formRowWithTag:@"autoUploadImage"];
  286. XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
  287. XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
  288. XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
  289. XLFormRowDescriptor *rowRemovePhotoCameraRoll = [self.form formRowWithTag:@"removePhotoCameraRoll"];
  290. XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
  291. XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
  292. XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
  293. XLFormRowDescriptor *rowAutoUploadFileName = [self.form formRowWithTag:@"autoUploadFileName"];
  294. // - STATUS ---------------------
  295. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  296. if (tableAccount.autoUpload)
  297. [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
  298. if (tableAccount.autoUploadImage)
  299. [rowAutoUploadImage setValue:@1]; else [rowAutoUploadImage setValue:@0];
  300. if (tableAccount.autoUploadWWAnPhoto)
  301. [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
  302. if (tableAccount.autoUploadVideo)
  303. [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
  304. if (tableAccount.autoUploadWWAnVideo)
  305. [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
  306. if (tableAccount.autoUploadDeleteAssetLocalIdentifier)
  307. [rowRemovePhotoCameraRoll setValue:@1]; else [rowRemovePhotoCameraRoll setValue:@0];
  308. if (tableAccount.autoUploadBackground)
  309. [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
  310. if (tableAccount.autoUploadFull)
  311. [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
  312. if (tableAccount.autoUploadCreateSubfolder)
  313. [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
  314. // - HIDDEN --------------------------------------------------------------------------
  315. rowAutoUploadImage.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  316. rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  317. rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  318. rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  319. rowRemovePhotoCameraRoll.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  320. rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  321. rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  322. rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  323. rowAutoUploadFileName.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
  324. // -----------------------------------------------------------------------------------
  325. [self.tableView reloadData];
  326. self.form.delegate = self;
  327. }
  328. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  329. {
  330. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  331. NSString *sectionName;
  332. NSString *autoUploadPath = [NSString stringWithFormat:@"%@/%@", [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl], [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName]];
  333. switch (section)
  334. {
  335. case 0:
  336. sectionName = NSLocalizedString(@"_autoupload_description_", nil);
  337. break;
  338. case 1:
  339. if (tableAccount.autoUpload) sectionName = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_autoupload_current_folder_", nil), [CCUtility returnPathfromServerUrl:autoUploadPath activeUrl:appDelegate.activeUrl]];
  340. else sectionName = @"";
  341. break;
  342. case 4:
  343. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil);
  344. else sectionName = @"";
  345. break;
  346. case 5:
  347. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
  348. else sectionName = @"";
  349. break;
  350. case 6:
  351. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
  352. else sectionName = @"";
  353. break;
  354. case 7:
  355. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
  356. else sectionName = @"";
  357. break;
  358. case 8:
  359. if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_filenamemask_footer_", nil);
  360. else sectionName = @"";
  361. break;
  362. }
  363. return sectionName;
  364. }
  365. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  366. {
  367. if (serverUrl != nil) {
  368. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  369. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_autoupload_error_select_folder_" delay:k_dismissAfterSecond type:messageTypeError errorCode:0];
  370. return;
  371. }
  372. // Clear data (old) Auto Upload
  373. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:[[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl] account:appDelegate.activeAccount];
  374. // Settings new folder Automatatic upload
  375. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:[CCUtility getLastPathFromServerUrl:serverUrl activeUrl:appDelegate.activeUrl]];
  376. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:[CCUtility deletingLastPathComponentFromServerUrl:serverUrl] activeUrl:appDelegate.activeUrl];
  377. // Clear data new Auto Upload
  378. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  379. }
  380. }
  381. - (void)selectAutomaticUploadFolder
  382. {
  383. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  384. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  385. viewController.delegate = self;
  386. viewController.hideButtonCreateFolder = false;
  387. viewController.selectFile = false;
  388. viewController.includeDirectoryE2EEncryption = false;
  389. viewController.includeImages = false;
  390. viewController.type = @"";
  391. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  392. viewController.layoutViewSelect = k_layout_view_move;
  393. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  394. [self presentViewController:navigationController animated:YES completion:^{
  395. [self.tableView reloadData];
  396. }];
  397. }
  398. @end