Browse Source

New offline interface

Marino Faggiana 8 years ago
parent
commit
09cf20391c

+ 2 - 2
iOSClient/AppDelegate.m

@@ -641,7 +641,7 @@
                         [nvc popToRootViewControllerAnimated:NO];
                 
                     if ([nvc.topViewController isKindOfClass:[CCOffline class]])
-                        [(CCOffline *)nvc.topViewController forcedSwitchOffline];
+                        NSLog(@"ERROR");//[(CCOffline *)nvc.topViewController forcedSwitchOffline];
                 }
             
                 [tbc setSelectedIndex:TabBarApplicationIndexOffline];
@@ -655,7 +655,7 @@
         
                 UINavigationController *ncOffline = [tbc.viewControllers objectAtIndex:TabBarApplicationIndexOffline];
                 if ([ncOffline.topViewController isKindOfClass:[CCOffline class]])
-                    [(CCOffline *)ncOffline.topViewController forcedSwitchOffline];
+                    NSLog(@"ERROR");//[(CCOffline *)ncOffline.topViewController forcedSwitchOffline];
             
                 [tbc setSelectedIndex:TabBarApplicationIndexOffline];
             }

+ 1 - 32
iOSClient/Offline/CCOffline.h

@@ -25,40 +25,9 @@
 
 #import "CCOfflinePageContent.h"
 
-
-#import "UIScrollView+EmptyDataSet.h"
-#import "TWMessageBarManager.h"
-#import "AHKActionSheet.h"
-#import "CCCellOffline.h"
-#import "CCUtility.h"
-#import "CCCoreData.h"
-#import "CCMain.h"
-#import "CCGraphics.h"
-#import "CCAccountWeb.h"
-#import "CCBancomat.h"
-#import "CCCartaDiCredito.h"
-#import "CCCartaIdentita.h"
-#import "CCContoCorrente.h"
-#import "CCNote.h"
-#import "CCPassaporto.h"
-#import "CCPatenteGuida.h"
-
-@interface CCOffline : UIViewController <UIPageViewControllerDataSource, UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, CCAccountWebDelegate, CCBancomatDelegate, CCCartaDiCreditoDelegate, CCCartaIdentitaDelegate, CCContoCorrenteDelegate, CCNoteDelegate, CCPassaportoDelegate, CCPatenteGuidaDelegate>
+@interface CCOffline : UIViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
 
 @property (strong, nonatomic) UIPageViewController *pageViewController;
 @property (strong, nonatomic) NSArray *pageType;
 
-
-@property (nonatomic, strong) CCMetadata *metadata;
-@property (nonatomic, strong) NSString *fileIDPhoto;
-@property (nonatomic, strong) NSString *directoryIDPhoto;
-
-@property (nonatomic, strong) NSString *localServerUrl;
-@property (nonatomic, strong) NSString *typeOfController;
-
-@property (nonatomic, weak) CCDetail *detailViewController;
-@property (nonatomic, strong) UIDocumentInteractionController *docController;
-
-- (void)forcedSwitchOffline;
-
 @end

+ 15 - 634
iOSClient/Offline/CCOffline.m

@@ -30,7 +30,7 @@
 
 @interface CCOffline ()
 {
-    NSMutableArray *dataSource;
+
 }
 
 @end
@@ -38,23 +38,6 @@
 @implementation CCOffline
 
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Init =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (id)initWithCoder:(NSCoder *)aDecoder
-{
-    if (self = [super initWithCoder:aDecoder])  {
-        
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTable) name:@"reloadTableCCOffline" object:nil];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readFileOffline) name:@"readFileOffline" object:nil];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initToHome) name:@"initToHomeOffline" object:nil];
-        
-        app.activeOffline = self;
-    }
-    return self;
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== View =====
 #pragma --------------------------------------------------------------------------------------------
@@ -69,6 +52,7 @@
     // Create page view controller
     self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OfflinePageViewController"];
     self.pageViewController.dataSource = self;
+    self.pageViewController.delegate = self;
     
     CCOfflinePageContent *startingViewController = [self viewControllerAtIndex:0];
     NSArray *viewControllers = @[startingViewController];
