浏览代码

dev share view

marinofaggiana 5 年之前
父节点
当前提交
b574ff1b8c
共有 2 个文件被更改,包括 52 次插入6 次删除
  1. 9 4
      iOSClient/Database/NCManageDatabase.swift
  2. 43 2
      iOSClient/Share/NCShare.swift

+ 9 - 4
iOSClient/Database/NCManageDatabase.swift

@@ -2620,14 +2620,19 @@ class NCManageDatabase: NSObject {
         return Array(results)
     }
     
-    @objc func getTableSharesV2(metadata: tableMetadata) -> [tableShare]? {
+    func getTableSharesV2(metadata: tableMetadata) -> (firstShareLink: tableShare?,  share: [tableShare]?) {
         
         let realm = try! Realm()
         realm.refresh()
         
-        let results = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, metadata.fileName).sorted(byKeyPath: "fileName", ascending: true)
-        
-        return Array(results.map { tableShare.init(value:$0) })
+        let firstShareLink = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@ AND shareLink != ''", metadata.account, metadata.serverUrl, metadata.fileName).sorted(byKeyPath: "fileName", ascending: true).first
+        if firstShareLink == nil {
+            let results = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, metadata.fileName).sorted(byKeyPath: "fileName", ascending: true)
+            return(firstShareLink: firstShareLink, share: Array(results.map { tableShare.init(value:$0) }))
+        } else {
+            let results = realm.objects(tableShare.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@ AND shareLink != %@", metadata.account, metadata.serverUrl, metadata.fileName, firstShareLink!.shareLink).sorted(byKeyPath: "fileName", ascending: true)
+            return(firstShareLink: firstShareLink, share: Array(results.map { tableShare.init(value:$0) }))
+        }
     }
     
     //MARK: -

+ 43 - 2
iOSClient/Share/NCShare.swift

@@ -259,7 +259,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate {
         shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "")
         addShareLinkButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "add"), width: 40, height: 40, color: UIColor.gray), for: .normal)
 
-        let bottomImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 200, height: 200, color: NCBrandColor.sharedInstance.nextcloud)
+        let bottomImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: 200, height: 200, color: NCBrandColor.sharedInstance.customer)
         let topImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 200, height: 200, color: UIColor.white)
         UIGraphicsBeginImageContextWithOptions(CGSize(width: iconShare, height: iconShare), false, 0.0)
         bottomImage?.draw(in: CGRect(origin: CGPoint.zero, size: CGSize(width: iconShare, height: iconShare)))
@@ -267,7 +267,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate {
         shareLinkImage.image = UIGraphicsGetImageFromCurrentImageContext()
         UIGraphicsEndImageContext()
         
-        sharesTable = NCManageDatabase.sharedInstance.getTableSharesV2(metadata: metadata!)
+        tableView.dataSource = self
+        tableView.delegate = self
     }
     
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -275,6 +276,46 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate {
     }
 }
 
+extension NCShare: UITableViewDelegate {
+    
+    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+        return 60
+    }
+}
+
+extension NCShare: UITableViewDataSource {
+    
+    func numberOfSections(in tableView: UITableView) -> Int {
+        return 1
+    }
+    
+    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        
+        var numOfRows = 0
+        let shares = NCManageDatabase.sharedInstance.getTableSharesV2(metadata: metadata!)
+        
+        if shares.share != nil {
+            numOfRows = shares.share!.count
+        }
+        
+        return numOfRows
+    }
+    
+    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        
+        let shares = NCManageDatabase.sharedInstance.getTableSharesV2(metadata: metadata!)
+        let tableShare = shares.share![indexPath.row]
+        
+        if let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as? activityTableViewCell {
+           
+            
+            return cell
+        }
+        
+        return UITableViewCell()
+    }
+}
+
 // MARK: - AddShareLink
 
 extension NCShare {