123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- //
- // CCManageAccount.m
- // Nextcloud iOS
- //
- // Created by Marino Faggiana on 12/03/15.
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- #import <JDStatusBarNotification/JDStatusBarNotification.h>
- #import "CCManageAccount.h"
- #import "AppDelegate.h"
- #import "CCLogin.h"
- #import "NCAutoUpload.h"
- #import "NCBridgeSwift.h"
- #define actionSheetCancellaAccount 1
- @interface CCManageAccount () <CCLoginDelegate, CCLoginDelegateWeb>
- {
- AppDelegate *appDelegate;
- }
- @end
- @implementation CCManageAccount
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
-
- if (self) {
-
- appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
- }
-
- return self;
- }
- - (void)initializeForm
- {
- XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
- XLFormSectionDescriptor *section;
- XLFormRowDescriptor *row;
-
- NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
- tableCapabilities *tableCapabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:tableAccount.account];
- // Section : ACCOUNTS -------------------------------------------
-
- section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_accounts_", nil)];
- [form addFormSection:section];
- form.rowNavigationOptions = XLFormRowNavigationOptionNone;
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"pickerAccount" rowType:XLFormRowDescriptorTypePicker];
- row.height = 100;
- if (listAccount.count > 0) {
- row.selectorOptions = listAccount;
- row.value = tableAccount.account;
- } else {
- row.selectorOptions = [[NSArray alloc] initWithObjects:@"", nil];
- }
-
- // Avatar
- NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl], appDelegate.activeUser];
-
- UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
- if (avatar) {
-
- avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(40, 40) isAspectRation:YES];
-
- CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
-
- CGSize imageSize = avatarImageView.bounds.size;
- UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
- CGContextRef context = UIGraphicsGetCurrentContext();
- [avatarImageView.layer renderInContext:context];
- avatar = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- } else {
- avatar = [UIImage imageNamed:@"avatarBN"];
- }
-
- [row.cellConfig setObject:avatar forKey:@"imageView.image"];
- [section addFormRow:row];
- // Section : MANAGE ACCOUNT -------------------------------------------
-
- if ([NCBrandOptions sharedInstance].disable_manage_account == NO) {
-
- section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_manage_account_", nil)];
- [form addFormSection:section];
-
- // Modify Account
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changePassword" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_password_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
- [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
- row.action.formSelector = @selector(changePassword:);
- if (listAccount.count == 0) row.disabled = @YES;
- [section addFormRow:row];
-
- // Brand
- if ([NCBrandOptions sharedInstance].disable_multiaccount == NO) {
-
- // New Account nextcloud
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"addAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_account_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
- [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
- row.action.formSelector = @selector(addAccount:);
- [section addFormRow:row];
- }
-
- // delete Account
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_delete_account_", nil)];
- [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
- [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
- row.action.formSelector = @selector(deleteAccount:);
- if (listAccount.count == 0) row.disabled = @YES;
- [section addFormRow:row];
- }
-
- // Section : USER INFORMATION -------------------------------------------
-
- section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_personal_information_", nil)];
- [form addFormSection:section];
-
- // Full Name
- if ([tableAccount.displayName length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userfullname" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_full_name_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"user"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.displayName;
- [section addFormRow:row];
- }
-
- // Address
- if ([tableAccount.address length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useraddress" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_address_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"address"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.address;
- [section addFormRow:row];
- }
-
- // City + zip
- if ([tableAccount.city length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercity" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_city_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"city"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.city;
- if ([tableAccount.zip length] > 0) {
- row.value = [NSString stringWithFormat:@"%@ %@", row.value, tableAccount.zip];
- }
- [section addFormRow:row];
- }
-
- // Country
- if ([tableAccount.country length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercountry" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_country_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"country"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = [[NSLocale systemLocale] displayNameForKey:NSLocaleCountryCode value:tableAccount.country];
- //NSArray *countryCodes = [NSLocale ISOCountryCodes];
- [section addFormRow:row];
- }
-
- // Phone
- if ([tableAccount.phone length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userphone" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_phone_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"phone"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.phone;
- [section addFormRow:row];
- }
-
- // Email
- if ([tableAccount.email length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_email_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"email"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.email;
- [section addFormRow:row];
- }
-
- // Web
- if ([tableAccount.webpage length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userweb" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_web_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"web"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.webpage;
- [section addFormRow:row];
- }
-
- // Twitter
- if ([tableAccount.twitter length] > 0) {
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usertwitter" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_twitter_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"twitter"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.twitter;
- [section addFormRow:row];
- }
-
- // Section : THIRT PART -------------------------------------------
- if (tableCapabilities.isHandwerkcloudEnabled) {
- section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_user_job_", nil)];
- [form addFormSection:section];
-
- // Business Type
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesstype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesstype_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"businesstype"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.businessType;
- [section addFormRow:row];
-
- // Business Size
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesssize" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesssize_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"users"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.businessSize;
- [section addFormRow:row];
-
- // Role
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userrole" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_role_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"role"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- if ([tableAccount.role isEqualToString:@"owner"]) row.value = NSLocalizedString(@"_user_owner_", nil);
- else if ([tableAccount.role isEqualToString:@"employee"]) row.value = NSLocalizedString(@"_user_employee_", nil);
- else if ([tableAccount.role isEqualToString:@"contractor"]) row.value = NSLocalizedString(@"_user_contractor_", nil);
- else row.value = @"";
- [section addFormRow:row];
-
- // Company
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercompany" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_company_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"company"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- row.value = tableAccount.company;
- [section addFormRow:row];
-
- if (tableAccount.hcIsTrial) {
-
- section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_trial_", nil)];
- [form addFormSection:section];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"trial" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_trial_expired_day_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
- [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
- [row.cellConfig setObject:[UIColor redColor] forKey:@"detailTextLabel.textColor"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"timer"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
- NSInteger numberOfDays = tableAccount.hcTrialRemainingSec / (24*3600);
- row.value = [@(numberOfDays) stringValue];
- [section addFormRow:row];
- }
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- // Edit profile
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"editUserProfile" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_user_editprofile_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"editUserProfile"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
- [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
- [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
- #if defined(HC)
- row.action.viewControllerClass = [HCEditProfile class];
- #endif
- if (listAccount.count == 0) row.disabled = @YES;
- [section addFormRow:row];
- }
-
- self.form = form;
-
- // Open Login
- if (listAccount.count == 0) {
- [appDelegate openLoginView:self delegate:self loginType:k_login_Add_Forced selector:k_intro_login];
- }
- }
- // Apparirà
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- self.navigationItem.title = NSLocalizedString(@"_credentials_", nil);
-
- self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
- self.tableView.showsVerticalScrollIndicator = NO;
- // Color
- [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
- [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- [self initializeForm];
- }
- - (void)changeTheming
- {
- [appDelegate changeTheming:self];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Delegate ===
- #pragma --------------------------------------------------------------------------------------------
- -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
- {
- [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
-
- if ([rowDescriptor.tag isEqualToString:@"pickerAccount"] && oldValue && newValue) {
-
- if (![newValue isEqualToString:oldValue] && ![newValue isEqualToString:@""] && ![newValue isEqualToString:appDelegate.activeAccount]) {
- [self ChangeDefaultAccount:newValue];
- }
-
- if ([newValue isEqualToString:@""]) {
- NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
- if ([listAccount count] > 0) {
- [self ChangeDefaultAccount:listAccount[0]];
- }
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Delegate Login ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)loginSuccess:(NSInteger)loginType
- {
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Add Account ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)addAccount:(XLFormRowDescriptor *)sender
- {
- [self deselectFormRow:sender];
-
- [appDelegate openLoginView:self delegate:self loginType:k_login_Add selector:k_intro_login];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Modify Account ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)changePassword:(XLFormRowDescriptor *)sender
- {
- [self deselectFormRow:sender];
-
- [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Delete Account ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)deleteAccount:(XLFormRowDescriptor *)sender
- {
- [self deselectFormRow:sender];
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_want_delete_",nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- XLFormPickerCell *pickerAccount = (XLFormPickerCell *)[[self.form formRowWithTag:@"pickerAccount"] cellForFormController:self];
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", pickerAccount.rowDescriptor.value]];
- NSString *account = tableAccount.account;
-
- if (account) {
-
- [appDelegate unsubscribingNextcloudServerPushNotification:account url:tableAccount.url withSubscribing:false];
-
- [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:account];
- [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:account];
-
- // Clear active user
- [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
-
- // Clear keychain
- [CCUtility clearAllKeysEndToEnd:account];
- [CCUtility clearAllKeysPushNotification:account];
- [CCUtility setPassword:account password:nil];
- [CCUtility setCertificateError:account error:NO];
- }
-
- NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
- if ([listAccount count] > 0) {
- [self ChangeDefaultAccount:listAccount[0]];
- } else {
- [self initializeForm];
- }
- }]];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
-
- alertController.popoverPresentationController.sourceView = self.view;
- NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
- alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Change Default Account ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)ChangeDefaultAccount:(NSString *)account
- {
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
- if (tableAccount) {
-
- [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
-
- // Init home
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
- }
-
- [self initializeForm];
- }
- @end
|