Browse Source

new view share

marinofaggiana 5 years ago
parent
commit
864f390998

+ 21 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -2343,7 +2343,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    func getTableShares(account: String, idRemoteShared: Int) -> tableShare? {
+    func getTableShare(account: String, idRemoteShared: Int) -> tableShare? {
         
         let realm = try! Realm()
         realm.refresh()
@@ -2355,6 +2355,26 @@ class NCManageDatabase: NSObject {
         return tableShare.init(value: result)
     }
     
+    @objc func getTableShares(account: String, serverUrl: String) -> [tableShare] {
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@", account, serverUrl)
+
+        return Array(results.map { tableShare.init(value:$0) })
+    }
+    
+    @objc func getTableShares(account: String, serverUrl: String, fileName: String) -> [tableShare] {
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", account, serverUrl, fileName)
+        
+        return Array(results.map { tableShare.init(value:$0) })
+    }
+    
     //MARK: -
     //MARK: Table Tag
     

+ 2 - 1
iOSClient/Favorites/CCFavorites.m

@@ -584,8 +584,9 @@
     }
     
     tableMetadata *metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", directory.fileID]];
+    NSArray *shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:metadata.account serverUrl:metadata.serverUrl fileName:metadata.fileName];
     
-    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:self.serverUrl autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory];
+    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:self.serverUrl autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory shares:shares];
     
     // NORMAL - > MAIN
 

+ 0 - 1
iOSClient/Main/CCMain.h

@@ -79,7 +79,6 @@
 - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID action:(NSInteger)action;
 
 - (void)openShareWithMetadata:(tableMetadata *)metadata;
-- (void)readShareServer;
 
 - (void)clearDateReadDataSource:(NSNotification *)notification;
 - (void)cancelSearchBar;

+ 19 - 15
iOSClient/Main/CCMain.m

@@ -74,6 +74,9 @@
     // Folder
     BOOL _loadingFolder;
     tableMetadata *_metadataFolder;
+    
+    // Share
+    NSArray *shares;
 }
 @end
 
@@ -191,6 +194,9 @@
         [self searchEnabled:YES];
     }
     
+    // Get Shares
+    shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount serverUrl:self.serverUrl];
+    
     // Query data source
     if (!_isSearchMode) {
         [self queryDatasourceWithReloadData:YES serverUrl:self.serverUrl];
@@ -296,7 +302,7 @@
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Initizlize Mail =====
+#pragma mark ===== Initialization =====
 #pragma --------------------------------------------------------------------------------------------
 
 //
@@ -332,15 +338,6 @@
         // Clear error certificate
         [CCUtility setCertificateError:appDelegate.activeAccount error:NO];
         
-        // populate shared Link & User
-        /*
-        NSArray *results = [[NCManageDatabase sharedInstance] getSharesWithAccount:appDelegate.activeAccount];
-        if (results) {
-            appDelegate.sharesLink = results[0];
-            appDelegate.sharesUserAndGroup = results[1];
-        }
-        */
-        
         // Setting Theming
         [appDelegate settingThemingColorBrand];
         
@@ -3728,24 +3725,31 @@
         return [CCCellMain new];
     }
     
-    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory];
+    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory shares:shares];
     
     // NORMAL - > MAIN
     
     if ([cell isKindOfClass:[CCCellMain class]]) {
         
-        NSString *shareLink = @""; //[appDelegate.sharesLink objectForKey:[metadata.serverUrl stringByAppendingString:metadata.fileName]];
-        NSString *shareUserAndGroup = @""; //[appDelegate.sharesUserAndGroup objectForKey:[metadata.serverUrl stringByAppendingString:metadata.fileName]];
         BOOL isShare = false;
         BOOL isMounted = false;
+        BOOL haveYouShare = false;
         
         if (_metadataFolder) {
             isShare = [metadata.permissions containsString:k_permission_shared] && ![_metadataFolder.permissions containsString:k_permission_shared];
             isMounted = [metadata.permissions containsString:k_permission_mounted] && ![_metadataFolder.permissions containsString:k_permission_mounted];
         }
         
+        // have you share ?
+        for (tableShare *share in shares) {
+            if ([share.fileName isEqualToString:metadata.fileName]) {
+                haveYouShare = true;
+                break;
+            }
+        }
+
         // Share add Tap
-        if (isShare || isMounted || shareLink != nil || shareUserAndGroup != nil) {
+        if (isShare || isMounted || haveYouShare) {
             
             if (isShare || isMounted) {
                 
@@ -3756,7 +3760,7 @@
                 ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
                 [((CCCellMain *)cell).shared addGestureRecognizer:tap];
                 
-            } else if (shareLink != nil || shareUserAndGroup != nil) {
+            } else if (haveYouShare) {
                 
                 // You share
                 

+ 36 - 18
iOSClient/Main/NCMainCommon.swift

@@ -215,10 +215,11 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
     
     //MARK: -
     
-    func collectionViewCellForItemAt(_ indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectFileID: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool,source: UIViewController) {
+    func collectionViewCellForItemAt(_ indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectFileID: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController) {
         
         var image: UIImage?
         var isImagePreviewLoaded = false
+        var tableShare: tableShare?
         
         // Image Preview
         if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileName)) {
@@ -232,15 +233,21 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
             }
         }
         
+        // Share
+        if shares != nil {
+            for share in shares! {
+                if share.fileName == metadata.fileName {
+                    tableShare = share
+                    break
+                }
+            }
+        }
+        
         // Download preview
         if downloadThumbnail {
             NCNetworkingMain.sharedInstance.downloadThumbnail(with: metadata, view: collectionView, indexPath: indexPath)
         }
         
-        // Share
-        let sharesLink = "" //appDelegate.sharesLink.object(forKey: serverUrl + metadata.fileName) as? String
-        let sharesUserAndGroup = "" //appDelegate.sharesUserAndGroup.object(forKey: serverUrl + metadata.fileName) as? String
-        
         var isShare = false
         var isMounted = false
         
@@ -274,9 +281,9 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                     image = UIImage.init(named: "folder_shared_with_me")
                 } else if isMounted {
                     image = UIImage.init(named: "folder_external")
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_shared_with_me")
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_public")
                 } else {
                     image = UIImage.init(named: "folder")
@@ -317,10 +324,10 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                 } else if (isMounted) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMounted"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
                 }
@@ -380,9 +387,9 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                     image = UIImage.init(named: "folder_shared_with_me")
                 } else if isMounted {
                     image = UIImage.init(named: "folder_external")
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_shared_with_me")
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_public")
                 } else {
                     image = UIImage.init(named: "folder")
@@ -425,10 +432,10 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                 } else if (isMounted) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMounted"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     cell.imageShare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                     cell.hide(buttonMore: hideButtonMore, hideImageShare: false)
                 }
