CCManageAccount.m 27 KB

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