CCManageAccount.m 25 KB

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