فهرست منبع

new auto upload

marinofaggiana 4 سال پیش
والد
کامیت
f80097591e

+ 0 - 6
Nextcloud.xcodeproj/project.pbxproj

@@ -269,7 +269,6 @@
 		F7AE00F8230E81CB007ACF8A /* NCBrowserWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AE00F7230E81CB007ACF8A /* NCBrowserWeb.swift */; };
 		F7AE00FA230E81EB007ACF8A /* NCBrowserWeb.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7AE00F9230E81EB007ACF8A /* NCBrowserWeb.storyboard */; };
 		F7AF7633246BEDFE00B86E3C /* TOPasscodeViewController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7AF7632246BEDFE00B86E3C /* TOPasscodeViewController.framework */; };
-		F7B0C1751EE839A30033AC24 /* CCAutoUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B0C1741EE839A30033AC24 /* CCAutoUpload.m */; };
 		F7B174C822FAC0A8000B7579 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B174C722FAC0A8000B7579 /* AppDelegate.m */; };
 		F7B2DEF01F976854007CF4D2 /* NYMnemonic.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B2DEEF1F976785007CF4D2 /* NYMnemonic.m */; };
 		F7B2DEF11F976859007CF4D2 /* english.txt in Resources */ = {isa = PBXBuildFile; fileRef = F7B2DEED1F976785007CF4D2 /* english.txt */; };
@@ -628,8 +627,6 @@
 		F7AE00F7230E81CB007ACF8A /* NCBrowserWeb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCBrowserWeb.swift; sourceTree = "<group>"; };
 		F7AE00F9230E81EB007ACF8A /* NCBrowserWeb.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCBrowserWeb.storyboard; sourceTree = "<group>"; };
 		F7AF7632246BEDFE00B86E3C /* TOPasscodeViewController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TOPasscodeViewController.framework; path = Carthage/Build/iOS/TOPasscodeViewController.framework; sourceTree = "<group>"; };
-		F7B0C1731EE839A30033AC24 /* CCAutoUpload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAutoUpload.h; sourceTree = "<group>"; };
-		F7B0C1741EE839A30033AC24 /* CCAutoUpload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAutoUpload.m; sourceTree = "<group>"; };
 		F7B174C722FAC0A8000B7579 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
 		F7B1A7761EBB3C8000BFB6D1 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F7B2DEED1F976785007CF4D2 /* english.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = english.txt; sourceTree = "<group>"; };
@@ -1226,8 +1223,6 @@
 			isa = PBXGroup;
 			children = (
 				F72CD63925C19EBF00F46F9A /* NCAutoUpload.swift */,
-				F7B0C1731EE839A30033AC24 /* CCAutoUpload.h */,
-				F7B0C1741EE839A30033AC24 /* CCAutoUpload.m */,
 			);
 			path = AutoUpload;
 			sourceTree = "<group>";
@@ -2051,7 +2046,6 @@
 				F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */,
 				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
-				F7B0C1751EE839A30033AC24 /* CCAutoUpload.m in Sources */,
 				F738E8421F90FFD100F95C8E /* NCManageEndToEndEncryption.m in Sources */,
 				F70753F12542A9A200972D44 /* NCViewerImageZoom.swift in Sources */,
 				F7A80BCB252624C100C7CD01 /* NCFileViewInFolder.swift in Sources */,

+ 4 - 5
iOSClient/AppDelegate.m

@@ -23,7 +23,6 @@
 
 #import "AppDelegate.h"
 #import "NCBridgeSwift.h"
-#import "CCAutoUpload.h"
 #import "NSNotificationCenter+MainThread.h"
 #import "NCPushNotification.h"
 #import <QuartzCore/QuartzCore.h>
