CCManageAccount.m 25 KB

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