marinofaggiana 3 years ago
parent
commit
69ff16959d
2 changed files with 62 additions and 23 deletions
  1. 5 5
      Share/MainInterface.storyboard
  2. 57 18
      Share/NCShareExtension.swift

+ 5 - 5
Share/MainInterface.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="EAU-PF-EEd">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="EAU-PF-EEd">
     <device id="retina6_5" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -47,7 +47,7 @@
                                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                         <prototypes>
                                             <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="Cell" rowHeight="50" id="6Kt-n0-i8J">
-                                                <rect key="frame" x="0.0" y="28" width="394" height="50"/>
+                                                <rect key="frame" x="0.0" y="24.333333969116211" width="394" height="50"/>
                                                 <autoresizingMask key="autoresizingMask"/>
                                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="6Kt-n0-i8J" id="WGN-Zn-lR8">
                                                     <rect key="frame" x="0.0" y="0.0" width="394" height="50"/>
@@ -72,7 +72,7 @@
                                                                 <constraint firstAttribute="height" constant="30" id="QqR-Uw-RnV"/>
                                                                 <constraint firstAttribute="width" constant="30" id="bpm-t5-3HA"/>
                                                             </constraints>
-                                                            <state key="normal" image="pencil"/>
+                                                            <state key="normal" image="more"/>
                                                         </button>
                                                     </subviews>
                                                     <constraints>
@@ -224,7 +224,7 @@
         </scene>
     </scenes>
     <resources>
-        <image name="pencil" width="16" height="16"/>
+        <image name="more" width="425" height="425"/>
         <systemColor name="separatorColor">
             <color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.28999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
         </systemColor>

+ 57 - 18
Share/NCShareExtension.swift

@@ -132,8 +132,27 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
                 
                 setAccount(account: activeAccount.account)
                 getFilesExtensionContext { (filesName, error) in
+                    
+                    self.filesName = filesName
                     DispatchQueue.main.async {
-                        self.filesName = filesName
+                        
+                        var saveHtml: [String] = []
+                        var saveOther: [String] = []
+                        
+                        for fileName in self.filesName {
+                            if (fileName as NSString).pathExtension.lowercased() == "html" {
+                                saveHtml.append(fileName)
+                            } else {
+                                saveOther.append(fileName)
+                            }
+                        }
+                        
+                        if saveOther.count > 0 && saveHtml.count > 0 {
+                            for file in saveHtml {
+                                self.filesName = self.filesName.filter(){$0 != file}
+                            }
+                        }
+                        
                         self.setCommandView()
                     }
                 }
@@ -404,19 +423,40 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
     }
     
-    @objc func renameButtonPressed(sender: NCShareExtensionButtonWithIndexPath) {
+    @objc func moreButtonPressed(sender: NCShareExtensionButtonWithIndexPath) {
         
         if let fileName = sender.fileName {
-            if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
+            let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
             
-                vcRename.delegate = self
-                vcRename.fileName = fileName
-                vcRename.imagePreview = sender.image
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .default) { (action:UIAlertAction) in
+                if let index = self.filesName.firstIndex(of: fileName) {
+                    
+                    self.filesName.remove(at: index)
+                    if self.filesName.count == 0 {
+                        self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
+                    } else {
+                        self.setCommandView()
+                    }
+                }
+            })
+            
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { (action:UIAlertAction) in
+                
+                if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
+                
+                    vcRename.delegate = self
+                    vcRename.fileName = fileName
+                    vcRename.imagePreview = sender.image
 
-                let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
-                                        
-                self.present(popup, animated: true)
-            }
+                    let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
+                                            
+                    self.present(popup, animated: true)
+                }
+            })
+            
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (action:UIAlertAction) in })
+            
+            self.present(alertController, animated: true, completion:nil)
         }
     }
     
@@ -646,7 +686,7 @@ extension NCShareExtension: UITableViewDataSource {
         
         let imageCell = cell.viewWithTag(10) as? UIImageView
         let fileNameCell = cell.viewWithTag(20) as? UILabel
-        let renameButton = cell.viewWithTag(30) as? NCShareExtensionButtonWithIndexPath
+        let moreButton = cell.viewWithTag(30) as? NCShareExtensionButtonWithIndexPath
 
         imageCell?.layer.cornerRadius = 6
         imageCell?.layer.masksToBounds = true
@@ -666,11 +706,11 @@ extension NCShareExtension: UITableViewDataSource {
         
         fileNameCell?.text = fileName
         
-        renameButton?.setImage(NCUtility.shared.loadImage(named: "pencil").image(color: NCBrandColor.shared.label, size: 15), for: .normal)
-        renameButton?.indexPath = indexPath
-        renameButton?.fileName = fileName
-        renameButton?.image = imageCell?.image
-        renameButton?.addTarget(self, action:#selector(renameButtonPressed(sender:)), for: .touchUpInside)
+        moreButton?.setImage(NCUtility.shared.loadImage(named: "more").image(color: NCBrandColor.shared.label, size: 15), for: .normal)
+        moreButton?.indexPath = indexPath
+        moreButton?.fileName = fileName
+        moreButton?.image = imageCell?.image
+        moreButton?.addTarget(self, action:#selector(moreButtonPressed(sender:)), for: .touchUpInside)
 
         return cell
     }
@@ -768,14 +808,13 @@ extension NCShareExtension {
                                 if let url = item as? NSURL {
                                     if FileManager.default.fileExists(atPath: url.path ?? "") {
                                         fileNameOriginal = url.lastPathComponent!
-                                    } else if url.scheme?.lowercased().contains("http") == true ||  url.scheme?.lowercased().contains("https") == true {
+                                    } else if url.scheme?.lowercased().contains("http") == true {
                                         fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter).html"
                                     } else {
                                         fileNameOriginal = "\(dateFormatter.string(from: Date()))\(conuter)"
                                     }
                                 }
                                 
-                                
                                 if error == nil {
                                                                         
                                     if let image = item as? UIImage {