@@ -81,36 +65,6 @@
     [self addChildViewController:_pageViewController];
     [self.view addSubview:_pageViewController.view];
     [self.pageViewController didMoveToParentViewController:self];
-    
-    /*
-    // Custom Cell
-    [self.tableView registerNib:[UINib nibWithNibName:@"CCCellOffline" bundle:nil] forCellReuseIdentifier:@"OfflineCell"];
-        
-    // Settings initial
-    if (!_localServerUrl) {
-        _typeOfController = @"offline";
-        
-        _localServerUrl = nil;
-    }
-    
-    // dataSource
-    dataSource = [NSMutableArray new];
-    
-    // Metadata
-    _metadata = [CCMetadata new];
-    
-    self.tableView.emptyDataSetDelegate = self;
-    self.tableView.emptyDataSetSource = self;
-    self.tableView.tableFooterView = [UIView new];
-    
-    // button
-    UIImage *image;
-    if ([_typeOfController isEqualToString:@"offline"]) {
-        image = [UIImage imageNamed:image_navBarLocal];
-    } else image = [UIImage imageNamed:image_navBarOffline];
-    UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(switchOfflineLocal)];
-    self.navigationItem.rightBarButtonItem=_btn;
-    */ 
 }
 
 // Apparirà
@@ -124,8 +78,6 @@
     
     // Plus Button
     [app plusButtonVisibile:true];
-    
-    [self reloadTable];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -185,596 +137,25 @@
     return 0;
 }
 
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Effetti Grafici =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)forcedSwitchOffline
-{
-     if ([_typeOfController isEqualToString:@"offline"] == NO)
-         [self switchOfflineLocal];
-}
-
-- (void)switchOfflineLocal
-{
-    UIImage *imageBarButton;
-    
-    if ([_typeOfController isEqualToString:@"offline"]) {
-        
-        imageBarButton = [UIImage imageNamed:image_navBarOffline];
-        
-        // img Tab Bar
-        UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:1];
-        
-        item.selectedImage = [UIImage imageNamed:image_tabBarLocal];
-        item.image = [UIImage imageNamed:image_tabBarLocal];
-
-        _localServerUrl = [CCUtility getDirectoryLocal];
-        app.isLocalStorage = true;
-        
-    } else {
-        
-        imageBarButton = [UIImage imageNamed:image_navBarLocal];
-        
-        // Image Tab Bar
-        UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:1];
-        
-        item.selectedImage = [UIImage imageNamed:image_tabBarOffline];
-        item.image = [UIImage imageNamed:image_tabBarOffline];
-
-        _localServerUrl = @"offline";
-        app.isLocalStorage = false;
-    }
-    
-    UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:imageBarButton style:UIBarButtonItemStylePlain target:self action:@selector(switchOfflineLocal)];
-    self.navigationItem.rightBarButtonItem=_btn;
-    
-    // init of Navigation Control
-    [self.navigationController popToRootViewControllerAnimated:NO];
-    
-    // refresh
-    if ([_typeOfController isEqualToString:@"offline"])
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"initToHomeOffline" object:nil];
-    else
-        [self reloadTable];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== DZNEmptyDataSetSource Methods ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
-{
-    if ([_typeOfController isEqualToString:@"Offline"] || [_localServerUrl isEqualToString:[CCUtility getDirectoryLocal]]) return YES;
-    else return NO;
-}
-
-- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
-{
-    return 0.0f;
-}
-
-- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
-{
-    return - self.navigationController.navigationBar.frame.size.height;
-}
-
-- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
-{
-    return [UIColor whiteColor];
-}
-
-- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
-{
-    if ([_typeOfController isEqualToString:@"offline"]) return [UIImage imageNamed:image_brandOffline];
-    else return [UIImage imageNamed:image_brandLocal];
-}
-
-- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
-{
-    NSString *text;
-    
-    if ([_typeOfController isEqualToString:@"offline"]) text = NSLocalizedString(@"_no_files_uploaded_", nil);
-    else text = NSLocalizedString(@"_no_files_uploaded_", nil);
-    
-    NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
-    
-    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
-}
-
-- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
-{
-    NSString *text;
-    
-    if ([_typeOfController isEqualToString:@"offline"]) text = NSLocalizedString(@"_tutorial_offline_view_", nil);
-    else text = NSLocalizedString(@"_tutorial_local_view_", nil);
-    
-    NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
-    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
-    paragraph.alignment = NSTextAlignmentCenter;
-    
-    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
-    
-    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== UIDocumentInteractionControllerDelegate =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
+- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers
 {
-    // evitiamo il rimando della eventuale photo e/o video
-    if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
-        
-        [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
-        [CCCoreData setCameraUploadDateVideo:[NSDate date]];
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== Comandi ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)openModel:(CCMetadata *)metadata
-{
-    UIViewController *viewController;
-    
-    if ([metadata.model isEqualToString:@"cartadicredito"])
-        viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"bancomat"])
-        viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"contocorrente"])
-        viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"accountweb"])
-        viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"patenteguida"])
-        viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"cartaidentita"])
-        viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-    
-    if ([metadata.model isEqualToString:@"passaporto"])
-        viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
+    CCOfflinePageContent *vc = (CCOfflinePageContent *)pendingViewControllers[0];
+    NSString *serverUrl = vc.localServerUrl;
+    NSString *pageType = vc.pageType;
     
