marinofaggiana 4 năm trước cách đây
mục cha
commit
346b22c5cd
3 tập tin đã thay đổi với 21 bổ sung71 xóa
  1. 11 61
      iOSClient/Media/NCMedia.swift
  2. 2 2
      iOSClient/Utility/CCUtility.h
  3. 8 8
      iOSClient/Utility/CCUtility.m

+ 11 - 61
iOSClient/Media/NCMedia.swift

@@ -48,7 +48,6 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     private var filterTypeFileVideo = false
             
     private let maxImageGrid: CGFloat = 7
-    private let minImageWidth: CGFloat = 70
     private var cellHeigth: CGFloat = 0
 
     private var oldInProgress = false
@@ -85,7 +84,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         collectionView.contentInset = UIEdgeInsets(top: 75, left: 0, bottom: 50, right: 0);
                 
         gridLayout = NCGridMediaLayout()
-        gridLayout.itemForLine = CGFloat(CCUtility.getMediaItemImage())
+        gridLayout.itemForLine = CGFloat(min(CCUtility.getMediaWidthImage(), 5))
         gridLayout.sectionHeadersPinToVisibleBounds = true
 
         collectionView.collectionViewLayout = gridLayout
@@ -107,11 +106,8 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         mediaCommandView = Bundle.main.loadNibNamed("NCMediaCommandView", owner: self, options: nil)?.first as? NCMediaCommandView
         self.view.addSubview(mediaCommandView!)
         mediaCommandView?.mediaView = self
-        
-        let newItemWidth = self.gridLayout.getItemWidth(itemForLine: gridLayout.itemForLine + 1)
-        mediaCommandView?.zoomOutButton.isEnabled = (newItemWidth > minImageWidth)
         mediaCommandView?.zoomInButton.isEnabled = !(gridLayout.itemForLine == 1)
-
+        mediaCommandView?.zoomOutButton.isEnabled = !(gridLayout.itemForLine == maxImageGrid - 1)
         mediaCommandView?.collapseControlButtonView(true)
         mediaCommandView?.translatesAutoresizingMaskIntoConstraints = false
         mediaCommandView?.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
@@ -179,15 +175,16 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     
     @objc func zoomOutGrid() {
         UIView.animate(withDuration: 0.0, animations: {
-            let newItemWidth = self.gridLayout.getItemWidth(itemForLine: self.gridLayout.itemForLine + 1)
-            if newItemWidth > self.minImageWidth {
+            if(self.gridLayout.itemForLine + 1 < self.maxImageGrid) {
                 self.gridLayout.itemForLine += 1
                 self.mediaCommandView?.zoomInButton.isEnabled = true
-            } else {
+            }
+            if(self.gridLayout.itemForLine == self.maxImageGrid - 1) {
                 self.mediaCommandView?.zoomOutButton.isEnabled = false
             }
-        
+
             self.collectionView.collectionViewLayout.invalidateLayout()
+            CCUtility.setMediaWidthImage(Int(self.gridLayout.itemForLine))
         })
     }
 
@@ -202,6 +199,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
             }
 
             self.collectionView.collectionViewLayout.invalidateLayout()
+            CCUtility.setMediaWidthImage(Int(self.gridLayout.itemForLine))
         })
     }
     
@@ -967,10 +965,6 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
     var marginLeftRight: CGFloat = 6
     var itemForLine: CGFloat = 3
     
-    var itemWidth: CGFloat = 0
-    var frameWidth: CGFloat = 0
-    var itemDiff: Int = 0
-    
     override init() {
         super.init()
         
@@ -991,48 +985,10 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
         get {
             if let collectionView = collectionView {
                 
-                if frameWidth == 0 {
-                    
-                    frameWidth = collectionView.frame.width
-                   
-                } else if collectionView.frame.width > frameWidth {
-                    
-                    if itemDiff < 0 {
-                        
-                        itemForLine += CGFloat(itemDiff)
-                        itemDiff = 0
-                        
-                    } else if itemDiff == 0 {
-                        
-                        let diff = collectionView.frame.width - collectionView.frame.height
-                        
-                        itemDiff = Int(diff / itemWidth)
-                        itemForLine += CGFloat(itemDiff)
-                    }
-                                        
-                } else if collectionView.frame.width < frameWidth {
-                    
-                    if itemDiff > 0 {
-                    
-                        itemForLine -= CGFloat(itemDiff)
-                        itemDiff = 0
-                        
-                    } else {
-                        
-                        let diff = collectionView.frame.height - collectionView.frame.width
-                        
-                        itemDiff = Int(diff / itemWidth)
-                        itemForLine -= CGFloat(itemDiff)
-                    }
-                }
-                
-                frameWidth = collectionView.frame.width
-                if itemForLine <= 0 { itemForLine = 1 }
-                itemWidth = getItemWidth(itemForLine: itemForLine)
+                let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine
+                let itemHeight: CGFloat = itemWidth
                 
-                CCUtility.setMediaItemImage(Int(itemForLine))
-
-                return CGSize(width: itemWidth, height: itemWidth)
+                return CGSize(width: itemWidth, height: itemHeight)
             }
             
             // Default fallback
@@ -1046,11 +1002,5 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
     override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
         return proposedContentOffset
     }
-    
-    public func getItemWidth(itemForLine: CGFloat) -> CGFloat {
-        
-        let itemWidth = (frameWidth - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine
-        return itemWidth
-    }
 }
 

+ 2 - 2
iOSClient/Utility/CCUtility.h

@@ -130,8 +130,8 @@
 + (NSString *)getPushNotificationDeviceIdentifierSignature:(NSString *)account;
 + (void)clearAllKeysPushNotification:(NSString *)account;
 
-+ (NSInteger)getMediaItemImage;
-+ (void)setMediaItemImage:(NSInteger)item;
++ (NSInteger)getMediaWidthImage;
++ (void)setMediaWidthImage:(NSInteger)width;
 
 + (BOOL)getDisableCrashservice;
 + (void)setDisableCrashservice:(BOOL)disable;

+ 8 - 8
iOSClient/Utility/CCUtility.m

@@ -476,21 +476,21 @@
     [self setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:nil];
 }
 
-+ (NSInteger)getMediaItemImage
++ (NSInteger)getMediaWidthImage
 {
-    NSString *item = [UICKeyChainStore stringForKey:@"mediaItemImage" service:NCBrandGlobal.shared.serviceShareKeyChain];
+    NSString *width = [UICKeyChainStore stringForKey:@"mediaWidthImage" service:NCBrandGlobal.shared.serviceShareKeyChain];
     
-    if (item == nil) {
-        return 5;
+    if (width == nil) {
+        return 80;
     } else {
-        return [item integerValue];
+        return [width integerValue];
     }
 }
 
-+ (void)setMediaItemImage:(NSInteger)item
++ (void)setMediaWidthImage:(NSInteger)width
 {
-    NSString *widthString = [@(item) stringValue];
-    [UICKeyChainStore setString:widthString forKey:@"mediaItemImage" service:NCBrandGlobal.shared.serviceShareKeyChain];
+    NSString *widthString = [@(width) stringValue];
+    [UICKeyChainStore setString:widthString forKey:@"mediaWidthImage" service:NCBrandGlobal.shared.serviceShareKeyChain];
 }
 
 + (BOOL)getDisableCrashservice