@@ -195,7 +194,7 @@
     [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
     
     // Initialize Auto upload
-    [[CCAutoUpload shared] initStateAutoUpload];
+    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
     
     // Read active directory
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCBrandGlobal.shared.notificationCenterReloadDataSourceNetworkForced object:nil];
@@ -269,11 +268,11 @@
     // Not Photos Video in library ? then align and Init Auto Upload
     NSArray *recordsPhotoLibrary = [[NCManageDatabase shared] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", self.account]];
     if ([recordsPhotoLibrary count] == 0) {
-        [[CCAutoUpload shared] alignPhotoLibrary];
+        [[NCAutoUpload shared] alignPhotoLibrary];
     }
     
     // Start Auto Upload
-    [[CCAutoUpload shared] initStateAutoUpload];
+    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
     
     // Start services
     [[NCService shared] startRequestServicesServer];
@@ -521,7 +520,7 @@
     [[NCCommunicationCommon shared] writeLog:@"Start perform Fetch With Completion Handler"];
     
     // Verify new photo
-    [[CCAutoUpload shared] initStateAutoUpload];
+    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
     
     // after 20 sec
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

+ 0 - 39
iOSClient/AutoUpload/CCAutoUpload.h

@@ -1,39 +0,0 @@
-//
-//  CCAutoUpload.h
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 07/06/17.
-//  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 <Foundation/Foundation.h>
-#import <Photos/Photos.h>
-#import "CCManageAutoUpload.h"
-
-@class tableAccount;
-
-@interface CCAutoUpload : NSObject
-
-+ (CCAutoUpload *)shared;
-
-- (void)initStateAutoUpload;
-- (BOOL)checkIfLocationIsEnabled;
-- (void)setupAutoUploadFull;
-- (void)alignPhotoLibrary;
-
-@end

+ 0 - 604
iOSClient/AutoUpload/CCAutoUpload.m

@@ -1,604 +0,0 @@
-//
-//  CCAutoUpload.m
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 07/06/17.
-//  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 "CCAutoUpload.h"
-#import "AppDelegate.h"
-#import "NCBridgeSwift.h"
-#import "CCHud.h"
-
-#pragma GCC diagnostic ignored "-Wundeclared-selector"
-
-@interface CCAutoUpload ()
-{
-    AppDelegate *appDelegate;
-    CCHud *_hud;
-    BOOL endForAssetToUpload;
-}
-@end
-
-@implementation CCAutoUpload
-
-+ (CCAutoUpload *)shared {
-    
-    static CCAutoUpload *shared;
-    
-    @synchronized(self)
-    {
-        if (!shared) {
-            
-            shared = [CCAutoUpload new];
-            shared->appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-            
-            [[NSNotificationCenter defaultCenter] addObserver:shared selector:@selector(statusAuthorizationLocationChanged) name:NCBrandGlobal.shared.notificationStatusAuthorizationChangedLocation object:nil];
-            [[NSNotificationCenter defaultCenter] addObserver:shared selector:@selector(changedLocation) name:NCBrandGlobal.shared.notificationCenterChangedLocation object:nil];
-
-        }
-        return shared;
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark === initStateAutoUpload ===
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)initStateAutoUpload
-{
-    tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-    
-    if (account.autoUpload) {
-        
-        [self setupAutoUpload];
-        
-        if (account.autoUploadBackground) {
-         
-            [self checkIfLocationIsEnabled];
-        }
-        
-    } else {
-        
-        [[NCManageLocation shared] stopSignificantChangeUpdates];
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark === Camera Upload & Full ===
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)setupAutoUpload
-{
-    if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-        
-        [self performSelectorOnMainThread:@selector(uploadNewAssets) withObject:nil waitUntilDone:NO];
-        
-    } else {
-        
-        tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-
-        if (account.autoUpload == YES)
-            [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
-        
-        [[NCManageLocation shared] stopSignificantChangeUpdates];
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-        
-        [alertController addAction:okAction];
-        [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-        return;        
-    }
-}
-
-- (void)setupAutoUploadFull
-{
-    if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-        
-        [self performSelectorOnMainThread:@selector(uploadFullAssets) withObject:nil waitUntilDone:NO];
-        
-    } else {
-        
-        tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-
-        if (account.autoUpload == YES)
-            [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
-        
-        [[NCManageLocation shared] stopSignificantChangeUpdates];
-        
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-        
-        [alertController addAction:okAction];
-        [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark === Location ===
-#pragma --------------------------------------------------------------------------------------------
-
-- (BOOL)checkIfLocationIsEnabled
-{
-    tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-        
-    if ([CLLocationManager locationServicesEnabled]) {
-        
-        [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Check if location is enabled: authorizationStatus: %d", [CLLocationManager authorizationStatus]]];
-        
-        if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
-            
-            if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined ) {
-                
-                [[NCCommunicationCommon shared] writeLog:@"Check if location is enabled: Location services not determined"];
-                [[NCManageLocation shared] startSignificantChangeUpdates];
-                
-            } else {
-                
-                if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-                    
-                    if (account.autoUploadBackground == YES)
-                        [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-                    
-                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_location_not_enabled_", nil) message:NSLocalizedString(@"_location_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                    
-                    [alertController addAction:okAction];
-                    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-                    
-                } else {
-                    
-                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                    
-                    [alertController addAction:okAction];
-                    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-                }
-            }
-            
-        } else {
-            
-            if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-                
-                if (account.autoUploadBackground == NO)
-                    [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:YES];
-                
-                [[NCManageLocation shared] startSignificantChangeUpdates];
-                
-            } else {
-                
-                if (account.autoUploadBackground == YES)
-                    [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-                
-                [[NCManageLocation shared] stopSignificantChangeUpdates];
-                
-                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                
-                [alertController addAction:okAction];
-                [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-            }
-        }
-        
-    } else {
-        
-        if (account.autoUploadBackground == YES)
-            [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-        
-        [[NCManageLocation shared] stopSignificantChangeUpdates];
-        
-        if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-            
-            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_location_not_enabled_", nil) message:NSLocalizedString(@"_location_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-            
-            [alertController addAction:okAction];
-            [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-            
-        } else {
-            
-            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_location_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_location_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-            
-            [alertController addAction:okAction];
-            [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-        }
-    }
-    
-    tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
-    return tableAccount.autoUploadBackground;
-}
-
-- (void)statusAuthorizationLocationChanged
-{
-    tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-    
-    if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined){
-        
-        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
-            
-            if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-                
-                if (NCManageLocation.shared.firstChangeAuthorizationDone) {
-                                    
-                    if (account.autoUploadBackground == YES)
-                        [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-                    
-                    [[NCManageLocation shared] stopSignificantChangeUpdates];
-                }
-                
-            } else {
-                
-                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                
-                [alertController addAction:okAction];
-                [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-            }
-            
-        } else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined){
-            
-            if (account.autoUploadBackground == YES) {
-                
-                [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-                
-                [[NCManageLocation shared] stopSignificantChangeUpdates];
-                
-                if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-                    
-                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_location_not_enabled_", nil) message:NSLocalizedString(@"_location_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                    
-                    [alertController addAction:okAction];
-                    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-                    
-                } else {
-                    
-                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_location_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_location_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                    
-                    [alertController addAction:okAction];
-                    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:alertController animated:YES completion:nil];
-                }
-            }
-        }
-        
-        if (!NCManageLocation.shared.firstChangeAuthorizationDone) {
-            
-            NCManageLocation.shared.firstChangeAuthorizationDone = true;
-        }
-    }
-}
-
-- (void)changedLocation
-{
-    // Only in background
-    tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-    
-    if (account.autoUpload && account.autoUploadBackground && [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
-        
-        if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-            
-            //check location
-            if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
-                
-                [[NCCommunicationCommon shared] writeLog:@"Changed Location call upload new assets"];
-                [self uploadNewAssets];
-            }
-            
-        } else {
-            
-            if (account.autoUpload == YES)
-                [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUpload" state:NO];
-            
-            if (account.autoUploadBackground == YES)
-                [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-            
-            [[NCManageLocation shared] stopSignificantChangeUpdates];
-        }
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Upload Assets : NEW & FULL ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)uploadNewAssets
-{
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-        [self uploadAssetsNewAndFull:NCBrandGlobal.shared.selectorUploadAutoUpload];
-    });
-}
-
-- (void)uploadFullAssets
-{
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-        [self uploadAssetsNewAndFull:NCBrandGlobal.shared.selectorUploadAutoUploadAll];
-    });
-}
-
-- (void)uploadAssetsNewAndFull:(NSString *)selector
-{
-    if (!appDelegate.account) return;
-    
-    tableAccount *tableAccount = [[NCManageDatabase shared] getAccountActive];
-    if (tableAccount == nil) {
-        return;
-    }
-    
-    NSMutableArray *metadataFull = [NSMutableArray new];
-    NSString *autoUploadPath = [[NCManageDatabase shared] getAccountAutoUploadPathWithUrlBase:appDelegate.urlBase account:appDelegate.account];
-    NSString *serverUrl;
-    __block NSInteger counterLivePhoto = 0;
-
-    // Check Asset : NEW or FULL
-    NSArray *newAssetToUpload = [self getCameraRollAssets:tableAccount selector:selector alignPhotoLibrary:NO];
-    
-    // News Assets ? if no verify if blocked Table Auto Upload -> Autostart
-    if (newAssetToUpload == nil || [newAssetToUpload count] == 0) {
-        
-        [[NCCommunicationCommon shared] writeLog:@"Automatic upload, no new assets found"];
-        return;
-        
-    } else {
-        
-        [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Automatic upload, new %lu assets found", (unsigned long)[newAssetToUpload count]]];
-    }
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-            if (!_hud)
-                _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
-        
-            [[NCContentPresenter shared] messageNotification:@"_attention_" description:@"_create_full_upload_" delay:[[NCBrandGlobal shared] dismissAfterSecondLong] type:messageTypeInfo errorCode:0 forced:true];
-            [_hud visibleHudTitle:NSLocalizedString(@"_wait_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
-        }
-    });
-    
-    // Create the folder for auto upload & if request the subfolders
-    if ([[NCNetworking shared] createFolderWithAssets:newAssetToUpload selector:selector useSubFolder:tableAccount.autoUploadCreateSubfolder account:appDelegate.account urlBase:appDelegate.urlBase]) {
-        if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-            [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" delay:[[NCBrandGlobal shared] dismissAfterSecond] type:messageTypeError errorCode:NCBrandGlobal.shared.ErrorInternalError forced:true];
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [_hud hideHud];
-            });
-        }
-        
-        return;
-    }
-    
-    endForAssetToUpload = false;
-    for (PHAsset *asset in newAssetToUpload) {
-        
-        BOOL livePhoto = false;
-        NSDate *assetDate = asset.creationDate;
-        PHAssetMediaType assetMediaType = asset.mediaType;
-        NSString *session;
-        NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:NCBrandGlobal.shared.keyFileNameAutoUploadMask keyFileNameType:NCBrandGlobal.shared.keyFileNameAutoUploadType keyFileNameOriginal:NCBrandGlobal.shared.keyFileNameOriginalAutoUpload];
-
-        // Detect LivePhoto Upload
-        if ((asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive+PHAssetMediaSubtypePhotoHDR) && CCUtility.getLivePhoto) {
-            livePhoto = true;
-        }
-        
-        // Select type of session
-        if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-            session = NCCommunicationCommon.shared.sessionIdentifierUpload;
-        } else {
-            if (assetMediaType == PHAssetMediaTypeImage && tableAccount.autoUploadWWAnPhoto == NO) session = NCNetworking.shared.sessionIdentifierBackground;
-            else if (assetMediaType == PHAssetMediaTypeVideo && tableAccount.autoUploadWWAnVideo == NO) session = NCNetworking.shared.sessionIdentifierBackground;
-            else if (assetMediaType == PHAssetMediaTypeImage && tableAccount.autoUploadWWAnPhoto) session = NCNetworking.shared.sessionIdentifierBackgroundWWan;
-            else if (assetMediaType == PHAssetMediaTypeVideo && tableAccount.autoUploadWWAnVideo) session = NCNetworking.shared.sessionIdentifierBackgroundWWan;
-            else session = NCNetworking.shared.sessionIdentifierBackground;
-        }
-        
-        NSDateFormatter *formatter = [NSDateFormatter new];
-        
-        [formatter setDateFormat:@"yyyy"];
-        NSString *yearString = [formatter stringFromDate:assetDate];
-        
-        [formatter setDateFormat:@"MM"];
-        NSString *monthString = [formatter stringFromDate:assetDate];
-        
-        if (tableAccount.autoUploadCreateSubfolder)
-            serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
-        else
-            serverUrl = autoUploadPath;
-        
-        tableMetadata *metadata = [[NCManageDatabase shared] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.account, serverUrl, fileName]];
-        if (metadata) {
-            
-            if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUpload]) {
-                [[NCManageDatabase shared] addPhotoLibrary:@[asset] account:appDelegate.account];
-            }
-            
-        } else {
-        
-            /* INSERT METADATA FOR UPLOAD */
-            tableMetadata *metadataForUpload = [[NCManageDatabase shared] createMetadataWithAccount:appDelegate.account fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrl urlBase:appDelegate.urlBase url:@"" contentType:@"" livePhoto:livePhoto];
-            
-            metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
-            metadataForUpload.livePhoto = livePhoto;
-            metadataForUpload.session = session;
-            metadataForUpload.sessionSelector = selector;
-            metadataForUpload.size = [[NCUtilityFileSystem shared] getFileSizeWithAsset:asset];
-            metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload;
-            if (assetMediaType == PHAssetMediaTypeVideo) {
-                metadataForUpload.typeFile = NCBrandGlobal.shared.metadataTypeFileVideo;
-            } else if (assetMediaType == PHAssetMediaTypeImage) {
-                metadataForUpload.typeFile = NCBrandGlobal.shared.metadataTypeFileImage;
-            }
-            
-            if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUpload]) {
-               
-                [[NCManageDatabase shared] addMetadataForAutoUpload:metadataForUpload];
-                [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Automatic upload added %@ (%lu bytes) with Identifier %@", metadata.fileNameView, (unsigned long)metadata.size, metadata.assetLocalIdentifier]];
-                [[NCManageDatabase shared] addPhotoLibrary:@[asset] account:appDelegate.account];
-                
-            } else if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-                
-                [metadataFull addObject:metadataForUpload];
-            }
-
-            /* INSERT METADATA MOV LIVE PHOTO FOR UPLOAD */
-            if (livePhoto) {
-                
-                counterLivePhoto++;
-                NSString *fileNameMove = [NSString stringWithFormat:@"%@.mov", fileName.stringByDeletingPathExtension];
-                NSString *ocId = [[NSUUID UUID] UUIDString];
-                NSString *filePath = [CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileNameMove];
-                                
-                [CCUtility extractLivePhotoAsset:asset filePath:filePath withCompletion:^(NSURL *url) {
-                    if (url != nil) {
-                        
-                        unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
-                        tableMetadata *metadataMOVForUpload = [[NCManageDatabase shared] createMetadataWithAccount:appDelegate.account fileName:fileNameMove ocId:ocId serverUrl:serverUrl urlBase:appDelegate.urlBase url:@"" contentType:@"" livePhoto:livePhoto];
-                       
-                        metadataMOVForUpload.livePhoto = true;
-                        metadataMOVForUpload.session = session;
-                        metadataMOVForUpload.sessionSelector = selector;
-                        metadataMOVForUpload.size = fileSize;
-                        metadataMOVForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload;
-                        metadataMOVForUpload.typeFile = NCBrandGlobal.shared.metadataTypeFileVideo;
-
-                        if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUpload]) {
-                            
-                            [[NCManageDatabase shared] addMetadataForAutoUpload:metadataMOVForUpload];
-                            [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Automatic upload added Live Photo %@ (%llu bytes)", fileNameMove, fileSize]];
-                            
-                        } else if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-                            
-                            [metadataFull addObject:metadataMOVForUpload];
-                        }
-                    }
-                    counterLivePhoto--;
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        if (endForAssetToUpload && counterLivePhoto == 0 && [selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-                            [[NCManageDatabase shared] addMetadatas:metadataFull];
-                            [_hud hideHud];
-                        }
-                    });
-                }];
-            }
-        }
-    }
-    endForAssetToUpload = true;
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (counterLivePhoto == 0 && [selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUploadAll]) {
-            [[NCManageDatabase shared] addMetadatas:metadataFull];
-            [_hud hideHud];
-        }
-    });
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== get Camera Roll new Asset ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (NSArray *)getCameraRollAssets:(tableAccount *)account selector:(NSString *)selector alignPhotoLibrary:(BOOL)alignPhotoLibrary
-{
-    @synchronized(self) {
-        
-        if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) {
-            
-            PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil];
-            if (result.count == 0) {
-                return nil;
-            }
-            
-            NSPredicate *predicateImage = [NSPredicate predicateWithFormat:@"mediaType == %i", PHAssetMediaTypeImage];
-            NSPredicate *predicateVideo = [NSPredicate predicateWithFormat:@"mediaType == %i", PHAssetMediaTypeVideo];
-            NSPredicate *predicate;
-
-            NSMutableArray *newAssets =[NSMutableArray new];
-            
-            if (alignPhotoLibrary || (account.autoUploadImage && account.autoUploadVideo)) {
-                
-                predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predicateImage, predicateVideo]];
-                
-            } else if (account.autoUploadImage) {
-                
-                predicate = predicateImage;
-                
-            } else if (account.autoUploadVideo) {
-                
-                predicate = predicateVideo;
-                
-            } else {
-                
-                return nil;
-            }
-            
-            PHFetchOptions *fetchOptions = [PHFetchOptions new];
-            fetchOptions.predicate = predicate;
-            
-            PHAssetCollection *collection = result[0];
-            
-            PHFetchResult *assets = [PHAsset fetchAssetsInAssetCollection:collection options:fetchOptions];
-            
-            if ([selector isEqualToString:NCBrandGlobal.shared.selectorUploadAutoUpload]) {
-            
-                NSString *creationDate;
-                NSString *idAsset;
-
-                NSArray *idsAsset = [[NCManageDatabase shared] getPhotoLibraryIdAssetWithImage:account.autoUploadImage video:account.autoUploadVideo account:account.account];
-                
-                for (PHAsset *asset in assets) {
-                    
-                    (asset.creationDate != nil) ? (creationDate = [NSString stringWithFormat:@"%@", asset.creationDate]) : (creationDate = @"");
-                    
-                    idAsset = [NSString stringWithFormat:@"%@%@%@", account.account, asset.localIdentifier, creationDate];
-                    
-                    if (![idsAsset containsObject: idAsset])
-                        [newAssets addObject:asset];
-                }
-                
-                return newAssets;
-                
-            } else {
-            
-                return (NSArray *)[assets copy];
-            }
-        }
-    }
-    
-    return nil;
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Align Photo Library ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)alignPhotoLibrary
-{
-    tableAccount *account = [[NCManageDatabase shared] getAccountActive];
-
-    NSArray *assets = [self getCameraRollAssets:account selector:NCBrandGlobal.shared.selectorUploadAutoUploadAll alignPhotoLibrary:YES];
-   
-    [[NCManageDatabase shared] clearTable:[tablePhotoLibrary class] account:appDelegate.account];
-    if (assets != nil) {
-        (void)[[NCManageDatabase shared] addPhotoLibrary:assets account:account.account];
-
-        [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Align Photo Library %lu", (unsigned long)[assets count]]];
-    }
-}
-
-@end

+ 52 - 45
iOSClient/AutoUpload/NCAutoUpload.swift

@@ -25,53 +25,15 @@ import Foundation
 import CoreLocation
 import NCCommunication
 
-class NCAutoUpload: NSObject {
+class NCAutoUpload: NSObject, CLLocationManagerDelegate {
     @objc static let shared: NCAutoUpload = {
         let instance = NCAutoUpload()
         return instance
     }()
     
-    func initStateAutoUpload(viewController: UIViewController?) {
-        
-        if let account = NCManageDatabase.shared.getAccountActive() {
-            if account.autoUpload {
-                // [self setupAutoUpload];
-                
-                if account.autoUploadBackground {
-                    NCAskAuthorization.shared.askAuthorizationLocationManager(viewController: viewController) { (hasPermissions) in
-                        if hasPermissions {
-                            NCManageLocation.shared.startSignificantChangeUpdates()
-                        }
-                    }
-                }
-            }
-        } else {
-            NCManageLocation.shared.stopSignificantChangeUpdates()
-        }
-    }
-    
-    @objc func changeLocation() {
-        
-        if let account = NCManageDatabase.shared.getAccountActive() {
-            if account.autoUpload && account.autoUploadBackground && UIApplication.shared.applicationState == UIApplication.State.background {
-            }
-        }
-    }
-}
-
-//MARK: -
-
-//- (void)statusAuthorizationLocationChanged;
-//- (void)changedLocation;
-
-class NCManageLocation: NSObject, CLLocationManagerDelegate {
-    @objc static let shared: NCManageLocation = {
-        let instance = NCManageLocation()
-        return instance
-    }()
-    
     public var locationManager: CLLocationManager?
-    @objc public var firstChangeAuthorizationDone: Bool = false
+
+    // MARK: -
     
     @objc public func startSignificantChangeUpdates() {
         
@@ -82,7 +44,7 @@ class NCManageLocation: NSObject, CLLocationManagerDelegate {
             locationManager?.requestAlwaysAuthorization()
         }
         
-        locationManager?.startMonitoringSignificantLocationChanges()        
+        locationManager?.startMonitoringSignificantLocationChanges()
     }
     
     @objc public func stopSignificantChangeUpdates() {
@@ -98,16 +60,61 @@ class NCManageLocation: NSObject, CLLocationManagerDelegate {
         
         NCCommunicationCommon.shared.writeLog("update location manager: latitude " + latitude + ", longitude " + longitude)
         
-        NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterChangedLocation)
+        changeLocation()
     }
     
     func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
         
-        NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationStatusAuthorizationChangedLocation)
+        statusAuthorizationLocationChanged()
     }
     
     func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
         
-        NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationStatusAuthorizationChangedLocation)
+        statusAuthorizationLocationChanged()
+    }
+    
+    func changeLocation() {
+        
+        if let account = NCManageDatabase.shared.getAccountActive() {
+            if account.autoUpload && account.autoUploadBackground && UIApplication.shared.applicationState == UIApplication.State.background {
+            }
+        }
+    }
+    
+    func statusAuthorizationLocationChanged() {
+        
+    }
+    
+    // MARK: -
+    
+    @objc func initStateAutoUpload(viewController: UIViewController?) {
+        
+        if let account = NCManageDatabase.shared.getAccountActive() {
+            if account.autoUpload {
+                setupAutoUpload()
+                
+                if account.autoUploadBackground {
+                    NCAskAuthorization.shared.askAuthorizationLocationManager(viewController: viewController) { (hasPermissions) in
+                        if hasPermissions {
+                            self.startSignificantChangeUpdates()
+                        }
+                    }
+                }
+            }
+        } else {
+            stopSignificantChangeUpdates()
+        }
+    }
+    
+    @objc func setupAutoUpload() {
+        
+    }
+    
+    @objc func setupAutoUploadFull() {
+        
+    }
+    
+    @objc func alignPhotoLibrary() {
+        
     }
 }