-    if ([metadata.model isEqualToString:@"note"]) {
-        
-        viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
-        
-        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-        
-        [self presentViewController:navigationController animated:YES completion:nil];
-        
-    } else {
-        
-         UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-        
-        [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-        
-        [self presentViewController:navigationController animated:YES completion:nil];
-    }
-}
-
-- (void)openWith:(CCMetadata *)metadata
-{
-    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _localServerUrl, metadata.fileNamePrint]];
-    
-    self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
-    
-    self.docController.delegate = self;
-    
-    [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== read file Offline for download =====
-#pragma---------------------------------------------------------------------------------------------
-
-- (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    // error
-}
-
-- (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
-{
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-        
-        [[CCOfflineFileFolder sharedOfflineFileFolder] verifyChangeMedatas:[[NSArray alloc] initWithObjects:metadata, nil] serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount offline:NO];
-    });
-    
-    //[self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
-}
-
-- (void)readFileOffline
-{
-    if (app.activeAccount == nil || [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud] == nil) return;
-    
-    NSArray *metadatas = [[NSArray alloc] init];
-    
-    //metadatas = [CCCoreData getOfflineWithControlZombie:YES activeAccount:app.activeAccount directoryUser:app.directoryUser];
-    
-    for (CCMetadata *metadata in metadatas) {
-        
-        NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
-        if (serverUrl == nil) continue;
-        
-        // if this file is on folder offline skip
-        if ([CCCoreData isOfflineDirectory:serverUrl activeAccount:app.activeAccount])
-            continue;
-
-        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-        
-        metadataNet.action = actionReadFile;
-        metadataNet.fileName = metadata.fileName;
-        metadataNet.fileNamePrint = metadata.fileNamePrint;
-        metadataNet.serverUrl = serverUrl;
-        metadataNet.selector = selectorReadFileOffline;
-        metadataNet.priority = NSOperationQueuePriorityVeryLow;
-        
-        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-    }
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Swipe Table -> menu =====
-#pragma--------------------------------------------------------------------------------------------
-
-// more
-- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    if ([_typeOfController isEqualToString:@"offline"] == NO) {
-        
-        NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
-        NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
-        
-        CCMetadata *metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
-        
-        if (metadata.directory)
-            return nil;
+    if ([pageType isEqualToString:@"Offline"]) {
+        if (serverUrl)
+            self.title = @"Offline";
         else
-            return NSLocalizedString(@"_more_", nil);
-        
-    } else return nil;
-}
-
-- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    UIImage *iconHeader;
-    
-    NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
-    NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
-
-    self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
-    
-    [self setEditing:NO animated:YES];
-    
-    AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
-    
-    actionSheet.animationDuration = 0.2;
-    
-    actionSheet.blurRadius = 0.0f;
-    actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
-    
-    actionSheet.buttonHeight = 50.0;
-    actionSheet.cancelButtonHeight = 50.0f;
-    actionSheet.separatorHeight = 5.0f;
-        
-    actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
-    actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
-    actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
-    actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
-    
-    actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
-    actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
-
-    // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
-    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint]])
-        iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint]];
-    else
-        iconHeader = [UIImage imageNamed:self.metadata.iconName];
-    
-    [actionSheet addButtonWithTitle: _metadata.fileNamePrint
-                              image: iconHeader
-                    backgroundColor: COLOR_NAVBAR_IOS7
-                             height: 50.0
-                               type: AHKActionSheetButtonTypeDisabled
-                            handler: nil
-    ];
-    
-    [actionSheet addButtonWithTitle: NSLocalizedString(@"_open_in_", nil)
-                              image: [UIImage imageNamed:image_actionSheetOpenIn]
-                    backgroundColor: [UIColor whiteColor]
-                             height: 50.0
-                               type: AHKActionSheetButtonTypeDefault
-                            handler: ^(AHKActionSheet *as) {
-                                [self performSelector:@selector(openWith:) withObject:self.metadata];
-                            }];
-
-    [actionSheet show];
-}
-
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    // close swip
-    [self setEditing:NO animated:YES];
-    
-    if ([_typeOfController isEqualToString:@"offline"]) {
-        
-        NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
-        [CCCoreData removeOfflineFileID:[record valueForKey:@"fileID"] activeAccount:app.activeAccount];
-    }
-    
-    if ([_typeOfController isEqualToString:@"offline"] == NO) {
-        
-        NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _localServerUrl,[dataSource objectAtIndex:indexPath.row]];
-        NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl,[dataSource objectAtIndex:indexPath.row]];
-        
-        [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
-        [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
-    }
-    
-    [self reloadTable];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== Table ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)initToHome
-{
-    _typeOfController = @"Offline";
-    
-    UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:image_navBarLocal] style:UIBarButtonItemStylePlain target:self action:@selector(switchOfflineLocal)];
-    self.navigationItem.rightBarButtonItem=_btn;
-    
-    [self reloadTable];
-}
-
-- (void)reloadTable
-{
-    [dataSource removeAllObjects];
-    
-    if ([_typeOfController isEqualToString:@"offline"]) {
-        
-        if (!_localServerUrl) {
-            
-            dataSource = (NSMutableArray*)[CCCoreData getHomeOfflineActiveAccount:app.activeAccount directoryUser:app.directoryUser];
-            
-            self.title = @"offline";
-            
-        } else {
-            
-            NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:_localServerUrl activeAccount:app.activeAccount];
-            NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
-            
-            CCSectionDataSource *sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil replaceDateToExifDate:NO activeAccount:app.activeAccount];
-            
-            for (NSString *key in sectionDataSource.allRecordsDataSource)
-                [dataSource  insertObject:[sectionDataSource.allRecordsDataSource objectForKey:key] atIndex:0 ];
-            
-            self.title = [_localServerUrl lastPathComponent];
-        }
-    }
-    
-    if ([_typeOfController isEqualToString:@"local"]) {
-        
-        NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_localServerUrl error:nil];
-        
-        for (NSString *subpath in subpaths)
-            if (![[subpath lastPathComponent] hasPrefix:@"."]) [dataSource addObject:subpath];
-    }
-    
-    //[self.tableView reloadData];
-}
-
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    return 60;
-}
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
-    return 1;
-}
-
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-{
-    return [dataSource count];
-}
-
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    CCCellOffline *cell = (CCCellOffline *)[tableView dequeueReusableCellWithIdentifier:@"OfflineCell" forIndexPath:indexPath];
-    
-    // change color selection
-    UIView *selectionColor = [[UIView alloc] init];
-    selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
-    cell.selectedBackgroundView = selectionColor;
-
-    // i am in Offline
-    if ([_typeOfController isEqualToString:@"offline"]) {
-    
-        self.metadata = [dataSource objectAtIndex:indexPath.row];
-        cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadata.fileID]];
-    }
-    
-    // i am in local
-    if ([_typeOfController isEqualToString:@"offline"] == NO) {
-        
-        NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
-        NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
-        
-        self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
-        
-        cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint]];
-        
-        if (!cell.fileImageView.image) {
-                        
-            UIImage *icon = [CCGraphics createNewImageFrom:self.metadata.fileID directoryUser:_localServerUrl fileNameTo:self.metadata.fileID fileNamePrint:self.metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
-            
-            if (icon) {
-                [CCGraphics saveIcoWithFileID:self.metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
-                cell.fileImageView.image = icon;
-            }
-        }
-    }
-    
-    // color and font
-    if (self.metadata.cryptated) {
-        cell.labelTitle.textColor = COLOR_ENCRYPTED;
-        //nameLabel.font = RalewayLight(13.0f);
-        cell.labelInfoFile.textColor = [UIColor blackColor];
-        //detailLabel.font = RalewayLight(9.0f);
-    } else {
-        cell.labelTitle.textColor = COLOR_CLEAR;
-        //nameLabel.font = RalewayLight(13.0f);
-        cell.labelInfoFile.textColor = [UIColor blackColor];
-        //detailLabel.font = RalewayLight(9.0f);
-    }
-
-    if (self.metadata.directory) {
-        cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
-        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-    }
-    
-    // File name
-    cell.labelTitle.text = self.metadata.fileNamePrint;
-    cell.labelInfoFile.text = @"";
-    
-    // Immagine del file, se non c'è l'anteprima mettiamo quella standard
-    if (cell.fileImageView.image == nil)
-        cell.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
-    
-    cell.statusImageView.image = nil;
-    
-    // it's encrypted ???
-    if (self.metadata.cryptated && [self.metadata.type isEqualToString:metadataType_model] == NO)
-        cell.statusImageView.image = [UIImage imageNamed:image_lock];
-    
-    // it's in download mode
-    if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound)
-        cell.statusImageView.image = [UIImage imageNamed:image_attention];
-    
-    // text and length
-    if (self.metadata.directory) {
-        
-        cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
-        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-        
-    } else {
-        
-        NSString *date = [CCUtility dateDiff:self.metadata.date];
-        NSString *length = [CCUtility transformedSize:self.metadata.size];
-        
-        if ([self.metadata.type isEqualToString:metadataType_model])
-            cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
-        
-        if ([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local])
-            cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", date, length];
-        
-        cell.accessoryType = UITableViewCellAccessoryNone;
-        
-    }
-    
-    return cell;
-}
-
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
-    // deselect row
-    [tableView deselectRowAtIndexPath:indexPath animated:YES];
-        
-    if ([_typeOfController isEqualToString:@"offline"]) {
-        
-        NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
-        self.fileIDPhoto = [record valueForKey:@"fileID"];
-        self.metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", self.fileIDPhoto, app.activeAccount] context:nil];
-    }
-    
-    if ([_typeOfController isEqualToString:@"local"]) {
-        
-        NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
-        NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
-        
-        self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
-        self.fileIDPhoto = self.metadata.fileID;
-    }
-    
-    // if is in download [do not touch]
-    if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound) return;
-    
-    if (([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local]) && self.metadata.directory == NO) {
-        
-        if ([self shouldPerformSegue])
-            [self performSegueWithIdentifier:@"segueDetail" sender:self];
+            self.title = @"Offline";
     }
     
