CCManageAccount.m 25 KB

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