Browse Source

Build 10

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
7df06e3cb5
1 changed files with 29 additions and 34 deletions
  1. 29 34
      iOSClient/Media/NCMedia.swift

+ 29 - 34
iOSClient/Media/NCMedia.swift

@@ -244,10 +244,9 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     // MARK: - Command
 
     func mediaCommandTitle() {
-        mediaCommandView?.title.text = ""
 
+        mediaCommandView?.title.text = ""
         if let visibleCells = self.collectionView?.indexPathsForVisibleItems.sorted(by: { $0.row < $1.row }).compactMap({ self.collectionView?.cellForItem(at: $0) }) {
-
             if let cell = visibleCells.first as? NCGridMediaCell {
                 if cell.date != nil {
                     mediaCommandView?.title.text = CCUtility.getTitleSectionDate(cell.date)
@@ -257,6 +256,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     }
 
     @objc func zoomOutGrid() {
+
         UIView.animate(withDuration: 0.0, animations: {
             if self.gridLayout.itemForLine + 1 < self.maxImageGrid {
                 self.gridLayout.itemForLine += 1
@@ -272,6 +272,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     }
 
     @objc func zoomInGrid() {
+
         UIView.animate(withDuration: 0.0, animations: {
             if self.gridLayout.itemForLine - 1 > 0 {
                 self.gridLayout.itemForLine -= 1
@@ -287,18 +288,19 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     }
 
     @objc func openMenuButtonMore(_ sender: Any) {
+
         toggleMenu()
     }
 
     // MARK: Select Path
 
     func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {
-        if serverUrl != nil {
-            let path = CCUtility.returnPathfromServerUrl(serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account) ?? ""
+
+        guard let serverUrl = serverUrl else { return }
+        let path = CCUtility.returnPathfromServerUrl(serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account) ?? ""
             NCManageDatabase.shared.setAccountMediaPath(path, account: appDelegate.account)
-            reloadDataSourceWithCompletion { _ in
-                self.searchNewMedia()
-            }
+        reloadDataSourceWithCompletion { _ in
+            self.searchNewMedia()
         }
     }
 
@@ -323,7 +325,6 @@ extension NCMedia: UICollectionViewDelegate {
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
         let metadata = metadatas[indexPath.row]
-
         if isEditMode {
             if let index = selectOcId.firstIndex(of: metadata.ocId) {
                 selectOcId.remove(at: index)
@@ -333,9 +334,7 @@ extension NCMedia: UICollectionViewDelegate {
             if indexPath.section <  collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
                 collectionView.reloadItems(at: [indexPath])
             }
-
         } else {
-
             // ACTIVE SERVERURL
             appDelegate.activeServerUrl = metadata.serverUrl
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridMediaCell
@@ -346,29 +345,21 @@ extension NCMedia: UICollectionViewDelegate {
     @available(iOS 13.0, *)
     func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
 
+        guard let cell = collectionView.cellForItem(at: indexPath) as? NCGridMediaCell else { return nil }
         let metadata = metadatas[indexPath.row]
         let identifier = indexPath as NSCopying
-        if let cell = collectionView.cellForItem(at: indexPath) as? NCGridMediaCell {
-
-            let image = cell.imageItem.image
-
-            return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
-
-                return NCViewerProviderContextMenu(metadata: metadata, image: image)
-
-            }, actionProvider: { _ in
+        let image = cell.imageItem.image
 
-                return NCFunctionCenter.shared.contextMenuConfiguration(ocId: metadata.ocId, viewController: self, enableDeleteLocal: false, enableViewInFolder: true, image: image)
-            })
-        } else {
-            return nil
-        }
+        return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
+            return NCViewerProviderContextMenu(metadata: metadata, image: image)
+        }, actionProvider: { _ in
+            return NCFunctionCenter.shared.contextMenuConfiguration(ocId: metadata.ocId, viewController: self, enableDeleteLocal: false, enableViewInFolder: true, image: image)
+        })
     }
 
     @available(iOS 13.0, *)
     func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
         animator.addCompletion {
-
             if let indexPath = configuration.identifier as? IndexPath {
                 self.collectionView(collectionView, didSelectItemAt: indexPath)
             }
@@ -397,15 +388,13 @@ extension NCMedia: UICollectionViewDataSource {
     }
 
     func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
-        if indexPath.row < self.metadatas.count {
-            let metadata = self.metadatas[indexPath.row]
-
-            if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
-                (cell as! NCGridMediaCell).imageItem.backgroundColor = nil
-                (cell as! NCGridMediaCell).imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
-            } else {
-                NCOperationQueue.shared.downloadThumbnail(metadata: metadata, placeholder: false, cell: cell, view: collectionView)
-            }
+        guard let cell = (cell as? NCGridMediaCell), indexPath.row < self.metadatas.count else { return }
+        let metadata = self.metadatas[indexPath.row]
+        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
+            cell.imageItem.backgroundColor = nil
+            cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
+        } else {
+            NCOperationQueue.shared.downloadThumbnail(metadata: metadata, placeholder: false, cell: cell, view: collectionView)
         }
     }
 
@@ -471,6 +460,7 @@ extension NCMedia {
     // MARK: - Datasource
 
     @objc func reloadDataSourceWithCompletion(_ completion: @escaping (_ metadatas: [tableMetadata]) -> Void) {
+
         guard !appDelegate.account.isEmpty else { return }
 
         if account != appDelegate.account {
@@ -516,6 +506,7 @@ extension NCMedia {
     }
 
     func updateMediaControlVisibility() {
+
         if self.metadatas.count == 0 {
             if !self.filterClassTypeImage && !self.filterClassTypeVideo {
                 self.mediaCommandView?.toggleEmptyView(isEmpty: true)
@@ -600,6 +591,7 @@ extension NCMedia {
     }
 
     @objc func searchNewMediaTimer() {
+
         self.searchNewMedia()
     }
 
@@ -671,6 +663,7 @@ extension NCMedia: UIScrollViewDelegate {
     }
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
+
         mediaCommandView?.collapseControlButtonView(true)
     }
 
@@ -687,6 +680,7 @@ extension NCMedia: UIScrollViewDelegate {
     }
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
+
         timerSearchNewMedia?.invalidate()
         timerSearchNewMedia = Timer.scheduledTimer(timeInterval: timeIntervalSearchNewMedia, target: self, selector: #selector(searchNewMediaTimer), userInfo: nil, repeats: false)
 
@@ -696,6 +690,7 @@ extension NCMedia: UIScrollViewDelegate {
     }
 
     func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
+        
         let y = view.safeAreaInsets.top
         scrollView.contentOffset.y = -(insetsTop + y)
     }