-    if ([self.metadata.type isEqualToString:metadataType_model]) [self openModel:self.metadata];
-    
-    if (self.metadata.directory)
-        [self performSegueDirectoryWithControlPasscode];
-}
-
--(void)performSegueDirectoryWithControlPasscode
-{
-    CCOffline *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineViewController"];
-    
-    NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
-    
-    vc.localServerUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:_metadata.fileName];
-    vc.typeOfController = _typeOfController;
-
-    [self.navigationController pushViewController:vc animated:YES];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Navigation ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (BOOL)shouldPerformSegue
-{
-    // if i am in background -> exit
-    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
-    
-    // if i am not window -> exit
-    if (self.view.window == NO)
-        return NO;
-
-    // Collapsed but i am in detail -> exit
-    if (self.splitViewController.isCollapsed)
-        if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
-    
-    // Video in run -> exit
-    if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
-    
-    return YES;
-}
-
--(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
-{
-    id viewController = segue.destinationViewController;
-    
-    if ([viewController isKindOfClass:[UINavigationController class]]) {
-        UINavigationController *nav = viewController;
-        self.detailViewController = (CCDetail *)nav.topViewController;
-    } else {
-        self.detailViewController = segue.destinationViewController;
+    if ([pageType isEqualToString:@"Local"]) {
+        if ([serverUrl isEqualToString:[CCUtility getDirectoryLocal]])
+            self.title = @"Local";
+        else
+            self.title = @"Local";
     }
-    
-    self.detailViewController.metadataDetail = self.metadata;
-    
-    if (app.isLocalStorage) self.detailViewController.sourceDirectory = sorceDirectoryLocal;
-    else self.detailViewController.sourceDirectory = sorceDirectoryOffline;
-    
-    self.detailViewController.dateFilterQuery = nil;
-    self.detailViewController.isCameraUpload = NO;
-    
-    [self.detailViewController setTitle:self.metadata.fileNamePrint];
 }
 
 @end

+ 23 - 1
iOSClient/Offline/CCOfflinePageContent.h

@@ -9,13 +9,35 @@
 #import <UIKit/UIKit.h>
 
 #import "CCDetail.h"
+#import "UIScrollView+EmptyDataSet.h"
+#import "TWMessageBarManager.h"
+#import "AHKActionSheet.h"
+#import "CCCellOffline.h"
+#import "CCUtility.h"
+#import "CCCoreData.h"
+#import "CCMain.h"
+#import "CCGraphics.h"
+#import "CCAccountWeb.h"
+#import "CCBancomat.h"
+#import "CCCartaDiCredito.h"
+#import "CCCartaIdentita.h"
+#import "CCContoCorrente.h"
+#import "CCNote.h"
+#import "CCPassaporto.h"
+#import "CCPatenteGuida.h"
 
-@interface CCOfflinePageContent : UITableViewController
+@interface CCOfflinePageContent : UITableViewController <UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIActionSheetDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, CCAccountWebDelegate, CCBancomatDelegate, CCCartaDiCreditoDelegate, CCCartaIdentitaDelegate, CCContoCorrenteDelegate, CCNoteDelegate, CCPassaportoDelegate, CCPatenteGuidaDelegate>
 
 @property NSUInteger pageIndex;
 @property (nonatomic, strong) NSString *pageType;
 
 
+@property (nonatomic, strong) CCMetadata *metadata;
+@property (nonatomic, strong) NSString *fileIDPhoto;
+@property (nonatomic, strong) NSString *directoryIDPhoto;
+
+@property (nonatomic, strong) NSString *localServerUrl;
+
 @property (nonatomic, weak) CCDetail *detailViewController;
 @property (nonatomic, strong) UIDocumentInteractionController *docController;
 

+ 254 - 49
iOSClient/Offline/CCOfflinePageContent.m

@@ -8,92 +8,297 @@
 
 #import "CCOfflinePageContent.h"
 
-@interface CCOfflinePageContent ()
+#import "AppDelegate.h"
 
+@interface CCOfflinePageContent ()
+{
+    NSMutableArray *dataSource;
+}
 @end
 
 @implementation CCOfflinePageContent
 
 - (void)viewDidLoad {
+    
     [super viewDidLoad];
     
+    // Custom Cell
+    [self.tableView registerNib:[UINib nibWithNibName:@"CCCellOffline" bundle:nil] forCellReuseIdentifier:@"OfflineCell"];
+
+    // dataSource
+    dataSource = [NSMutableArray new];
+    
+    // Metadata
+    _metadata = [CCMetadata new];
+    
+    self.tableView.emptyDataSetDelegate = self;
+    self.tableView.emptyDataSetSource = self;
+    self.tableView.tableFooterView = [UIView new];
+    
+    // Type
+    if ([self.pageType isEqualToString:@"Offline"] && !_localServerUrl) {
+        _localServerUrl = nil;
+    }
+    
+    if ([self.pageType isEqualToString:@"Local"] && !_localServerUrl) {
+        _localServerUrl = [CCUtility getDirectoryLocal];
+    }
+    
 }
 
 // Apparirà
 - (void)viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:animated];
+    
+    [self reloadTable];
 }
 
 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
