CCManageAccount.m 25 KB

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