123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- //
- // CCManageAutoUpload.m
- // Crypto Cloud Technology Nextcloud
- //
- // Created by Marino Faggiana on 01/09/15.
- // Copyright (c) 2017 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // 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 "CCManageAutoUpload.h"
- #import "NCAutoUpload.h"
- #import "AppDelegate.h"
- #import "NCBridgeSwift.h"
- @implementation CCManageAutoUpload
- // From Settings
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- [self initializeForm];
- }
-
- return self;
- }
- // From Photos
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
-
- if (self) {
-
- UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
- self.navigationItem.rightBarButtonItem = doneButton;
-
- [self initializeForm];
- }
-
- return self;
- }
- - (void)initializeForm
- {
- XLFormDescriptor *form ;
- XLFormSectionDescriptor *section;
- XLFormRowDescriptor *row;
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
-
- form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_autoupload_", nil)];
-
- // Auto Upload
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
- section.footerTitle = NSLocalizedString(@"_autoupload_description_", nil);
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_", nil)];
-
- if (tableAccount.autoUpload) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
- // Auto Upload Photo
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_photos_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadPhoto) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnPhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadWWAnPhoto) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- // Auto Upload Video
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_videos_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadVideo) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadWWAnVideo" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_wifi_only_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadWWAnVideo) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- // Auto Upload Background
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadBackground" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_background_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadBackground) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- // Auto Upload Full
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- NSString *title = NSLocalizedString(@"_autoupload_fullphotos_", nil);
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadFull" rowType:XLFormRowDescriptorTypeBooleanSwitch title:title];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- row.value = 0;
- if (tableAccount.autoUploadFull) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- // Auto Upload create subfolder
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUploadCreateSubfolder" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_autoupload_create_subfolder_", nil)];
- row.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- if (tableAccount.autoUploadCreateSubfolder) row.value = @1;
- else row.value = @0;
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
- // end
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
- self.form = form;
- }
- // Apparirà
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
- // Color
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- // Request permission for camera roll access
- [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
- switch (status) {
- case PHAuthorizationStatusRestricted:
- NSLog(@"[LOG] user can't grant access to camera roll");
- break;
- case PHAuthorizationStatusDenied:
- NSLog(@"[LOG] user denied access to camera roll");
- break;
- default:
- break;
- }
- }];
- [self reloadForm];
- }
- - (void)changeTheming
- {
- if (self.isViewLoaded && self.view.window)
- [app changeTheming:self];
- }
- -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
- {
- [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
-
- if ([rowDescriptor.tag isEqualToString:@"autoUpload"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- // Create Folder
- if (app.activeMain)
- [app.activeMain createFolderAutoUpload];
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUpload" state:YES];
-
- // Default
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:nil];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:nil activeUrl:app.activeUrl];
-
- // verifichiamo che almeno uno dei servizi (foto video) siano attivi, in caso contrario attiviamo le foto
- if (tableAccount.autoUploadPhoto == NO && tableAccount.autoUploadVideo == NO) {
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadPhoto" state:YES];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadVideo" state:YES];
- }
-
- // Settings date
- if (tableAccount.autoUploadPhoto)
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
- if (tableAccount.autoUploadVideo)
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[NSDate date]];
-
- } else {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUpload" state:NO];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadFull" state:NO];
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:nil];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:nil];
- // remove
- [[NCManageDatabase sharedInstance] clearTable:[tableAutoUpload class] account:app.activeAccount];
- }
-
- // Initialize Auto Upload
- [[NCAutoUpload sharedInstance] initStateAutoUpload];
-
- [self reloadForm];
- }
-
- if ([rowDescriptor.tag isEqualToString:@"autoUploadBackground"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- BOOL isLocationIsEnabled = NO;
-
- [[NCAutoUpload sharedInstance] checkIfLocationIsEnabled];
-
- if(isLocationIsEnabled == YES) {
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_autoupload_background_title_", nil) message:NSLocalizedString(@"_autoupload_background_msg_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadBackground" state:YES];
-
- } else {
-
- [self reloadForm];
- }
-
- } else {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadBackground" state:NO];
- [[CCManageLocation sharedInstance] stopSignificantChangeUpdates];
- }
- }
- if ([rowDescriptor.tag isEqualToString:@"autoUploadFull"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- [[NCAutoUpload sharedInstance] setupAutoUploadFull];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadFull" state:YES];
-
- } else {
-
- [[NCManageDatabase sharedInstance] clearTable:[tableAutoUpload class] account:app.activeAccount];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadFull" state:NO];
- }
- }
- if ([rowDescriptor.tag isEqualToString:@"autoUploadPhoto"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
-
- } else {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:nil];
- }
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadPhoto" state:[[rowDescriptor.value valueData] boolValue]];
-
- }
-
- if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnPhoto"]) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadWWAnPhoto" state:[[rowDescriptor.value valueData] boolValue]];
- }
-
- if ([rowDescriptor.tag isEqualToString:@"autoUploadVideo"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[NSDate date]];
- } else {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:nil];
- }
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadVideo" state:[[rowDescriptor.value valueData] boolValue]];
- }
-
- if ([rowDescriptor.tag isEqualToString:@"autoUploadWWAnVideo"]) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadWWAnVideo" state:[[rowDescriptor.value valueData] boolValue]];
- }
-
- if ([rowDescriptor.tag isEqualToString:@"autoUploadCreateSubfolder"]) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFiled:@"autoUploadCreateSubfolder" state:[[rowDescriptor.value valueData] boolValue]];
- }
- }
- - (void)done:(XLFormRowDescriptor *)sender
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)reloadForm
- {
- self.form.delegate = nil;
-
- XLFormRowDescriptor *rowAutoUpload = [self.form formRowWithTag:@"autoUpload"];
-
- XLFormRowDescriptor *rowAutoUploadPhoto = [self.form formRowWithTag:@"autoUploadPhoto"];
- XLFormRowDescriptor *rowAutoUploadWWAnPhoto = [self.form formRowWithTag:@"autoUploadWWAnPhoto"];
-
- XLFormRowDescriptor *rowAutoUploadVideo = [self.form formRowWithTag:@"autoUploadVideo"];
- XLFormRowDescriptor *rowAutoUploadWWAnVideo = [self.form formRowWithTag:@"autoUploadWWAnVideo"];
-
- XLFormRowDescriptor *rowAutoUploadBackground = [self.form formRowWithTag:@"autoUploadBackground"];
-
- XLFormRowDescriptor *rowAutoUploadFull = [self.form formRowWithTag:@"autoUploadFull"];
-
- XLFormRowDescriptor *rowAutoUploadCreateSubfolder = [self.form formRowWithTag:@"autoUploadCreateSubfolder"];
-
- // - STATUS ---------------------
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
-
- if (tableAccount.autoUpload)
- [rowAutoUpload setValue:@1]; else [rowAutoUpload setValue:@0];
-
- if (tableAccount.autoUploadPhoto)
- [rowAutoUploadPhoto setValue:@1]; else [rowAutoUploadPhoto setValue:@0];
-
- if (tableAccount.autoUploadWWAnPhoto)
- [rowAutoUploadWWAnPhoto setValue:@1]; else [rowAutoUploadWWAnPhoto setValue:@0];
-
- if (tableAccount.autoUploadVideo)
- [rowAutoUploadVideo setValue:@1]; else [rowAutoUploadVideo setValue:@0];
-
- if (tableAccount.autoUploadWWAnVideo)
- [rowAutoUploadWWAnVideo setValue:@1]; else [rowAutoUploadWWAnVideo setValue:@0];
-
- if (tableAccount.autoUploadBackground)
- [rowAutoUploadBackground setValue:@1]; else [rowAutoUploadBackground setValue:@0];
-
- if (tableAccount.autoUploadFull)
- [rowAutoUploadFull setValue:@1]; else [rowAutoUploadFull setValue:@0];
-
- if (tableAccount.autoUploadCreateSubfolder)
- [rowAutoUploadCreateSubfolder setValue:@1]; else [rowAutoUploadCreateSubfolder setValue:@0];
-
- // - HIDDEN ---------------------
-
- rowAutoUploadPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- rowAutoUploadWWAnPhoto.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
-
- rowAutoUploadVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- rowAutoUploadWWAnVideo.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
-
- rowAutoUploadBackground.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
-
- rowAutoUploadFull.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
-
- rowAutoUploadCreateSubfolder.hidden = [NSString stringWithFormat:@"$%@==0", @"autoUpload"];
- // ----------------------
-
- [self.tableView reloadData];
-
- self.form.delegate = self;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- {
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
- NSString *sectionName;
-
- switch (section)
- {
- case 0:
- sectionName = NSLocalizedString(@"_settings_autoupload_", nil);
- break;
- case 1:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_photos_", nil);
- else sectionName = @"";
- break;
- case 2:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_videos_", nil);
- else sectionName = @"";
- break;
- case 3:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_background_", nil);
- else sectionName = @"";
- break;
- case 4:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_", nil);
- else sectionName = @"";
- break;
- case 5:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_", nil);
- else sectionName = @"";
- break;
- }
- return sectionName;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
- {
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
- NSString *sectionName;
-
- switch (section)
- {
- case 0:
- sectionName = NSLocalizedString(@"_autoupload_description_", nil);
- break;
- case 3:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_description_background_", nil);
- else sectionName = @"";
- break;
- case 4:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_fullphotos_footer_", nil);
- else sectionName = @"";
- break;
- case 5:
- if (tableAccount.autoUpload) sectionName = NSLocalizedString(@"_autoupload_create_subfolder_footer_", nil);
- else sectionName = @"";
- break;
- }
- return sectionName;
- }
- @end
|