-    // Dispose of any resources that can be recreated.
 }
 
-#pragma mark - Table view data source
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ==== Table ====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)reloadTable
+{
+    [dataSource removeAllObjects];
+    
+    if ([_pageType isEqualToString:@"Offline"]) {
+        
+        if (!_localServerUrl) {
+            
+            dataSource = (NSMutableArray*)[CCCoreData getHomeOfflineActiveAccount:app.activeAccount directoryUser:app.directoryUser];
+            
+        } else {
+            
+            NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:_localServerUrl activeAccount:app.activeAccount];
+            NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
+            
+            CCSectionDataSource *sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil replaceDateToExifDate:NO activeAccount:app.activeAccount];
+            
+            for (NSString *key in sectionDataSource.allRecordsDataSource)
+                [dataSource  insertObject:[sectionDataSource.allRecordsDataSource objectForKey:key] atIndex:0 ];
+        }
+    }
+    
+    if ([_pageType isEqualToString:@"Local"]) {
+        
+        NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_localServerUrl error:nil];
+        
+        for (NSString *subpath in subpaths)
+            if (![[subpath lastPathComponent] hasPrefix:@"."])
+                [dataSource addObject:subpath];
+    }
+    
+    [self.tableView reloadData];
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    return 60;
+}
 
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-#warning Incomplete implementation, return the number of sections
-    return 0;
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return 1;
 }
 
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-#warning Incomplete implementation, return the number of rows
-    return 0;
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return [dataSource count];
 }
 