+ 0 - 1
iOSClient/Nextcloud-Bridging-Header.h

@@ -4,7 +4,6 @@
 
 #import "AppDelegate.h"
 #import "CCManageAccount.h"
-#import "CCAutoUpload.h"
 #import "NCEndToEndEncryption.h"
 #import "NYMnemonic.h"
 #import "UIImage+animatedGIF.h"

+ 1 - 1
iOSClient/Settings/CCAdvanced.m

@@ -353,7 +353,7 @@
     
     [CCUtility createDirectoryStandard];
 
-    [[CCAutoUpload shared] alignPhotoLibrary];
+    [[NCAutoUpload shared] alignPhotoLibrary];
 
     // Inizialized home
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCBrandGlobal.shared.notificationCenterInitializeMain object:nil userInfo:nil];

+ 0 - 1
iOSClient/Settings/CCManageAccount.m

@@ -24,7 +24,6 @@
 #import "CCManageAccount.h"
 #import "AppDelegate.h"
 #import "CCLogin.h"
-#import "CCAutoUpload.h"
 #import "NSNotificationCenter+MainThread.h"
 #import "NCBridgeSwift.h"
 

+ 6 - 7
iOSClient/Settings/CCManageAutoUpload.m

@@ -22,7 +22,6 @@
 //
 
 #import "CCManageAutoUpload.h"
