CCManageAccount.m 25 KB

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