CCManageAccount.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //
  2. // CCManageAccount.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/03/15.
  6. // Copyright (c) 2015 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 "CCManageAccount.h"
  24. #import "AppDelegate.h"
  25. #import "CCLogin.h"
  26. #import "NCAutoUpload.h"
  27. #import "NCBridgeSwift.h"
  28. #define actionSheetCancellaAccount 1
  29. @interface CCManageAccount ()
  30. {
  31. AppDelegate *appDelegate;
  32. }
  33. @end
  34. @implementation CCManageAccount
  35. - (void)initializeForm
  36. {
  37. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  38. XLFormSectionDescriptor *section;
  39. XLFormRowDescriptor *row;
  40. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  41. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  42. // Section : ACCOUNTS -------------------------------------------
  43. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_accounts_", nil)];
  44. [form addFormSection:section];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"pickerAccount" rowType:XLFormRowDescriptorTypePicker];
  47. row.height = 100;
  48. if (listAccount.count > 0) {
  49. row.selectorOptions = listAccount;
  50. row.value = tableAccount.account;
  51. } else {
  52. row.selectorOptions = [[NSArray alloc] initWithObjects:@"", nil];
  53. }
  54. // Avatar
  55. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl], appDelegate.activeUser];
  56. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  57. if (avatar) {
  58. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(40, 40) isAspectRation:YES];
  59. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  60. CGSize imageSize = avatarImageView.bounds.size;
  61. UIGraphicsBeginImageContextWithOptions(imageSize, NO, UIScreen.mainScreen.scale);
  62. CGContextRef context = UIGraphicsGetCurrentContext();
  63. [avatarImageView.layer renderInContext:context];
  64. avatar = UIGraphicsGetImageFromCurrentImageContext();
  65. UIGraphicsEndImageContext();
  66. } else {
  67. avatar = [UIImage imageNamed:@"avatarBN"];
  68. }
  69. [row.cellConfig setObject:avatar forKey:@"imageView.image"];
  70. [section addFormRow:row];
  71. // Section : MANAGE ACCOUNT -------------------------------------------
  72. if ([NCBrandOptions sharedInstance].disable_manage_account == NO) {
  73. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_manage_account_", nil)];
  74. [form addFormSection:section];
  75. // Brand
  76. if ([NCBrandOptions sharedInstance].disable_multiaccount == NO) {
  77. // New Account nextcloud
  78. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"addAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_account_", nil)];
  79. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  82. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  83. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  84. row.action.formSelector = @selector(addAccount:);
  85. [section addFormRow:row];
  86. }
  87. // delete Account
  88. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_delete_account_", nil)];
  89. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  90. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  93. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  94. row.action.formSelector = @selector(deleteAccount:);
  95. if (listAccount.count == 0) row.disabled = @YES;
  96. [section addFormRow:row];
  97. }
  98. // Section : USER INFORMATION -------------------------------------------
  99. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_personal_information_", nil)];
  100. [form addFormSection:section];
  101. // Full Name
  102. if ([tableAccount.displayName length] > 0) {
  103. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userfullname" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_full_name_", nil)];
  104. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  105. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  106. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  107. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  108. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"user"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  109. row.value = tableAccount.displayName;
  110. [section addFormRow:row];
  111. }
  112. // Address
  113. if ([tableAccount.address length] > 0) {
  114. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useraddress" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_address_", nil)];
  115. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  116. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  117. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  118. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  119. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"address"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  120. row.value = tableAccount.address;
  121. [section addFormRow:row];
  122. }
  123. // City + zip
  124. if ([tableAccount.city length] > 0) {
  125. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercity" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_city_", nil)];
  126. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  127. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  128. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  129. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  130. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"city"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  131. row.value = tableAccount.city;
  132. if ([tableAccount.zip length] > 0) {
  133. row.value = [NSString stringWithFormat:@"%@ %@", row.value, tableAccount.zip];
  134. }
  135. [section addFormRow:row];
  136. }
  137. // Country
  138. if ([tableAccount.country length] > 0) {
  139. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercountry" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_country_", nil)];
  140. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  141. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  143. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  144. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"country"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  145. row.value = [[NSLocale systemLocale] displayNameForKey:NSLocaleCountryCode value:tableAccount.country];
  146. //NSArray *countryCodes = [NSLocale ISOCountryCodes];
  147. [section addFormRow:row];
  148. }
  149. // Phone
  150. if ([tableAccount.phone length] > 0) {
  151. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userphone" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_phone_", nil)];
  152. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  153. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  154. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  155. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  156. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"phone"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  157. row.value = tableAccount.phone;
  158. [section addFormRow:row];
  159. }
  160. // Email
  161. if ([tableAccount.email length] > 0) {
  162. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_email_", nil)];
  163. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  164. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  165. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  166. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  167. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"email"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  168. row.value = tableAccount.email;
  169. [section addFormRow:row];
  170. }
  171. // Web
  172. if ([tableAccount.webpage length] > 0) {
  173. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userweb" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_web_", nil)];
  174. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  175. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  176. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  177. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  178. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"web"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  179. row.value = tableAccount.webpage;
  180. [section addFormRow:row];
  181. }
  182. // Twitter
  183. if ([tableAccount.twitter length] > 0) {
  184. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usertwitter" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_twitter_", nil)];
  185. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  186. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  187. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  188. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  189. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"twitter"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  190. row.value = tableAccount.twitter;
  191. [section addFormRow:row];
  192. }
  193. // Section : THIRT PART -------------------------------------------
  194. BOOL isHandwerkcloudEnabled = [[NCManageDatabase sharedInstance] getCapabilitiesServerBoolWithAccount:tableAccount.account elements:NCElementsJSON.shared.capabilitiesHWCEnabled exists:false];
  195. if (isHandwerkcloudEnabled) {
  196. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_user_job_", nil)];
  197. [form addFormSection:section];
  198. // Business Type
  199. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesstype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesstype_", nil)];
  200. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  201. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  202. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  203. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  204. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"businesstype"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  205. row.value = tableAccount.businessType;
  206. [section addFormRow:row];
  207. // Business Size
  208. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesssize" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesssize_", nil)];
  209. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  210. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  211. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  212. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  213. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"users"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  214. row.value = tableAccount.businessSize;
  215. [section addFormRow:row];
  216. // Role
  217. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userrole" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_role_", nil)];
  218. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  219. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  220. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  221. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  222. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"role"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  223. if ([tableAccount.role isEqualToString:@"owner"]) row.value = NSLocalizedString(@"_user_owner_", nil);
  224. else if ([tableAccount.role isEqualToString:@"employee"]) row.value = NSLocalizedString(@"_user_employee_", nil);
  225. else if ([tableAccount.role isEqualToString:@"contractor"]) row.value = NSLocalizedString(@"_user_contractor_", nil);
  226. else row.value = @"";
  227. [section addFormRow:row];
  228. // Company
  229. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercompany" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_company_", nil)];
  230. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  231. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  232. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  233. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  234. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"company"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  235. row.value = tableAccount.company;
  236. [section addFormRow:row];
  237. if (tableAccount.hcIsTrial) {
  238. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_trial_", nil)];
  239. [form addFormSection:section];
  240. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"trial" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_trial_expired_day_", nil)];
  241. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  242. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  243. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  244. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  245. [row.cellConfig setObject:[UIColor redColor] forKey:@"detailTextLabel.textColor"];
  246. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"timer"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  247. NSInteger numberOfDays = tableAccount.hcTrialRemainingSec / (24*3600);
  248. row.value = [@(numberOfDays) stringValue];
  249. [section addFormRow:row];
  250. }
  251. section = [XLFormSectionDescriptor formSection];
  252. [form addFormSection:section];
  253. // Edit profile
  254. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"editUserProfile" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_user_editprofile_", nil)];
  255. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundCell;
  256. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  257. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"editUserProfile"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  258. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  259. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  260. #if defined(HC)
  261. row.action.viewControllerClass = [HCEditProfile class];
  262. #endif
  263. if (listAccount.count == 0) row.disabled = @YES;
  264. [section addFormRow:row];
  265. }
  266. self.tableView.showsVerticalScrollIndicator = NO;
  267. self.form = form;
  268. // Open Login
  269. if (listAccount.count == 0) {
  270. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  271. }
  272. }
  273. - (void)viewDidLoad
  274. {
  275. [super viewDidLoad];
  276. self.title = NSLocalizedString(@"_credentials_", nil);
  277. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  278. // changeTheming
  279. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  280. [self changeTheming];
  281. }
  282. - (void)changeTheming
  283. {
  284. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  285. [self initializeForm];
  286. }
  287. #pragma --------------------------------------------------------------------------------------------
  288. #pragma mark === Delegate ===
  289. #pragma --------------------------------------------------------------------------------------------
  290. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  291. {
  292. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  293. if ([rowDescriptor.tag isEqualToString:@"pickerAccount"] && oldValue && newValue) {
  294. if (![newValue isEqualToString:oldValue] && ![newValue isEqualToString:@""] && ![newValue isEqualToString:appDelegate.activeAccount]) {
  295. [self ChangeDefaultAccount:newValue];
  296. }
  297. if ([newValue isEqualToString:@""]) {
  298. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  299. if ([listAccount count] > 0) {
  300. [self ChangeDefaultAccount:listAccount[0]];
  301. }
  302. }
  303. }
  304. }
  305. #pragma --------------------------------------------------------------------------------------------
  306. #pragma mark === Add Account ===
  307. #pragma --------------------------------------------------------------------------------------------
  308. - (void)addAccount:(XLFormRowDescriptor *)sender
  309. {
  310. [self deselectFormRow:sender];
  311. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  312. }
  313. #pragma --------------------------------------------------------------------------------------------
  314. #pragma mark === Delete Account ===
  315. #pragma --------------------------------------------------------------------------------------------
  316. - (void)deleteAccount:(XLFormRowDescriptor *)sender
  317. {
  318. [self deselectFormRow:sender];
  319. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_want_delete_",nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  320. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  321. XLFormPickerCell *pickerAccount = (XLFormPickerCell *)[[self.form formRowWithTag:@"pickerAccount"] cellForFormController:self];
  322. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", pickerAccount.rowDescriptor.value]];
  323. NSString *account = tableAccount.account;
  324. if (account) {
  325. [appDelegate deleteAccount:account wipe:false];
  326. }
  327. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  328. if ([listAccount count] > 0) {
  329. [self ChangeDefaultAccount:listAccount[0]];
  330. } else {
  331. [self initializeForm];
  332. }
  333. }]];
  334. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  335. alertController.popoverPresentationController.sourceView = self.view;
  336. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  337. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  338. [self presentViewController:alertController animated:YES completion:nil];
  339. }
  340. #pragma --------------------------------------------------------------------------------------------
  341. #pragma mark === Change Default Account ===
  342. #pragma --------------------------------------------------------------------------------------------
  343. - (void)ChangeDefaultAccount:(NSString *)account
  344. {
  345. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
  346. if (tableAccount) {
  347. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  348. // Init home
  349. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  350. }
  351. [self initializeForm];
  352. }
  353. @end