-#import "CCAutoUpload.h"
 #import "AppDelegate.h"
 #import "NCBridgeSwift.h"
 
@@ -261,7 +260,7 @@
             }
             
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-                [[CCAutoUpload shared] alignPhotoLibrary];
+                [[NCAutoUpload shared] alignPhotoLibrary];
             });
             
         } else {
@@ -287,7 +286,7 @@
             
             BOOL isLocationIsEnabled = NO;
             
-            [[CCAutoUpload shared] checkIfLocationIsEnabled];
+            //[[CCAutoUpload shared] checkIfLocationIsEnabled];
                             
             if(isLocationIsEnabled == YES) {
                 
@@ -307,7 +306,7 @@
         } else {
             
             [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadBackground" state:NO];
-            [[NCManageLocation shared] stopSignificantChangeUpdates];
+            [[NCAutoUpload shared] stopSignificantChangeUpdates];
         }
     }
 
@@ -315,7 +314,7 @@
         
         if ([[rowDescriptor.value valueData] boolValue] == YES) {
             
-            [[CCAutoUpload shared] setupAutoUploadFull];
+            [[NCAutoUpload shared] setupAutoUploadFull];
             [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
             
         } else {
@@ -331,7 +330,7 @@
 
         if ([[rowDescriptor.value valueData] boolValue] == YES) {
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-                [[CCAutoUpload shared] alignPhotoLibrary];
+                [[NCAutoUpload shared] alignPhotoLibrary];
             });
         }
     }
@@ -347,7 +346,7 @@
 
         if ([[rowDescriptor.value valueData] boolValue] == YES){
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-                [[CCAutoUpload shared] alignPhotoLibrary];
+                [[NCAutoUpload shared] alignPhotoLibrary];
             });
         }
     }

+ 1 - 0
iOSClient/Settings/NCSettings.m

@@ -25,6 +25,7 @@
 #import "AppDelegate.h"
 #import "CCAdvanced.h"
 #import "CCManageAccount.h"
+#import "CCManageAutoUpload.h"
 #import "NCManageEndToEndEncryption.h"
 #import "NCBridgeSwift.h"
 #import "NSNotificationCenter+MainThread.h"

+ 1 - 1
iOSClient/Utility/NCAskAuthorization.swift

@@ -115,7 +115,7 @@ class NCAskAuthorization: NSObject {
             viewController?.present(alert, animated: true, completion: nil)
             break
         case CLAuthorizationStatus.notDetermined:
-            NCManageLocation.shared.startSignificantChangeUpdates()
+            NCAutoUpload.shared.startSignificantChangeUpdates()
             completion(false)
             break
         default: