Skip to content

Commit

Permalink
Delete (#3079)
Browse files Browse the repository at this point in the history

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

---------

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
  • Loading branch information
marinofaggiana authored Sep 27, 2024
1 parent af3970b commit 3d28601
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 200 deletions.
15 changes: 4 additions & 11 deletions iOSClient/Extensions/UIAlertController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,10 @@ extension UIAlertController {
preferredStyle: .alert)
if canDeleteServer {
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { (_: UIAlertAction) in
Task {
var error = NKError()
var ocId: [String] = []
for metadata in selectedMetadatas where error == .success {
error = await NCNetworking.shared.deleteMetadata(metadata)
if error == .success {
ocId.append(metadata.ocId)
}
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": false, "error": error])
for metadata in selectedMetadatas {
NCNetworking.shared.deleteMetadata(metadata)
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
completion(false)
})
}
Expand All @@ -142,7 +135,7 @@ extension UIAlertController {
ocId.append(metadata.ocId)
}
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": true, "error": error])
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
}
completion(false)
})
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class NCFiles: NCCollectionViewCommon {
let predicateDirectory = NSPredicate(format: "account == %@ AND serverUrl == %@", session.account, self.serverUrl)

if NCKeychain().getPersonalFilesOnly(account: session.account) {
predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND (ownerId == %@ || ownerId == '') AND mountType == '' AND NOT (status IN %@)", session.account, self.serverUrl, session.userId, global.metadataStatusFileUp)
predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND (ownerId == %@ || ownerId == '') AND mountType == '' AND NOT (status IN %@)", session.account, self.serverUrl, session.userId, global.metadataStatusHideInView)
}

self.metadataFolder = database.getMetadataFolder(session: session, serverUrl: self.serverUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,10 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate {
if canDeleteServer {
let copyMetadatas = metadatas
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)
if error == .success {
ocId.append(metadata.ocId)
}
}
NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": false, "error": error])
for metadata in copyMetadatas {
NCNetworking.shared.deleteMetadata(metadata)
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
self.setEditMode(false)
})
}
Expand All @@ -73,7 +66,7 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate {
ocId.append(metadata.ocId)
}
}
NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": true, "error": error])
NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
}
self.setEditMode(false)
})
Expand Down
6 changes: 3 additions & 3 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
}

var defaultPredicate: NSPredicate {
let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND NOT (status IN %@) AND NOT (livePhotoFile != '' AND classFile == %@)", session.account, self.serverUrl, NCGlobal.shared.metadataStatusFileUp, NKCommon.TypeClassFile.video.rawValue)
let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND NOT (status IN %@) AND NOT (livePhotoFile != '' AND classFile == %@)", session.account, self.serverUrl, NCGlobal.shared.metadataStatusHideInView, NKCommon.TypeClassFile.video.rawValue)
return predicate
}

Expand Down Expand Up @@ -194,6 +194,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
self.navigationController?.navigationItem.leftBarButtonItems?.first?.customView?.addInteraction(dropInteraction)

NotificationCenter.default.addObserver(self, selector: #selector(changeTheming(_:)), name: NSNotification.Name(rawValue: global.notificationCenterChangeTheming), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource(_:)), name: NSNotification.Name(rawValue: global.notificationCenterReloadDataSource), object: nil)

}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -236,7 +238,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
NotificationCenter.default.addObserver(self, selector: #selector(changeStatusFolderE2EE(_:)), name: NSNotification.Name(rawValue: global.notificationCenterChangeStatusFolderE2EE), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadAvatar(_:)), name: NSNotification.Name(rawValue: global.notificationCenterReloadAvatar), object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource(_:)), name: NSNotification.Name(rawValue: global.notificationCenterReloadDataSource), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSourceNetwork(_:)), name: NSNotification.Name(rawValue: global.notificationCenterReloadDataSourceNetwork), object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: global.notificationCenterDeleteFile), object: nil)
Expand Down Expand Up @@ -278,7 +279,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: global.notificationCenterChangeStatusFolderE2EE), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: global.notificationCenterReloadAvatar), object: nil)

NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: global.notificationCenterReloadDataSource), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: global.notificationCenterReloadDataSourceNetwork), object: nil)

NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: global.notificationCenterDeleteFile), object: nil)
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Media/NCMedia+CollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension NCMedia: UICollectionViewDataSource {
}
guard let metadata = dataSource.getMetadata(indexPath: indexPath) else { return cell }

let ext = NCGlobal.shared.getSizeExtension(column: self.numberOfColumns)
let ext = global.getSizeExtension(column: self.numberOfColumns)
let imageCache = imageCache.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext)

cell.backgroundColor = .secondarySystemBackground
Expand All @@ -125,7 +125,7 @@ extension NCMedia: UICollectionViewDataSource {
}

if cell.imageItem.image == nil {
if isPinchGestureActive || ext == NCGlobal.shared.previewExt512 || ext == NCGlobal.shared.previewExt1024 {
if isPinchGestureActive || ext == global.previewExt512 || ext == global.previewExt1024 {
cell.imageItem.image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext)
} else {
DispatchQueue.global(qos: .userInteractive).async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension NCMedia: UICollectionViewDataSourcePrefetching {

let cost = indexPaths.first?.row ?? 0
let metadatas = self.dataSource.getMetadatas(indexPaths: indexPaths)
let ext = NCGlobal.shared.getSizeExtension(column: self.numberOfColumns)
let ext = global.getSizeExtension(column: self.numberOfColumns)
let percentageCache = (Double(self.imageCache.cache.count) / Double(self.imageCache.countLimit - 1)) * 100

if cost > self.imageCache.countLimit, percentageCache > 75 {
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Media/NCMedia+CollectionViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension NCMedia: UICollectionViewDelegate {
}
tabBarSelect.selectCount = fileSelect.count
} else if let metadata = database.getMetadataFromOcId(metadata.ocId) {
let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024)
let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: global.previewExt1024)
let ocIds = dataSource.metadatas.map { $0.ocId }

NCViewer().view(viewController: self, metadata: metadata, ocIds: ocIds, image: image)
Expand All @@ -52,7 +52,7 @@ extension NCMedia: UICollectionViewDelegate {
let metadata = database.getMetadataFromOcId(ocId)
else { return nil }
let identifier = indexPath as NSCopying
let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024)
let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: global.previewExt1024)

return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
return NCViewerProviderContextMenu(metadata: metadata, image: image)
Expand Down
65 changes: 40 additions & 25 deletions iOSClient/Media/NCMedia+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ extension NCMedia {
}

func createMenu() {
let layoutForView = database.getLayoutForView(account: session.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")
var layout = layoutForView?.layout ?? NCGlobal.shared.mediaLayoutRatio
let layoutForView = database.getLayoutForView(account: session.account, key: global.layoutViewMedia, serverUrl: "")
var layout = layoutForView?.layout ?? global.mediaLayoutRatio
/// Overwrite default value
if layout == NCGlobal.shared.layoutList { layout = NCGlobal.shared.mediaLayoutRatio }
if layout == global.layoutList { layout = global.mediaLayoutRatio }
///
let layoutTitle = (layout == NCGlobal.shared.mediaLayoutRatio) ? NSLocalizedString("_media_square_", comment: "") : NSLocalizedString("_media_ratio_", comment: "")
let layoutImage = (layout == NCGlobal.shared.mediaLayoutRatio) ? utility.loadImage(named: "square.grid.3x3") : utility.loadImage(named: "rectangle.grid.3x2")
let layoutTitle = (layout == global.mediaLayoutRatio) ? NSLocalizedString("_media_square_", comment: "") : NSLocalizedString("_media_ratio_", comment: "")
let layoutImage = (layout == global.mediaLayoutRatio) ? utility.loadImage(named: "square.grid.3x3") : utility.loadImage(named: "rectangle.grid.3x2")

let viewFilterMenu = UIMenu(title: "", options: .displayInline, children: [
UIAction(title: NSLocalizedString("_media_viewimage_show_", comment: ""), image: utility.loadImage(named: "photo")) { _ in
Expand All @@ -129,12 +129,12 @@ extension NCMedia {

let viewLayoutMenu = UIMenu(title: "", options: .displayInline, children: [
UIAction(title: layoutTitle, image: layoutImage) { _ in
if layout == NCGlobal.shared.mediaLayoutRatio {
self.database.setLayoutForView(account: self.session.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutSquare)
self.layoutType = NCGlobal.shared.mediaLayoutSquare
if layout == self.global.mediaLayoutRatio {
self.database.setLayoutForView(account: self.session.account, key: self.global.layoutViewMedia, serverUrl: "", layout: self.global.mediaLayoutSquare)
self.layoutType = self.global.mediaLayoutSquare
} else {
self.database.setLayoutForView(account: self.session.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutRatio)
self.layoutType = NCGlobal.shared.mediaLayoutRatio
self.database.setLayoutForView(account: self.session.account, key: self.global.layoutViewMedia, serverUrl: "", layout: self.global.mediaLayoutRatio)
self.layoutType = self.global.mediaLayoutRatio
}
self.createMenu()
self.collectionViewReloadData()
Expand Down Expand Up @@ -187,29 +187,44 @@ extension NCMedia {

extension NCMedia: NCMediaSelectTabBarDelegate {
func delete() {
let fileSelect = self.fileSelect.map { $0 }
let ocIds = self.fileSelect.map { $0 }
var alertStyle = UIAlertController.Style.actionSheet
var indexPaths: [IndexPath] = []

if UIDevice.current.userInterfaceIdiom == .pad { alertStyle = .alert }
if !fileSelect.isEmpty {

if !ocIds.isEmpty {
let indices = dataSource.metadatas.enumerated().filter { ocIds.contains($0.element.ocId) }.map { $0.offset }
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: alertStyle)

alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_selected_photos_", comment: ""), style: .destructive) { (_: UIAlertAction) in
Task {
var error = NKError()
var ocIds: [String] = []
for ocId in fileSelect where error == .success {
if let metadata = self.database.getMetadataFromOcId(ocId) {
error = await NCNetworking.shared.deleteMetadata(metadata)
if error == .success {
ocIds.append(metadata.ocId)
}
}
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocIds, "onlyLocalCache": false, "error": error])
}
self.isEditMode = false
self.setSelectcancelButton()

for ocId in ocIds {
if let metadata = self.database.getMetadataFromOcId(ocId) {
NCNetworking.shared.deleteMetadata(metadata)
}
}

for index in indices {
let indexPath = IndexPath(row: index, section: 0)
if let cell = self.collectionView.cellForItem(at: indexPath) as? NCMediaCell,
self.dataSource.metadatas[index].ocId == cell.ocId {
indexPaths.append(indexPath)
}
}

self.dataSource.removeMetadata(ocIds)
if indexPaths.count == ocIds.count {
self.collectionView.deleteItems(at: indexPaths)
} else {
self.collectionViewReloadData()
}
})

alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in })

present(alertController, animated: true, completion: { })
}
}
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Media/NCMedia+DragDrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension NCMedia: UICollectionViewDragDelegate {

extension NCMedia: UICollectionViewDropDelegate {
func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool {
return session.canLoadObjects(ofClass: UIImage.self) || session.hasItemsConforming(toTypeIdentifiers: [UTType.movie.identifier, NCGlobal.shared.metadataOcIdDataRepresentation])
return session.canLoadObjects(ofClass: UIImage.self) || session.hasItemsConforming(toTypeIdentifiers: [UTType.movie.identifier, global.metadataOcIdDataRepresentation])
}

func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Media/NCMedia+MediaLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import RealmSwift
extension NCMedia: NCMediaLayoutDelegate {
func getColumnCount() -> Int {
if self.numberOfColumns == 0,
let layoutForView = database.getLayoutForView(account: session.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "") {
let layoutForView = database.getLayoutForView(account: session.account, key: global.layoutViewMedia, serverUrl: "") {
if layoutForView.columnPhoto > 0 {
self.numberOfColumns = layoutForView.columnPhoto
} else {
Expand Down Expand Up @@ -81,7 +81,7 @@ extension NCMedia: NCMediaLayoutDelegate {
}

func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath, columnCount: Int, typeLayout: String) -> CGSize {
if typeLayout == NCGlobal.shared.mediaLayoutSquare {
if typeLayout == global.mediaLayoutSquare {
return CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
} else {
guard let metadata = dataSource.getMetadata(indexPath: indexPath) else { return .zero }
Expand Down
Loading

0 comments on commit 3d28601

Please sign in to comment.