-/*
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    CCCellOffline *cell = (CCCellOffline *)[tableView dequeueReusableCellWithIdentifier:@"OfflineCell" forIndexPath:indexPath];
+    
+    // change color selection
+    UIView *selectionColor = [[UIView alloc] init];
+    selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
+    cell.selectedBackgroundView = selectionColor;
+    
+    // i am in Offline
+    if ([_pageType isEqualToString:@"Offline"]) {
+        
+        self.metadata = [dataSource objectAtIndex:indexPath.row];
+        cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadata.fileID]];
+    }
+    
+    // i am in local
+    if ([_pageType isEqualToString:@"Local"]) {
+        
+        NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
+        NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
+        
+        self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
+        
+        cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint]];
+        
+        if (!cell.fileImageView.image) {
+            
+            UIImage *icon = [CCGraphics createNewImageFrom:self.metadata.fileID directoryUser:_localServerUrl fileNameTo:self.metadata.fileID fileNamePrint:self.metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
+            
+            if (icon) {
+                [CCGraphics saveIcoWithFileID:self.metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, self.metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
+                cell.fileImageView.image = icon;
+            }
+        }
+    }
+    
+    // color and font
+    if (self.metadata.cryptated) {
+        cell.labelTitle.textColor = COLOR_ENCRYPTED;
+        //nameLabel.font = RalewayLight(13.0f);
+        cell.labelInfoFile.textColor = [UIColor blackColor];
+        //detailLabel.font = RalewayLight(9.0f);
+    } else {
+        cell.labelTitle.textColor = COLOR_CLEAR;
+        //nameLabel.font = RalewayLight(13.0f);
+        cell.labelInfoFile.textColor = [UIColor blackColor];
+        //detailLabel.font = RalewayLight(9.0f);
+    }
+    
+    if (self.metadata.directory) {
+        cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
+        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+    }
+    
+    // File name
+    cell.labelTitle.text = self.metadata.fileNamePrint;
+    cell.labelInfoFile.text = @"";
     
-    // Configure the cell...
+    // Immagine del file, se non c'è l'anteprima mettiamo quella standard
+    if (cell.fileImageView.image == nil)
+        cell.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
+    
+    cell.statusImageView.image = nil;
+    
+    // it's encrypted ???
+    if (self.metadata.cryptated && [self.metadata.type isEqualToString:metadataType_model] == NO)
+        cell.statusImageView.image = [UIImage imageNamed:image_lock];
+    
+    // it's in download mode
+    if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound)
+        cell.statusImageView.image = [UIImage imageNamed:image_attention];
+    
+    // text and length
+    if (self.metadata.directory) {
+        
+        cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
+        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+        
+    } else {
+        
+        NSString *date = [CCUtility dateDiff:self.metadata.date];
+        NSString *length = [CCUtility transformedSize:self.metadata.size];
+        
+        if ([self.metadata.type isEqualToString:metadataType_model])
+            cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
+        
+        if ([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local])
+            cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", date, length];
+        
+        cell.accessoryType = UITableViewCellAccessoryNone;
+        
+    }
     
     return cell;
 }
-*/
 
