Browse Source

Bring back old file menu in Share ext.

It's easier for current users and more explicit.
But also keep quick renaming, by tapping on file row.

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
65fc6a7d32

+ 32 - 4
Share/NCShareCell.swift

@@ -3,7 +3,22 @@
 //  Share
 //
 //  Created by Henrik Storch on 29.12.21.
-//  Copyright © 2021 Marino Faggiana. All rights reserved.
+//  Copyright © 2021 Henrik Storch. All rights reserved.
+//
+//  Author Henrik Storch <henrik.storch@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
@@ -11,6 +26,7 @@ import NCCommunication
 
 protocol NCShareCellDelegate: AnyObject {
     func removeFile(named fileName: String)
+    func renameFile(named fileName: String)
 }
 
 class NCShareCell: UITableViewCell {
@@ -18,7 +34,7 @@ class NCShareCell: UITableViewCell {
     @IBOutlet weak var fileNameCell: UILabel!
     @IBOutlet weak var moreButton: UIButton!
     @IBOutlet weak var sizeCell: UILabel!
-    weak var delegate: NCShareCellDelegate?
+    weak var delegate: (NCShareCellDelegate & UIViewController)?
     var fileName = ""
 
     func setup(fileName: String) {
@@ -44,10 +60,22 @@ class NCShareCell: UITableViewCell {
         let fileSize = NCUtilityFileSystem.shared.getFileSize(filePath: (NSTemporaryDirectory() + fileName))
         sizeCell?.text = CCUtility.transformedSize(fileSize)
 
-        moreButton?.setImage(NCUtility.shared.loadImage(named: "deleteScan").image(color: NCBrandColor.shared.label, size: 15), for: .normal)
+        moreButton?.setImage(NCUtility.shared.loadImage(named: "more").image(color: NCBrandColor.shared.label, size: 15), for: .normal)
     }
 
     @IBAction func buttonTapped(_ sender: Any) {
-        delegate?.removeFile(named: fileName)
+        guard !fileName.isEmpty else { return }
+        let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
+
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { _ in
+            self.delegate?.renameFile(named: self.fileName)
+        })
+
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_file_", comment: ""), style: .default) { _ in
+            self.delegate?.removeFile(named: self.fileName)
+        })
+
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in })
+        delegate?.present(alertController, animated: true, completion: nil)
     }
 }

+ 1 - 13
Share/NCShareExtension+DataSource.swift

@@ -75,7 +75,6 @@ extension NCShareExtension: UICollectionViewDataSource {
         cell.imageFavorite.image = nil
         cell.imageShared.image = nil
         cell.imageMore.image = nil
-
         cell.imageItem.image = nil
         cell.imageItem.backgroundColor = nil
 
@@ -160,17 +159,7 @@ extension NCShareExtension: UITableViewDelegate {
 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let fileName = filesName[indexPath.row]
-
-        guard let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile else { return }
-
-        let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
-        vcRename.delegate = self
-        vcRename.fileName = fileName
-        let img = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) ?? UIImage(named: resultInternalType.iconName) ?? NCBrandColor.cacheImages.file
-        vcRename.imagePreview = img
-        let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
-
-        self.present(popup, animated: true)
+        renameFile(named: fileName)
     }
 }
 
@@ -181,7 +170,6 @@ extension NCShareExtension: UITableViewDataSource {
     }
 
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
         guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? NCShareCell else { return UITableViewCell() }
         let fileName = filesName[indexPath.row]
         cell.setup(fileName: fileName)

+ 13 - 0
Share/NCShareExtension+NCDelegate.swift

@@ -114,6 +114,19 @@ extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCel
         }
     }
 
+    func renameFile(named fileName: String) {
+        guard let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile else { return }
+
+        let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
+        vcRename.delegate = self
+        vcRename.fileName = fileName
+        let img = UIImage(contentsOfFile: (NSTemporaryDirectory() + fileName)) ?? UIImage(named: resultInternalType.iconName) ?? NCBrandColor.cacheImages.file
+        vcRename.imagePreview = img
+        let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
+
+        self.present(popup, animated: true)
+    }
+
     func rename(fileName: String, fileNameNew: String) {
         guard let fileIx = self.filesName.firstIndex(of: fileName),
               !self.filesName.contains(fileNameNew),

+ 5 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -143,6 +143,11 @@
 "_recent_"                  = "Recent";
 "_view_in_folder_"          = "View in folder";
 "_leave_share_"             = "Leave this share";
+
+/* Remove a file from a list, don't delete it entirely */
+"_remove_file_"             = "Remove file";
+
+/* Delete file and put it into the trash */
 "_delete_file_"             = "Delete file";
 "_delete_folder_"           = "Delete folder";
 "_delete_photo_"            = "Delete photo";