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