CCManageAccount.m 26 KB

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