@@ -491,9 +498,10 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
         }
     }
     
-    @objc func cellForRowAtIndexPath(_ indexPath: IndexPath, tableView: UITableView ,metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, autoUploadFileName: String, autoUploadDirectory: String) -> UITableViewCell {
+    @objc func cellForRowAtIndexPath(_ indexPath: IndexPath, tableView: UITableView ,metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, autoUploadFileName: String, autoUploadDirectory: String, shares: [tableShare]?) -> UITableViewCell {
         
         var image: UIImage?
+        var tableShare: tableShare?
 
         // Create File System
         if metadata.directory {
@@ -502,6 +510,16 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
             CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView)
         }
         
+        // Share
+        if shares != nil {
+            for share in shares! {
+                if share.fileName == metadata.fileName {
+                    tableShare = share
+                    break
+                }
+            }
+        }
+        
         // CCCell
         if metadata.status == k_metadataStatusNormal {
             
@@ -556,9 +574,9 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                     image = UIImage.init(named: "folder_shared_with_me")
                 } else if isMounted {
                     image = UIImage.init(named: "folder_external")
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_shared_with_me")
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     image = UIImage.init(named: "folder_public")
                 } else {
                     image = UIImage.init(named: "folder")
@@ -613,9 +631,9 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                     cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                 } else if (isMounted) {
                     cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMounted"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
-                } else if (sharesLink != nil) {
+                } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
                     cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
-                } else if (sharesUserAndGroup != nil) {
+                } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
                     cell.shared.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
                 }
             }

+ 1 - 1
iOSClient/Media/NCMedia.swift

@@ -468,7 +468,7 @@ extension NCMedia: UICollectionViewDataSource {
         
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
         
-        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: true, downloadThumbnail: false, source: self)
+        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: true, downloadThumbnail: false, shares: nil, source: self)
         
         return cell
     }

+ 3 - 1
iOSClient/Offline/NCOffline.swift

@@ -654,7 +654,9 @@ extension NCOffline: UICollectionViewDataSource {
             cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         
-        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, source: self)
+        let shares = NCManageDatabase.sharedInstance.getTableShares(account: metadata.account, serverUrl: metadata.serverUrl, fileName: metadata.fileName)
+        
+        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: false, downloadThumbnail: true, shares: shares, source: self)
         
         return cell
     }

+ 6 - 1
iOSClient/Select/NCSelect.swift

@@ -82,6 +82,8 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, NCListCellDelegat
     private let sectionHeaderHeight: CGFloat = 20
     private let footerHeight: CGFloat = 50
     
+    private var shares: [tableShare]?
+    
     private let refreshControl = UIRefreshControl()
     
     //BKPasscodeViewController
@@ -162,6 +164,9 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, NCListCellDelegat
             collectionView.collectionViewLayout = gridLayout
         }
         
+        // get shares
+        shares = NCManageDatabase.sharedInstance.getTableShares(account: appDelegate.activeAccount, serverUrl: serverUrl)
+        
         loadDatasource(withLoadFolder: true)
     }
     
@@ -641,7 +646,7 @@ extension NCSelect: UICollectionViewDataSource {
             cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
         }
         
-        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: metadataFolder, serverUrl: serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory ,hideButtonMore: true, downloadThumbnail: true, source: self)
+        NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: metadataFolder, serverUrl: serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory ,hideButtonMore: true, downloadThumbnail: true, shares: shares, source: self)
         
         return cell
     }

+ 1 - 1
iOSClient/Transfers/CCTransfers.m

@@ -510,7 +510,7 @@
         return [CCCellMainTransfer new];
     }
     
-    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:nil serverUrl:metadata.serverUrl autoUploadFileName:@"" autoUploadDirectory:@""];
+    UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:nil serverUrl:metadata.serverUrl autoUploadFileName:@"" autoUploadDirectory:@"" shares:nil];
     
     // TRANSFER