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