-/*
-// Override to support conditional editing of the table view.
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
-    // Return NO if you do not want the specified item to be editable.
-    return YES;
-}
-*/
-
-/*
-// Override to support editing the table view.
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-    if (editingStyle == UITableViewCellEditingStyleDelete) {
-        // Delete the row from the data source
-        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
-    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
-        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
-    }   
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    // deselect row
+    [tableView deselectRowAtIndexPath:indexPath animated:YES];
+    
+    if ([_pageType isEqualToString:@"Offline"]) {
+        
+        NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
+        self.fileIDPhoto = [record valueForKey:@"fileID"];
+        self.metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", self.fileIDPhoto, app.activeAccount] context:nil];
+    }
+    
+    if ([_pageType isEqualToString:@"Local"]) {
+        
+        NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
+        NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
+        
+        self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
+        self.fileIDPhoto = self.metadata.fileID;
+    }
+    
+    // if is in download [do not touch]
+    if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound) return;
+    
+    if (([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local]) && self.metadata.directory == NO) {
+        
+        if ([self shouldPerformSegue])
+            [self performSegueWithIdentifier:@"segueDetail" sender:self];
+    }
+    
+    //if ([self.metadata.type isEqualToString:metadataType_model]) [self openModel:self.metadata];
+    
+    if (self.metadata.directory)
+        [self performSegueDirectoryWithControlPasscode];
 }
-*/
 
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+-(void)performSegueDirectoryWithControlPasscode
+{
+    CCOffline *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineViewController"];
+    
+    NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
+    
+    //vc.localServerUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:_metadata.fileName];
+    //vc.typeOfController = _typeOfController;
+    
+    [self.navigationController pushViewController:vc animated:YES];
 }
