|
@@ -26,7 +26,6 @@ import Realm
|
|
|
import NextcloudKit
|
|
|
import EasyTipView
|
|
|
import JGProgressHUD
|
|
|
-import Queuer
|
|
|
|
|
|
class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, NCSectionFooterDelegate, UIAdaptivePresentationControllerDelegate, NCEmptyDataSetDelegate, UIContextMenuInteractionDelegate, NCAccountRequestDelegate {
|
|
|
|
|
@@ -37,7 +36,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
|
|
|
private var pushed: Bool = false
|
|
|
private var tipView: EasyTipView?
|
|
|
- private var isTransitioning: Bool = false
|
|
|
+ var isTransitioning: Bool = false
|
|
|
|
|
|
let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
|
|
|
let utilityFileSystem = NCUtilityFileSystem()
|
|
@@ -49,7 +48,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
var serverUrl: String = ""
|
|
|
var isEditMode = false
|
|
|
var selectOcId: [String] = []
|
|
|
- var selectIndexPath: [IndexPath] = []
|
|
|
+ var selectIndexPaths: [IndexPath] = []
|
|
|
var metadataFolder: tableMetadata?
|
|
|
var dataSource = NCDataSource()
|
|
|
var richWorkspaceText: String?
|
|
@@ -91,10 +90,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
|
|
|
// MARK: - View Life Cycle
|
|
|
|
|
|
- required init?(coder aDecoder: NSCoder) {
|
|
|
- super.init(coder: aDecoder)
|
|
|
- }
|
|
|
-
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
|
|
@@ -544,8 +539,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
let chunk: Int = userInfo["chunk"] as? Int ?? 0
|
|
|
let e2eEncrypted: Bool = userInfo["e2eEncrypted"] as? Bool ?? false
|
|
|
|
|
|
- if self.headerMenuTransferView && (chunk > 0 || e2eEncrypted) {
|
|
|
- DispatchQueue.main.async {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ if self.headerMenuTransferView && (chunk > 0 || e2eEncrypted) {
|
|
|
if NCNetworking.shared.transferInForegorund?.ocId == ocId {
|
|
|
NCNetworking.shared.transferInForegorund?.progress = progressNumber.floatValue
|
|
|
} else {
|
|
@@ -553,12 +548,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
self.collectionView.reloadData()
|
|
|
}
|
|
|
self.headerMenu?.progressTransfer.progress = progressNumber.floatValue
|
|
|
- }
|
|
|
- } else {
|
|
|
- guard let indexPath = self.dataSource.getIndexPathMetadata(ocId: ocId).indexPath else { return }
|
|
|
- let status = userInfo["status"] as? Int ?? NCGlobal.shared.metadataStatusNormal
|
|
|
- DispatchQueue.main.async {
|
|
|
- guard let cell = self.collectionView?.cellForItem(at: indexPath),
|
|
|
+ } else {
|
|
|
+ guard let indexPath = self.dataSource.getIndexPathMetadata(ocId: ocId).indexPath,
|
|
|
+ let cell = self.collectionView?.cellForItem(at: indexPath),
|
|
|
let cell = cell as? NCCellProtocol else { return }
|
|
|
if progressNumber.floatValue == 1 && !(cell is NCTransferCell) {
|
|
|
cell.fileProgressView?.isHidden = true
|
|
@@ -574,6 +566,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
cell.fileProgressView?.isHidden = false
|
|
|
cell.fileProgressView?.progress = progressNumber.floatValue
|
|
|
cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCImageCache.images.buttonStop)
|
|
|
+ let status = userInfo["status"] as? Int ?? NCGlobal.shared.metadataStatusNormal
|
|
|
if status == NCGlobal.shared.metadataStatusDownloading {
|
|
|
cell.fileInfoLabel?.text = self.utilityFileSystem.transformedSize(totalBytesExpected)
|
|
|
cell.fileSubinfoLabel?.text = self.infoLabelsSeparator + "↓ " + self.utilityFileSystem.transformedSize(totalBytes)
|
|
@@ -943,7 +936,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
|
|
|
searchResults: self.searchResults)
|
|
|
} update: { _, _, searchResult, metadatas in
|
|
|
guard let metadatas, !metadatas.isEmpty, self.isSearchingMode, let searchResult else { return }
|
|
|
- NCNetworking.shared.unifiedSearchQueue.addOperation(NCOperationUnifiedSearch(collectionViewCommon: self, metadatas: metadatas, searchResult: searchResult))
|
|
|
+ NCNetworking.shared.unifiedSearchQueue.addOperation(NCCollectionViewUnifiedSearch(collectionViewCommon: self, metadatas: metadatas, searchResult: searchResult))
|
|
|
} completion: { _, _ in
|
|
|
self.refreshControl.endRefreshing()
|
|
|
self.collectionView.reloadData()
|
|
@@ -1042,10 +1035,10 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
|
|
|
if isEditMode {
|
|
|
if let index = selectOcId.firstIndex(of: metadata.ocId) {
|
|
|
selectOcId.remove(at: index)
|
|
|
- selectIndexPath.removeAll(where: { $0 == indexPath })
|
|
|
+ selectIndexPaths.removeAll(where: { $0 == indexPath })
|
|
|
} else {
|
|
|
selectOcId.append(metadata.ocId)
|
|
|
- selectIndexPath.append(indexPath)
|
|
|
+ selectIndexPaths.append(indexPath)
|
|
|
}
|
|
|
collectionView.reloadItems(at: [indexPath])
|
|
|
|
|
@@ -1246,12 +1239,13 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
|
|
|
// LAYOUT LIST
|
|
|
if layoutForView?.layout == NCGlobal.shared.layoutList {
|
|
|
guard let listCell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell else { return NCListCell() }
|
|
|
- listCell.delegate = self
|
|
|
+ listCell.listCellDelegate = self
|
|
|
+ // listCell.delegate = self
|
|
|
cell = listCell
|
|
|
} else {
|
|
|
// LAYOUT GRID
|
|
|
guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell else { return NCGridCell() }
|
|
|
- gridCell.delegate = self
|
|
|
+ gridCell.gridCellDelegate = self
|
|
|
cell = gridCell
|
|
|
}
|
|
|
|
|
@@ -1362,7 +1356,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
|
|
|
// image Favorite
|
|
|
if metadata.favorite {
|
|
|
cell.fileFavoriteImage?.image = NCImageCache.images.favorite
|
|
|
- a11yValues.append(NSLocalizedString("_favorite_", comment: ""))
|
|
|
+ a11yValues.append(NSLocalizedString("_favorite_short_", comment: ""))
|
|
|
}
|
|
|
|
|
|
// Share image
|
|
@@ -1476,6 +1470,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
|
|
|
cell.hideButtonMore(true)
|
|
|
}
|
|
|
|
|
|
+ cell.setIconOutlines()
|
|
|
+
|
|
|
return cell
|
|
|
}
|
|
|
|
|
@@ -1658,282 +1654,6 @@ extension NCCollectionViewCommon: EasyTipViewDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-extension NCCollectionViewCommon: NCSelectableNavigationView, NCCollectionViewCommonSelectTabBarDelegate {
|
|
|
- func setNavigationRightItems(enableMenu: Bool = false) {
|
|
|
- var selectedMetadatas: [tableMetadata] = []
|
|
|
- var isAnyOffline = false
|
|
|
- var isAnyDirectory = false
|
|
|
- var isAllDirectory = true
|
|
|
- var isAnyLocked = false
|
|
|
- var canUnlock = true
|
|
|
- var canSetAsOffline = true
|
|
|
-
|
|
|
- for ocId in selectOcId {
|
|
|
- guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { continue }
|
|
|
- selectedMetadatas.append(metadata)
|
|
|
-
|
|
|
- if metadata.directory {
|
|
|
- isAnyDirectory = true
|
|
|
- } else {
|
|
|
- isAllDirectory = false
|
|
|
- }
|
|
|
-
|
|
|
- if !metadata.canSetAsAvailableOffline {
|
|
|
- canSetAsOffline = false
|
|
|
- }
|
|
|
-
|
|
|
- if metadata.lock {
|
|
|
- isAnyLocked = true
|
|
|
- if metadata.lockOwner != appDelegate.userId {
|
|
|
- canUnlock = false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- guard !isAnyOffline else { continue }
|
|
|
-
|
|
|
- if metadata.directory,
|
|
|
- let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, metadata.serverUrl + "/" + metadata.fileName)) {
|
|
|
- isAnyOffline = directory.offline
|
|
|
- } else if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
|
|
|
- isAnyOffline = localFile.offline
|
|
|
- } // else: file is not offline, continue
|
|
|
- }
|
|
|
-
|
|
|
- guard let tabBarSelect = tabBarSelect as? NCCollectionViewCommonSelectTabBar else { return }
|
|
|
-
|
|
|
- tabBarSelect.isAnyOffline = isAnyOffline
|
|
|
- tabBarSelect.canSetAsOffline = canSetAsOffline
|
|
|
- tabBarSelect.isAnyDirectory = isAnyDirectory
|
|
|
- tabBarSelect.isAllDirectory = isAllDirectory
|
|
|
- tabBarSelect.isAnyLocked = isAnyLocked
|
|
|
- tabBarSelect.canUnlock = canUnlock
|
|
|
- tabBarSelect.enableLock = !isAnyDirectory && canUnlock && !NCGlobal.shared.capabilityFilesLockVersion.isEmpty
|
|
|
- tabBarSelect.isSelectedEmpty = selectOcId.isEmpty
|
|
|
- tabBarSelect.selectedMetadatas = selectedMetadatas
|
|
|
-
|
|
|
- if isEditMode {
|
|
|
- tabBarSelect.show()
|
|
|
- let select = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .done) { self.toggleSelect() }
|
|
|
- navigationItem.rightBarButtonItems = [select]
|
|
|
- } else {
|
|
|
- tabBarSelect.hide()
|
|
|
- if navigationItem.rightBarButtonItems == nil || enableMenu {
|
|
|
- let menuButton = UIBarButtonItem(image: .init(systemName: "ellipsis.circle"), menu: UIMenu(children: createMenuActions()))
|
|
|
- if layoutKey == NCGlobal.shared.layoutViewFiles {
|
|
|
- let notification = UIBarButtonItem(image: .init(systemName: "bell"), style: .plain, action: tapNotification)
|
|
|
- navigationItem.rightBarButtonItems = [menuButton, notification]
|
|
|
- } else {
|
|
|
- navigationItem.rightBarButtonItems = [menuButton]
|
|
|
- }
|
|
|
- } else {
|
|
|
- navigationItem.rightBarButtonItems?.first?.menu = navigationItem.rightBarButtonItems?.first?.menu?.replacingChildren(createMenuActions())
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func onListSelected() {
|
|
|
- if layoutForView?.layout == NCGlobal.shared.layoutGrid {
|
|
|
- layoutForView?.layout = NCGlobal.shared.layoutList
|
|
|
- NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
|
|
|
- self.groupByField = "name"
|
|
|
- if self.dataSource.groupByField != self.groupByField {
|
|
|
- self.dataSource.changeGroupByField(self.groupByField)
|
|
|
- }
|
|
|
-
|
|
|
- self.collectionView.reloadData()
|
|
|
- self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
- self.collectionView.setCollectionViewLayout(self.listLayout, animated: true) {_ in self.isTransitioning = false }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func onGridSelected() {
|
|
|
- if layoutForView?.layout == NCGlobal.shared.layoutList {
|
|
|
- layoutForView?.layout = NCGlobal.shared.layoutGrid
|
|
|
- NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
|
|
|
- if isSearchingMode {
|
|
|
- self.groupByField = "name"
|
|
|
- } else {
|
|
|
- self.groupByField = "classFile"
|
|
|
- }
|
|
|
- if self.dataSource.groupByField != self.groupByField {
|
|
|
- self.dataSource.changeGroupByField(self.groupByField)
|
|
|
- }
|
|
|
-
|
|
|
- self.collectionView.reloadData()
|
|
|
- self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
- self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true) {_ in self.isTransitioning = false }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func selectAll() {
|
|
|
- collectionViewSelectAll()
|
|
|
- }
|
|
|
-
|
|
|
- func delete(selectedMetadatas: [tableMetadata]) {
|
|
|
- let alertController = UIAlertController(
|
|
|
- title: NSLocalizedString("_confirm_delete_selected_", comment: ""),
|
|
|
- message: nil,
|
|
|
- preferredStyle: .alert)
|
|
|
-
|
|
|
- let canDeleteServer = selectedMetadatas.allSatisfy { !$0.lock }
|
|
|
-
|
|
|
- if canDeleteServer {
|
|
|
- let copyMetadatas = selectedMetadatas
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { _ in
|
|
|
- Task {
|
|
|
- var error = NKError()
|
|
|
- var ocId: [String] = []
|
|
|
- for metadata in copyMetadatas where error == .success {
|
|
|
- error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: false)
|
|
|
- if error == .success {
|
|
|
- ocId.append(metadata.ocId)
|
|
|
- }
|
|
|
- }
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": self.selectIndexPath, "onlyLocalCache": false, "error": error])
|
|
|
- }
|
|
|
-
|
|
|
- self.toggleSelect()
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
|
|
|
- let copyMetadatas = selectedMetadatas
|
|
|
-
|
|
|
- Task {
|
|
|
- var error = NKError()
|
|
|
- var ocId: [String] = []
|
|
|
- for metadata in copyMetadatas where error == .success {
|
|
|
- error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: true)
|
|
|
- if error == .success {
|
|
|
- ocId.append(metadata.ocId)
|
|
|
- }
|
|
|
- }
|
|
|
- if error != .success {
|
|
|
- NCContentPresenter().showError(error: error)
|
|
|
- }
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": self.selectIndexPath, "onlyLocalCache": true, "error": error])
|
|
|
- self.toggleSelect()
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in })
|
|
|
- self.viewController.present(alertController, animated: true, completion: nil)
|
|
|
- }
|
|
|
-
|
|
|
- func move(selectedMetadatas: [tableMetadata]) {
|
|
|
- NCActionCenter.shared.openSelectView(items: selectedMetadatas, indexPath: self.selectIndexPath)
|
|
|
- self.toggleSelect()
|
|
|
- }
|
|
|
-
|
|
|
- func share(selectedMetadatas: [tableMetadata]) {
|
|
|
- NCActionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas)
|
|
|
- self.toggleSelect()
|
|
|
- }
|
|
|
-
|
|
|
- func saveAsAvailableOffline(selectedMetadatas: [tableMetadata], isAnyOffline: Bool) {
|
|
|
- if !isAnyOffline, selectedMetadatas.count > 3 {
|
|
|
- let alert = UIAlertController(
|
|
|
- title: NSLocalizedString("_set_available_offline_", comment: ""),
|
|
|
- message: NSLocalizedString("_select_offline_warning_", comment: ""),
|
|
|
- preferredStyle: .alert)
|
|
|
- alert.addAction(UIAlertAction(title: NSLocalizedString("_continue_", comment: ""), style: .default, handler: { _ in
|
|
|
- selectedMetadatas.forEach { NCActionCenter.shared.setMetadataAvalableOffline($0, isOffline: isAnyOffline) }
|
|
|
- self.toggleSelect()
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel))
|
|
|
- self.viewController.present(alert, animated: true)
|
|
|
- } else {
|
|
|
- selectedMetadatas.forEach { NCActionCenter.shared.setMetadataAvalableOffline($0, isOffline: isAnyOffline) }
|
|
|
- self.toggleSelect()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func lock(selectedMetadatas: [tableMetadata], isAnyLocked: Bool) {
|
|
|
- for metadata in selectedMetadatas where metadata.lock == isAnyLocked {
|
|
|
- NCNetworking.shared.lockUnlockFile(metadata, shoulLock: !isAnyLocked)
|
|
|
- }
|
|
|
-
|
|
|
- self.toggleSelect()
|
|
|
- }
|
|
|
-
|
|
|
- func createMenuActions() -> [UIMenuElement] {
|
|
|
- guard let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl) else { return [] }
|
|
|
-
|
|
|
- let select = UIAction(title: NSLocalizedString("_select_", comment: ""), image: .init(systemName: "checkmark.circle"), attributes: selectableDataSource.isEmpty ? .disabled : []) { _ in self.toggleSelect() }
|
|
|
-
|
|
|
- let list = UIAction(title: NSLocalizedString("_list_", comment: ""), image: .init(systemName: "list.bullet"), state: layoutForView.layout == NCGlobal.shared.layoutList ? .on : .off) { _ in
|
|
|
- self.onListSelected()
|
|
|
- self.setNavigationRightItems()
|
|
|
- }
|
|
|
-
|
|
|
- let grid = UIAction(title: NSLocalizedString("_icons_", comment: ""), image: .init(systemName: "square.grid.2x2"), state: layoutForView.layout == NCGlobal.shared.layoutGrid ? .on : .off) { _ in
|
|
|
- self.onGridSelected()
|
|
|
- self.setNavigationRightItems()
|
|
|
- }
|
|
|
-
|
|
|
- let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid])
|
|
|
-
|
|
|
- let ascending = layoutForView.ascending
|
|
|
- let ascendingChevronImage = UIImage(systemName: ascending ? "chevron.up" : "chevron.down")
|
|
|
- let isName = layoutForView.sort == "fileName"
|
|
|
- let isDate = layoutForView.sort == "date"
|
|
|
- let isSize = layoutForView.sort == "size"
|
|
|
-
|
|
|
- let byName = UIAction(title: NSLocalizedString("_name_", comment: ""), image: isName ? ascendingChevronImage : nil, state: isName ? .on : .off) { _ in
|
|
|
- if isName { // repeated press
|
|
|
- layoutForView.ascending = !layoutForView.ascending
|
|
|
- }
|
|
|
-
|
|
|
- layoutForView.sort = "fileName"
|
|
|
- self.saveLayout(layoutForView)
|
|
|
- }
|
|
|
-
|
|
|
- let byNewest = UIAction(title: NSLocalizedString("_date_", comment: ""), image: isDate ? ascendingChevronImage : nil, state: isDate ? .on : .off) { _ in
|
|
|
- if isDate { // repeated press
|
|
|
- layoutForView.ascending = !layoutForView.ascending
|
|
|
- }
|
|
|
-
|
|
|
- layoutForView.sort = "date"
|
|
|
- self.saveLayout(layoutForView)
|
|
|
- }
|
|
|
-
|
|
|
- let byLargest = UIAction(title: NSLocalizedString("_size_", comment: ""), image: isSize ? ascendingChevronImage : nil, state: isSize ? .on : .off) { _ in
|
|
|
- if isSize { // repeated press
|
|
|
- layoutForView.ascending = !layoutForView.ascending
|
|
|
- }
|
|
|
-
|
|
|
- layoutForView.sort = "size"
|
|
|
- self.saveLayout(layoutForView)
|
|
|
- }
|
|
|
-
|
|
|
- let sortSubmenu = UIMenu(title: NSLocalizedString("_order_by_", comment: ""), options: .displayInline, children: [byName, byNewest, byLargest])
|
|
|
-
|
|
|
- let foldersOnTop = UIAction(title: NSLocalizedString("_directory_on_top_no_", comment: ""), image: UIImage(systemName: "folder"), state: layoutForView.directoryOnTop ? .on : .off) { _ in
|
|
|
- layoutForView.directoryOnTop = !layoutForView.directoryOnTop
|
|
|
- self.saveLayout(layoutForView)
|
|
|
- }
|
|
|
-
|
|
|
- let showDescriptionKeychain = NCKeychain().showDescription
|
|
|
-
|
|
|
- let showDescription = UIAction(title: NSLocalizedString("_show_description_", comment: ""), image: UIImage(systemName: "list.dash.header.rectangle"), attributes: richWorkspaceText == nil ? .disabled : [], state: showDescriptionKeychain && richWorkspaceText != nil ? .on : .off) { _ in
|
|
|
- NCKeychain().showDescription = !showDescriptionKeychain
|
|
|
- self.collectionView.reloadData()
|
|
|
- self.setNavigationRightItems()
|
|
|
- }
|
|
|
-
|
|
|
- showDescription.subtitle = richWorkspaceText == nil ? NSLocalizedString("_no_description_available_", comment: "") : ""
|
|
|
-
|
|
|
- let additionalSubmenu = UIMenu(title: "", options: .displayInline, children: [foldersOnTop, showDescription])
|
|
|
-
|
|
|
- if layoutKey == NCGlobal.shared.layoutViewRecent {
|
|
|
- return [select]
|
|
|
- } else {
|
|
|
- return [select, viewStyleSubmenu, sortSubmenu, additionalSubmenu]
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
extension NCCollectionViewCommon {
|
|
|
|
|
|
func getAvatarFromIconUrl(metadata: tableMetadata) -> String? {
|
|
@@ -2047,100 +1767,6 @@ extension NCCollectionViewCommon {
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
-class NCOperationUnifiedSearch: ConcurrentOperation {
|
|
|
-
|
|
|
- var collectionViewCommon: NCCollectionViewCommon
|
|
|
- var metadatas: [tableMetadata]
|
|
|
- var searchResult: NKSearchResult
|
|
|
-
|
|
|
- init(collectionViewCommon: NCCollectionViewCommon, metadatas: [tableMetadata], searchResult: NKSearchResult) {
|
|
|
- self.collectionViewCommon = collectionViewCommon
|
|
|
- self.metadatas = metadatas
|
|
|
- self.searchResult = searchResult
|
|
|
- }
|
|
|
-
|
|
|
- func reloadDataThenPerform(_ closure: @escaping (() -> Void)) {
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
|
- CATransaction.begin()
|
|
|
- CATransaction.setCompletionBlock(closure)
|
|
|
- self.collectionViewCommon.collectionView.reloadData()
|
|
|
- CATransaction.commit()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override func start() {
|
|
|
-
|
|
|
- guard !isCancelled else { return self.finish() }
|
|
|
-
|
|
|
- self.collectionViewCommon.dataSource.addSection(metadatas: metadatas, searchResult: searchResult)
|
|
|
- self.collectionViewCommon.searchResults?.append(self.searchResult)
|
|
|
- reloadDataThenPerform {
|
|
|
- self.finish()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class NCCollectionViewDownloadThumbnail: ConcurrentOperation {
|
|
|
-
|
|
|
- var metadata: tableMetadata
|
|
|
- var cell: NCCellProtocol?
|
|
|
- var collectionView: UICollectionView?
|
|
|
- var fileNamePath: String
|
|
|
- var fileNamePreviewLocalPath: String
|
|
|
- var fileNameIconLocalPath: String
|
|
|
- let utilityFileSystem = NCUtilityFileSystem()
|
|
|
-
|
|
|
- init(metadata: tableMetadata, cell: NCCellProtocol?, collectionView: UICollectionView?) {
|
|
|
- self.metadata = tableMetadata.init(value: metadata)
|
|
|
- self.cell = cell
|
|
|
- self.collectionView = collectionView
|
|
|
- self.fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
|
|
|
- self.fileNamePreviewLocalPath = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)
|
|
|
- self.fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
|
|
|
- }
|
|
|
-
|
|
|
- override func start() {
|
|
|
- guard !isCancelled else { return self.finish() }
|
|
|
-
|
|
|
- var etagResource: String?
|
|
|
- let sizePreview = NCUtility().getSizePreview(width: metadata.width, height: metadata.height)
|
|
|
-
|
|
|
- if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
|
|
|
- etagResource = metadata.etagResource
|
|
|
- }
|
|
|
-
|
|
|
- NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePath,
|
|
|
- fileNamePreviewLocalPath: fileNamePreviewLocalPath,
|
|
|
- widthPreview: Int(sizePreview.width),
|
|
|
- heightPreview: Int(sizePreview.height),
|
|
|
- fileNameIconLocalPath: fileNameIconLocalPath,
|
|
|
- sizeIcon: NCGlobal.shared.sizeIcon,
|
|
|
- etag: etagResource,
|
|
|
- options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, imageIcon, _, etag, error in
|
|
|
-
|
|
|
- if error == .success, let image = imageIcon {
|
|
|
- NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag)
|
|
|
- DispatchQueue.main.async {
|
|
|
- if self.metadata.ocId == self.cell?.fileObjectId, let filePreviewImageView = self.cell?.filePreviewImageView {
|
|
|
- if self.metadata.hasPreviewBorder {
|
|
|
- self.cell?.filePreviewImageView?.layer.borderWidth = 0.2
|
|
|
- self.cell?.filePreviewImageView?.layer.borderColor = UIColor.systemGray3.cgColor
|
|
|
- }
|
|
|
- UIView.transition(with: filePreviewImageView,
|
|
|
- duration: 0.75,
|
|
|
- options: .transitionCrossDissolve,
|
|
|
- animations: { filePreviewImageView.image = image },
|
|
|
- completion: nil)
|
|
|
- } else {
|
|
|
- self.collectionView?.reloadData()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- self.finish()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
private class AccountSwitcherButton: UIButton {
|
|
|
var onMenuOpened: (() -> Void)?
|
|
|
|