diff options
author | marinofaggiana <ios@nextcloud.com> | 2022-08-02 18:13:43 +0300 |
---|---|---|
committer | marinofaggiana <ios@nextcloud.com> | 2022-08-02 18:13:43 +0300 |
commit | 50c0265d7a26d79af217bf7336cb0d3aa9309aca (patch) | |
tree | 0dd60acbc366f946f92263f4e0c5fd8fe272b249 /iOSClient | |
parent | 9cf7562fba9e1aa8d5372197fbac6ff09525e20b (diff) |
new openFileViewInFolder
Signed-off-by: marinofaggiana <ios@nextcloud.com>
Diffstat (limited to 'iOSClient')
-rw-r--r-- | iOSClient/AppDelegate.swift | 3 | ||||
-rw-r--r-- | iOSClient/FileViewInFolder/NCFileViewInFolder.storyboard | 53 | ||||
-rw-r--r-- | iOSClient/FileViewInFolder/NCFileViewInFolder.swift | 160 | ||||
-rw-r--r-- | iOSClient/Files/NCFiles.swift | 31 | ||||
-rw-r--r-- | iOSClient/Main/Collection Common/NCCollectionViewCommon.swift | 14 | ||||
-rw-r--r-- | iOSClient/Main/NCFunctionCenter.swift | 75 | ||||
-rw-r--r-- | iOSClient/Menu/NCCollectionViewCommon+Menu.swift | 8 | ||||
-rw-r--r-- | iOSClient/Menu/NCMenuAction.swift | 8 | ||||
-rw-r--r-- | iOSClient/Menu/NCViewer+Menu.swift | 2 |
9 files changed, 56 insertions, 298 deletions
diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 67256ae35..c8c563f55 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -43,7 +43,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD var deletePasswordSession: Bool = false var activeAppConfigView: NCAppConfigView? var activeFiles: NCFiles? - var activeFileViewInFolder: NCFileViewInFolder? var activeLogin: NCLogin? var activeLoginWeb: NCLoginWeb? @objc var activeMedia: NCMedia? @@ -868,7 +867,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - NCFunctionCenter.shared.openFileViewInFolder(viewController: self.activeViewController, serverUrl: serverUrl, fileName: fileName) + NCFunctionCenter.shared.openFileViewInFolder(viewController: self.activeViewController, serverUrl: serverUrl, fileNameBlink: fileName) } } else { diff --git a/iOSClient/FileViewInFolder/NCFileViewInFolder.storyboard b/iOSClient/FileViewInFolder/NCFileViewInFolder.storyboard deleted file mode 100644 index 95d7bd36e..000000000 --- a/iOSClient/FileViewInFolder/NCFileViewInFolder.storyboard +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="EFX-fO-Oip"> - <device id="retina5_9" orientation="portrait" appearance="light"/> - <dependencies> - <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/> - <capability name="Safe area layout guides" minToolsVersion="9.0"/> - <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> - </dependencies> - <scenes> - <!--File View In Folder--> - <scene sceneID="X4W-6b-l7s"> - <objects> - <viewController storyboardIdentifier="NCFileViewInFolder.storyboard" extendedLayoutIncludesOpaqueBars="YES" id="EFX-fO-Oip" customClass="NCFileViewInFolder" 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"/> - <subviews> - <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="Zaz-Cl-qpZ"> - <rect key="frame" x="0.0" y="0.0" width="375" height="812"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> - <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="fF1-wd-0xN"> - <size key="itemSize" width="0.0" height="0.0"/> - <size key="headerReferenceSize" width="0.0" height="0.0"/> - <size key="footerReferenceSize" width="0.0" height="0.0"/> - <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/> - </collectionViewFlowLayout> - <cells/> - <connections> - <outlet property="dataSource" destination="EFX-fO-Oip" id="2On-qP-zuG"/> - <outlet property="delegate" destination="EFX-fO-Oip" id="s3n-CL-8X2"/> - </connections> - </collectionView> - </subviews> - <viewLayoutGuide key="safeArea" id="Meh-VD-wWh"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> - <constraints> - <constraint firstItem="Zaz-Cl-qpZ" firstAttribute="leading" secondItem="Meh-VD-wWh" secondAttribute="leading" id="1bp-sm-u0X"/> - <constraint firstItem="Meh-VD-wWh" firstAttribute="trailing" secondItem="Zaz-Cl-qpZ" secondAttribute="trailing" id="aNd-UL-hmu"/> - <constraint firstItem="Meh-VD-wWh" firstAttribute="bottom" secondItem="Zaz-Cl-qpZ" secondAttribute="bottom" constant="-34" id="aNr-tf-2AH"/> - <constraint firstItem="Zaz-Cl-qpZ" firstAttribute="top" secondItem="QEs-gO-Cmp" secondAttribute="top" id="tji-wt-R7s"/> - </constraints> - </view> - <connections> - <outlet property="collectionView" destination="Zaz-Cl-qpZ" id="8oA-Gx-z7T"/> - </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> - </scenes> -</document> diff --git a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift b/iOSClient/FileViewInFolder/NCFileViewInFolder.swift deleted file mode 100644 index fde4d488d..000000000 --- a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift +++ /dev/null @@ -1,160 +0,0 @@ -// -// NCFileViewInFolder.swift -// Nextcloud -// -// Created by Marino Faggiana on 01/10/2020. -// Copyright © 2020 Marino Faggiana. All rights reserved. -// -// Author Marino Faggiana <marino.faggiana@nextcloud.com> -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. -// - -import UIKit -import NCCommunication - -class NCFileViewInFolder: NCCollectionViewCommon { - - internal var fileName: String? - - // MARK: - View Life Cycle - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - - appDelegate.activeFileViewInFolder = self - titleCurrentFolder = NCBrandOptions.shared.brand - layoutKey = NCGlobal.shared.layoutViewViewInFolder - enableSearchBar = false - headerMenuButtonsCommand = false - headerMenuButtonsView = true - headerRichWorkspaceDisable = true - emptyImage = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width) - emptyTitle = "_files_no_files_" - emptyDescription = "_no_file_pull_down_" - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - - appDelegate.activeViewController = self - - if serverUrl == NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account) { - self.navigationItem.title = NCBrandOptions.shared.brand - } else { - self.navigationItem.title = (serverUrl as NSString).lastPathComponent - } - - presentationController?.delegate = self - - layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) - gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3) - - if layoutForView?.layout == NCGlobal.shared.layoutList { - collectionView?.collectionViewLayout = listLayout - } else { - collectionView?.collectionViewLayout = gridLayout - } - - self.navigationItem.leftBarButtonItem = nil - self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_close_", comment: ""), style: .plain, target: self, action: #selector(tapClose(sender:))) - } - - // MARK: - TAP EVENT - - @objc func tapClose(sender: Any) { - dismiss(animated: true) - } - - // MARK: - DataSource + NC Endpoint - - override func reloadDataSource(forced: Bool = true) { - super.reloadDataSource() - - DispatchQueue.global().async { - let metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl)) - if self.metadataFolder == nil { - self.metadataFolder = NCManageDatabase.shared.getMetadataFolder(account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, serverUrl: self.serverUrl) - } - - self.dataSource = NCDataSource(metadatas: metadatas, - account: self.appDelegate.account, - sort: self.layoutForView?.sort, - ascending: self.layoutForView?.ascending, - directoryOnTop: self.layoutForView?.directoryOnTop, - favoriteOnTop: true, - filterLivePhoto: true, - groupByField: self.groupByField, - providers: self.providers, - searchResults: self.searchResults) - - DispatchQueue.main.async { - self.refreshControl.endRefreshing() - self.collectionView.reloadData() - // Blink file - if self.fileName != nil { - if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, self.fileName!)) { - let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId) - if let indexPath = indexPath { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - UIView.animate(withDuration: 0.3) { - self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false) - } completion: { _ in - if let cell = self.collectionView.cellForItem(at: indexPath) { - cell.backgroundColor = .darkGray - UIView.animate(withDuration: 2) { - cell.backgroundColor = .clear - self.fileName = nil - } - } - } - } - } - } - } - } - } - } - - override func reloadDataSourceNetwork(forced: Bool = false) { - super.reloadDataSourceNetwork(forced: forced) - - if isSearching { - networkSearch() - return - } - - isReloadDataSourceNetworkInProgress = true - collectionView?.reloadData() - - networkReadFolder(forced: forced) { tableDirectory, metadatas, _, _, errorCode, _ in - if errorCode == 0 { - for metadata in metadatas ?? [] { - if !metadata.directory { - if NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) { - NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile) - } - } - } - } - - DispatchQueue.main.async { - self.refreshControl.endRefreshing() - self.isReloadDataSourceNetworkInProgress = false - self.richWorkspaceText = tableDirectory?.richWorkspace - self.reloadDataSource() - } - } - } -} diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index 7dc2be74c..62fcbabce 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -27,6 +27,7 @@ import NCCommunication class NCFiles: NCCollectionViewCommon { internal var isRoot: Bool = true + internal var fileNameBlink: String? // MARK: - View Life Cycle @@ -76,6 +77,7 @@ class NCFiles: NCCollectionViewCommon { // // forced: do no make the etag of directory test (default) // + override func reloadDataSource(forced: Bool = true) { super.reloadDataSource() @@ -92,7 +94,7 @@ class NCFiles: NCCollectionViewCommon { self.richWorkspaceText = directory?.richWorkspace // FORCED false: test the directory.etag - if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil { + if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil, self.fileNameBlink == nil { return } @@ -109,7 +111,11 @@ class NCFiles: NCCollectionViewCommon { providers: self.providers, searchResults: self.searchResults) - DispatchQueue.main.async { self.collectionView.reloadData() } + DispatchQueue.main.async { + self.collectionView.reloadData() + self.blinkCell(fileName: self.fileNameBlink) + self.fileNameBlink = nil + } } } @@ -140,4 +146,25 @@ class NCFiles: NCCollectionViewCommon { } } } + + func blinkCell(fileName: String?) { + + if let fileName = fileName, let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, fileName)) { + let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId) + if let indexPath = indexPath { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + UIView.animate(withDuration: 0.3) { + self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false) + } completion: { _ in + if let cell = self.collectionView.cellForItem(at: indexPath) { + cell.backgroundColor = .darkGray + UIView.animate(withDuration: 2) { + cell.backgroundColor = .clear + } + } + } + } + } + } + } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 91a75882b..6eb38f773 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -1214,18 +1214,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS } } - // VIEW IN FOLDER - if layoutKey == NCGlobal.shared.layoutViewViewInFolder && !pushed { - - if let viewController: NCFileViewInFolder = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as? NCFileViewInFolder { - - viewController.serverUrl = serverUrlPush - viewController.titleCurrentFolder = metadata.fileNameView - - pushViewController(viewController: viewController) - } - } - // SHARES ( for push use Files ... he he he ) if layoutKey == NCGlobal.shared.layoutViewShares && !pushed { @@ -1282,7 +1270,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate { pushMetadata(metadata) - } else { //if !(self is NCFileViewInFolder) { + } else { let imageIcon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) diff --git a/iOSClient/Main/NCFunctionCenter.swift b/iOSClient/Main/NCFunctionCenter.swift index 49524b768..fb739cd89 100644 --- a/iOSClient/Main/NCFunctionCenter.swift +++ b/iOSClient/Main/NCFunctionCenter.swift @@ -454,52 +454,7 @@ import Photos // MARK: - - /* - func openFileViewInFolder(serverUrl: String, fileName: String) { - - let viewController = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as! NCFileViewInFolder - let navigationController = UINavigationController(rootViewController: viewController) - - let topViewController = viewController - var listViewController = [NCFileViewInFolder]() - var serverUrl = serverUrl - let homeUrl = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account) - - while true { - - var viewController: NCFileViewInFolder? - if serverUrl != homeUrl { - viewController = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as? NCFileViewInFolder - if viewController == nil { - return - } - viewController!.titleCurrentFolder = (serverUrl as NSString).lastPathComponent - } else { - viewController = topViewController - } - guard let vc = viewController else { return } - - vc.serverUrl = serverUrl - vc.fileName = fileName - - vc.navigationItem.backButtonTitle = vc.titleCurrentFolder - listViewController.insert(vc, at: 0) - - if serverUrl != homeUrl { - serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: appDelegate.account, serverUrl: serverUrl) - } else { - break - } - } - - navigationController.setViewControllers(listViewController, animated: false) - navigationController.modalPresentationStyle = .formSheet - - appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil) - } - */ - - func openFileViewInFolder(viewController: UIViewController?, serverUrl: String, fileName: String) { + func openFileViewInFolder(viewController: UIViewController?, serverUrl: String, fileNameBlink: String?) { var topNavigationController: UINavigationController? var pushServerUrl = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account) @@ -512,19 +467,33 @@ import Photos topNavigationController = navigationController } } - guard let topNavigationController = topNavigationController else { return} + if pushServerUrl == serverUrl { + let viewController = topNavigationController?.topViewController as? NCFiles + viewController?.blinkCell(fileName: fileNameBlink) + return + } + guard let topNavigationController = topNavigationController else { return } - while pushServerUrl != serverUrl { + let diffDirectory = serverUrl.replacingOccurrences(of: pushServerUrl, with: "") + var subDirs = diffDirectory.split(separator: "/") + + while pushServerUrl != serverUrl, subDirs.count > 0 { + + guard let dir = subDirs.first, let viewController = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles else { return } + pushServerUrl = pushServerUrl + "/" + dir - guard let viewController = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles else { return } - pushServerUrl = pushServerUrl + "/" + fileName - viewController.isRoot = false viewController.serverUrl = pushServerUrl - viewController.titleCurrentFolder = fileName + viewController.isRoot = false + viewController.titleCurrentFolder = String(dir) + if pushServerUrl == serverUrl { + viewController.fileNameBlink = fileNameBlink + } appDelegate.listFilesVC[serverUrl] = viewController viewController.navigationItem.backButtonTitle = viewController.titleCurrentFolder topNavigationController.pushViewController(viewController, animated: false) + + subDirs.remove(at: 0) } } @@ -665,7 +634,7 @@ import Photos } let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), image: UIImage(systemName: "arrow.forward.square")) { _ in - self.openFileViewInFolder(viewController: viewController, serverUrl: metadata.serverUrl, fileName: metadata.fileName) + self.openFileViewInFolder(viewController: viewController, serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName) } let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { _ in diff --git a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift index 6410c3888..9339cd17c 100644 --- a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift +++ b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift @@ -281,13 +281,7 @@ extension NCCollectionViewCommon { title: NSLocalizedString("_modify_", comment: ""), icon: NCUtility.shared.loadImage(named: "pencil.tip.crop.circle"), action: { menuAction in - if self is NCFileViewInFolder { - self.dismiss(animated: true) { - NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook) - } - } else { - NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook) - } + NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook) } ) ) diff --git a/iOSClient/Menu/NCMenuAction.swift b/iOSClient/Menu/NCMenuAction.swift index 6aff1a224..66543d53e 100644 --- a/iOSClient/Menu/NCMenuAction.swift +++ b/iOSClient/Menu/NCMenuAction.swift @@ -154,13 +154,7 @@ extension NCMenuAction { title: NSLocalizedString("_open_in_", comment: ""), icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"), action: { _ in - if viewController is NCFileViewInFolder { - viewController.dismiss(animated: true) { - NCFunctionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas) - } - } else { - NCFunctionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas) - } + NCFunctionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas) completion?() } ) diff --git a/iOSClient/Menu/NCViewer+Menu.swift b/iOSClient/Menu/NCViewer+Menu.swift index d345185d2..696acb086 100644 --- a/iOSClient/Menu/NCViewer+Menu.swift +++ b/iOSClient/Menu/NCViewer+Menu.swift @@ -192,7 +192,7 @@ extension NCViewer { title: NSLocalizedString("_view_in_folder_", comment: ""), icon: NCUtility.shared.loadImage(named: "arrow.forward.square"), action: { menuAction in - NCFunctionCenter.shared.openFileViewInFolder(viewController: viewController, serverUrl: metadata.serverUrl, fileName: metadata.fileName) + NCFunctionCenter.shared.openFileViewInFolder(viewController: viewController, serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName) } ) ) |