-*/
 
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
-    // Return NO if you do not want the item to be re-orderable.
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Navigation ====
+#pragma --------------------------------------------------------------------------------------------
+
+- (BOOL)shouldPerformSegue
+{
+    // if i am in background -> exit
+    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
+    
+    // if i am not window -> exit
+    if (self.view.window == NO)
+        return NO;
+    
+    // Collapsed but i am in detail -> exit
+    if (self.splitViewController.isCollapsed)
+        if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
+    
+    // Video in run -> exit
+    if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
+    
     return YES;
 }
-*/
 
-/*
-#pragma mark - Navigation
-
-// In a storyboard-based application, you will often want to do a little preparation before navigation
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
-    // Get the new view controller using [segue destinationViewController].
-    // Pass the selected object to the new view controller.
+-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+    id viewController = segue.destinationViewController;
+    
+    if ([viewController isKindOfClass:[UINavigationController class]]) {
+        UINavigationController *nav = viewController;
+        self.detailViewController = (CCDetail *)nav.topViewController;
+    } else {
+        self.detailViewController = segue.destinationViewController;
+    }
+    
+    self.detailViewController.metadataDetail = self.metadata;
+    
+    if (app.isLocalStorage) self.detailViewController.sourceDirectory = sorceDirectoryLocal;
+    else self.detailViewController.sourceDirectory = sorceDirectoryOffline;
+    
+    self.detailViewController.dateFilterQuery = nil;
+    self.detailViewController.isCameraUpload = NO;
+    
+    [self.detailViewController setTitle:self.metadata.fileNamePrint];
 }
-*/
 
 @end