marinofaggiana 4 years ago
parent
commit
a31c11ee4b
2 changed files with 51 additions and 15 deletions
  1. 10 1
      iOSClient/Shares/NCShares.storyboard
  2. 41 14
      iOSClient/Shares/NCShares.swift

+ 10 - 1
iOSClient/Shares/NCShares.storyboard

@@ -11,7 +11,7 @@
         <!--Shares-->
         <scene sceneID="X4W-6b-l7s">
             <objects>
-                <viewController storyboardIdentifier="NCFavorite.storyboard" extendedLayoutIncludesOpaqueBars="YES" id="EFX-fO-Oip" customClass="NCShares" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
+                <viewController storyboardIdentifier="NCOffline.storyboard" extendedLayoutIncludesOpaqueBars="YES" id="EFX-fO-Oip" customClass="NCShares" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
                     <view key="view" contentMode="scaleToFill" id="QEs-gO-Cmp">
                         <rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -43,11 +43,20 @@
                     </view>
                     <connections>
                         <outlet property="collectionView" destination="Zaz-Cl-qpZ" id="8oA-Gx-z7T"/>
+                        <segue destination="rIl-hI-jAh" kind="showDetail" identifier="segueDetail" id="MHI-ti-PGq"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="JJ0-Le-6eT" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
             <point key="canvasLocation" x="256.80000000000001" y="228.32512315270938"/>
         </scene>
+        <!--NCDetail-->
+        <scene sceneID="D5y-IR-BuC">
+            <objects>
+                <viewControllerPlaceholder storyboardName="NCDetail" referencedIdentifier="NCDetail" id="rIl-hI-jAh" sceneMemberID="viewController"/>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="eCA-Ct-z68" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="1080" y="228"/>
+        </scene>
     </scenes>
 </document>

+ 41 - 14
iOSClient/Shares/NCShares.swift

@@ -68,25 +68,52 @@ class NCShares: NCCollectionViewCommon  {
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
         
-        NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
+        if serverUrl == "" {
             
-            self.refreshControl.endRefreshing()
-            self.isReloadDataSourceNetworkInProgress = false
-            
-            if errorCode == 0 {
+            NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
                 
-                NCManageDatabase.sharedInstance.deleteTableShare(account: account)
-                if shares != nil {
-                    NCManageDatabase.sharedInstance.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
-                }
-                self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: account)
+                self.refreshControl.endRefreshing()
+                self.isReloadDataSourceNetworkInProgress = false
                 
-                self.reloadDataSource()
+                if errorCode == 0 {
+                    
+                    NCManageDatabase.sharedInstance.deleteTableShare(account: account)
+                    if shares != nil {
+                        NCManageDatabase.sharedInstance.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
+                    }
+                    self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: account)
+                    
+                    self.reloadDataSource()
+                    
+                } else {
+                    
+                    self.collectionView?.reloadData()
+                    NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                }
+            }
+            
+        } else {
+                        
+            networkReadFolder(forced: forced) { (metadatas, metadatasUpdate, errorCode, errorDescription) in
+                if errorCode == 0 {
+                    for metadata in metadatas ?? [] {
+                        if !metadata.directory {
+                            let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                            if localFile == nil || localFile?.etag != metadata.etag {
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
+                            }
+                        }
+                    }
+                }
                 
-            } else {
+                self.refreshControl.endRefreshing()
+                self.isReloadDataSourceNetworkInProgress = false
                 
-                self.collectionView?.reloadData()
-                NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                if metadatasUpdate?.count ?? 0 > 0 || forced {
+                    self.reloadDataSource()
+                } else {
+                    self.collectionView?.reloadData()
+                }
             }
         }
     }