CCManageAccount.m 27 KB

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