Browse Source

Small Media view refresh

Signed-off-by: Philippe Weidmann <philippe.weidmann@infomaniak.com>
Philippe Weidmann 4 years ago
parent
commit
f7c6f672d2

+ 24 - 6
iOSClient/Main/Layout/NCLayout.swift

@@ -111,8 +111,9 @@ class NCGridLayout: UICollectionViewFlowLayout {
 
 class NCGridMediaLayout: UICollectionViewFlowLayout {
     
-    var preferenceWidth: CGFloat = 110
-    var marginLeftRight: CGFloat = 1
+    var increasing = true
+    var itemPerLine: CGFloat = 3
+    var marginLeftRight: CGFloat = 6
     var numItems: Int = 0
     
     override init() {
@@ -120,8 +121,8 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
         
         sectionHeadersPinToVisibleBounds = false
         
-        minimumInteritemSpacing = 1
-        minimumLineSpacing = 1
+        minimumInteritemSpacing = 0
+        minimumLineSpacing = marginLeftRight
         
         self.scrollDirection = .vertical
         self.sectionInset = UIEdgeInsets(top: 0, left: marginLeftRight, bottom: 0, right:  marginLeftRight)
@@ -135,9 +136,9 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
         get {
             if let collectionView = collectionView {
                 
-                self.numItems = Int(collectionView.frame.width / preferenceWidth)
-                let itemWidth: CGFloat = (collectionView.frame.width - (marginLeftRight * 2) - CGFloat(numItems)) / CGFloat(numItems)
+                let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemPerLine - 1)) / itemPerLine
                 let itemHeight: CGFloat = itemWidth
+                
                 return CGSize(width: itemWidth, height: itemHeight)
             }
             
@@ -153,3 +154,20 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
         return proposedContentOffset
     }
 }
+extension UICollectionView {
+
+var centerPoint : CGPoint {
+
+    get {
+        return CGPoint(x: self.center.x + self.contentOffset.x, y: self.center.y + self.contentOffset.y);
+    }
+}
+
+var centerCellIndexPath: IndexPath? {
+
+    if let centerIndexPath: IndexPath  = self.indexPathForItem(at: self.centerPoint) {
+        return centerIndexPath
+    }
+    return nil
+}
+}

+ 4 - 0
iOSClient/Main/NCMainCommon.swift

@@ -475,6 +475,8 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
             cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
             cell.accessoryType = UITableViewCell.AccessoryType.none
             cell.file.image = nil
+            cell.file.layer.cornerRadius = 6
+            cell.file.layer.masksToBounds = true
             cell.status.image = nil
             cell.favorite.image = nil
             cell.shared.image = nil
@@ -646,6 +648,8 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
             cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
             cell.accessoryType = UITableViewCell.AccessoryType.none
             cell.file.image = nil
+            cell.file.layer.cornerRadius = 6
+            cell.file.layer.masksToBounds = true
             cell.status.image = nil
             cell.user.image = nil
             

+ 17 - 20
iOSClient/Media/NCMedia.swift

@@ -47,6 +47,7 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     private let footerHeight: CGFloat = 50
     
     private var stepImageWidth: CGFloat = 10
+    private let kMaxImageGrid: CGFloat = 5
     
     private var isDistantPast = false
 
@@ -84,7 +85,7 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
         collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0);
                 
         gridLayout = NCGridMediaLayout()
-        gridLayout.preferenceWidth = CGFloat(CCUtility.getMediaWidthImage())
+        gridLayout.itemPerLine = CGFloat(min(CCUtility.getMediaWidthImage(), 5))
         gridLayout.sectionHeadersPinToVisibleBounds = true
 
         collectionView.collectionViewLayout = gridLayout
@@ -237,29 +238,21 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
     // MARK: IBAction
     
     @objc func touchUpInsideMenuButtonSwitch(_ sender: Any) {
-        
-        let itemSizeStart = self.gridLayout.itemSize
-        
+                
         UIView.animate(withDuration: 0.0, animations: {
-            
-            if self.gridLayout.numItems == 1 && self.stepImageWidth > 0 {
-                self.stepImageWidth = -10
-            } else if itemSizeStart.width < 50 {
-                self.stepImageWidth = 10
+            if(self.gridLayout.itemPerLine + 1 < self.kMaxImageGrid && self.gridLayout.increasing) {
+                self.gridLayout.itemPerLine+=1
+            } else {
+                self.gridLayout.increasing = false
+                self.gridLayout.itemPerLine-=1
+            }
+            if(self.gridLayout.itemPerLine == 0) {
+                self.gridLayout.increasing = true
+                self.gridLayout.itemPerLine = 2
             }
             
-            repeat {
-                self.gridLayout.preferenceWidth = self.gridLayout.preferenceWidth + self.stepImageWidth
-            } while (self.gridLayout.itemSize == itemSizeStart)
-            
-            CCUtility.setMediaWidthImage(Int(self.gridLayout?.preferenceWidth ?? 80))
             self.collectionView.collectionViewLayout.invalidateLayout()
-            
-            if self.stepImageWidth < 0 {
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                    self.selectSearchSections()
-                }
-            }
+            CCUtility.setMediaWidthImage(Int(self.gridLayout.itemPerLine))
         })
     }
     
@@ -485,6 +478,10 @@ extension NCMedia: UICollectionViewDataSource {
         cell.imageStatus.image = nil
         cell.imageLocal.image = nil
         cell.imageFavorite.image = nil
+        cell.imageItem.layer.masksToBounds = true
+        cell.imageItem.layer.cornerRadius = 6
+        cell.imageVisualEffect.layer.cornerRadius = 6
+        cell.imageVisualEffect.clipsToBounds = true
                     
         if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
             cell.imageItem.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))