CCManageAccount.m 26 KB

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