Browse Source

Add files via upload

Marino Faggiana 7 years ago
parent
commit
9852aca1b9

+ 37 - 0
Share/CCCellShareExt.h

@@ -0,0 +1,37 @@
+//
+//  CCCellShareExt.h
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 27/01/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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/UIKit.h>
+
+@interface CCCellShareExt : UITableViewCell
+
+@property(nonatomic, weak) IBOutlet UIImageView *fileImageView;
+@property(nonatomic, weak) IBOutlet UILabel *labelInformazioni;
+
+//Last position of the scroll of the swipe
+@property (nonatomic, assign) CGFloat lastContentOffset;
+
+//Index path of the cell swipe gesture ocured
+@property (nonatomic, strong) NSIndexPath *indexPath;
+
+@end

+ 59 - 0
Share/CCCellShareExt.m

@@ -0,0 +1,59 @@
+//
+//  CCCellShareExt.m
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 29/07/15.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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 "CCCellShareExt.h"
+
+@implementation CCCellShareExt
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+    if (self) {
+        // Initialization code
+
+        
+    }
+    return self;
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+    [super setSelected:selected animated:animated];
+
+    // Configure the view for the selected state
+}
+
+///-----------------------------------
+/// @name scrollViewWillBeginDecelerating
+///-----------------------------------
+
+/**
+ * Method to initialize the position where we make the swipe in order to detect the direction
+ *
+ * @param UIScrollView -> scrollView
+ */
+- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
+    _lastContentOffset = scrollView.contentOffset.x;
+}
+
+@end

+ 50 - 0
Share/CCCellShareExt.xib

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
+        <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
+    </dependencies>
+    <objects>
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CustomCellFileAndDirectory"/>
+        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+        <tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="0.0" reuseIdentifier="ShareExtCell" rowHeight="80" id="2" customClass="CCCellShareExt">
+            <rect key="frame" x="0.0" y="0.0" width="597" height="80"/>
+            <autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
+            <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2" id="sQq-jC-UEV">
+                <rect key="frame" x="0.0" y="0.0" width="597" height="79.5"/>
+                <autoresizingMask key="autoresizingMask"/>
+                <subviews>
+                    <imageView userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5">
+                        <rect key="frame" x="8" y="3" width="75" height="75"/>
+                        <constraints>
+                            <constraint firstAttribute="height" constant="75" id="2Z3-9a-dWb"/>
+                            <constraint firstAttribute="width" constant="75" id="fbQ-SN-CAK"/>
+                        </constraints>
+                    </imageView>
+                    <label opaque="NO" userInteractionEnabled="NO" tag="102" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="15D-cA-LLO" userLabel="Informazioni">
+                        <rect key="frame" x="91" y="3" width="501" height="75"/>
+                        <constraints>
+                            <constraint firstAttribute="height" constant="75" id="vPY-Rf-Mrc"/>
+                        </constraints>
+                        <fontDescription key="fontDescription" type="system" pointSize="12"/>
+                        <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                        <nil key="highlightedColor"/>
+                    </label>
+                </subviews>
+                <constraints>
+                    <constraint firstItem="5" firstAttribute="top" secondItem="sQq-jC-UEV" secondAttribute="topMargin" constant="-5" id="CT9-rd-lYA"/>
+                    <constraint firstAttribute="centerY" secondItem="15D-cA-LLO" secondAttribute="centerY" constant="-0.75" id="V5R-W6-5cF"/>
+                    <constraint firstAttribute="trailingMargin" secondItem="15D-cA-LLO" secondAttribute="trailing" constant="-3" id="cXo-tP-zxr"/>
+                    <constraint firstItem="15D-cA-LLO" firstAttribute="leading" secondItem="sQq-jC-UEV" secondAttribute="leadingMargin" constant="83" id="gIu-0P-Kea"/>
+                    <constraint firstItem="5" firstAttribute="leading" secondItem="sQq-jC-UEV" secondAttribute="leadingMargin" id="lC5-mh-JFW"/>
+                </constraints>
+            </tableViewCellContentView>
+            <connections>
+                <outlet property="fileImageView" destination="5" id="6"/>
+                <outlet property="labelInformazioni" destination="15D-cA-LLO" id="So0-uY-bRj"/>
+            </connections>
+            <point key="canvasLocation" x="171.5" y="416"/>
+        </tableViewCell>
+    </objects>
+</document>

+ 28 - 0
Share/CCSharedDBSession.h

@@ -0,0 +1,28 @@
+//
+//  CCSharedDBSession.h
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 13/02/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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/>.
+//
+
+@interface CCSharedDBSession : NSObject
+
++ (CCSharedDBSession *)sharedDBSession;
+
+@end

+ 47 - 0
Share/CCSharedDBSession.m

@@ -0,0 +1,47 @@
+//
+//  CCSharedDBSession.m
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 13/02/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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 "CCSharedDBSession.h"
+
+@implementation CCSharedDBSession
+
++ (CCSharedDBSession *)sharedDBSession {
+    static CCSharedDBSession *sharedDBSession;
+    @synchronized(self)
+    {
+        if (!sharedDBSession) {
+            
+            sharedDBSession = [[CCSharedDBSession alloc] init];
+        }
+        return sharedDBSession;
+    }
+}
+
+- (id)init
+{
+    self = [super init];
+    
+    return self;
+}
+
+@end

+ 181 - 0
Share/CCloadItemData.swift

@@ -0,0 +1,181 @@
+//
+//  CCloadItemData.swift
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 19/02/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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 MobileCoreServices
+
+class CCloadItemData: NSObject {
+    
+    func loadFiles(_ directoryUser: String, extensionContext: NSExtensionContext, vc: ShareViewController)
+    {
+        var filesName: [String] = []
+        var conuter = 0
+        let hud = CCHud(view: vc.view)!
+                
+        if let inputItems : [NSExtensionItem] = extensionContext.inputItems as? [NSExtensionItem] {
+            
+            for item : NSExtensionItem in inputItems {
+                
+                if let attachments = item.attachments as? [NSItemProvider] {
+                    
+                    if attachments.isEmpty {
+                        
+                        extensionContext.completeRequest(returningItems: nil, completionHandler: nil)
+                        
+                        vc.performSelector(onMainThread: #selector(vc.close), with: nil, waitUntilDone: false);
+                        
+                        return
+                    }
+                    
+                    for (index, current) in (attachments.enumerated()) {
+                        
+                        if current.hasItemConformingToTypeIdentifier(kUTTypeItem as String) {
+                            
+                            hud.visibleIndeterminateHud()
+                            
+                            current.loadItem(forTypeIdentifier: kUTTypeItem as String, options: nil, completionHandler: {(item, error) -> Void in
+                                
+                                if error == nil {
+                                    
+                                    let dateFormatter = DateFormatter()
+                                    dateFormatter.dateFormat = "yyyy-MM-dd HH-mm-ss-"
+                                    conuter += 1
+                                    
+                                    if let image = item as? UIImage {
+                                        
+                                        print("item as UIImage")
+                                        
+                                        if let pngImageData = UIImagePNGRepresentation(image) {
+                                        
+                                            let fileName = "\(dateFormatter.string(from: Date()))\(conuter).png"
+                                            let filenamePath = directoryUser + "/" + fileName
+                                        
+                                            let result = (try? pngImageData.write(to: URL(fileURLWithPath: filenamePath), options: [.atomic])) != nil
+                                        
+                                            if result {
+                                         
+                                                filesName.append(fileName)
+                                            }
+                                            
+                                        } else {
+                                         
+                                            print("Error image nil")
+                                        }
+                                    }
+                                    
+                                    if let url = item as? URL {
+                                        
+                                        print("item as url: \(String(describing: item))")
+                                        
+                                        let pathExtention = URL(fileURLWithPath: url.lastPathComponent).pathExtension
+                                        let fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
+                                        let filenamePath = directoryUser + "/" + fileName
+                                        
+                                        do {
+                                            try FileManager.default.copyItem(atPath: url.path, toPath:filenamePath)
+                                            
+                                            do {
+                                                let attr : NSDictionary? = try FileManager.default.attributesOfItem(atPath: filenamePath) as NSDictionary?
+                                                
+                                                if let _attr = attr {
+                                                    if _attr.fileSize() > 0 {
+                                                        
+                                                        filesName.append(fileName)
+                                                    }
+                                                }
+                                                
+                                            } catch let error as NSError {
+                                                
+                                                print("Error: \(error.localizedDescription)")
+                                            }                                            
+                                        } catch let error as NSError {
+                                            
+                                            print("Cannot copy file: \(error.localizedDescription)")
+                                        }
+                                    }
+                                    
+                                    if let data = item as? Data {
+                                        
+                                        if data.count > 0 {
+                                        
+                                            print("item as NSdata")
+                                        
+                                            let description = current.description
+                                        
+                                            let fullNameArr = description.components(separatedBy: "\"")
+                                            let fileExtArr = fullNameArr[1].components(separatedBy: ".")
+                                            let pathExtention = (fileExtArr[fileExtArr.count-1]).uppercased()
+                                        
+                                            let fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
+                                            let filenamePath = directoryUser + "/" + fileName
+
+                                            FileManager.default.createFile(atPath: filenamePath, contents:data, attributes:nil)
+                                                                                
+                                            filesName.append(fileName)
+                                        }
+                                    }
+                                    
+                                    if let data = item as? NSString {
+                                        
+                                        if data.length > 0 {
+                                        
+                                            print("item as NSString")
+                                        
+                                            let fileName = "\(dateFormatter.string(from: Date()))\(conuter).txt"
+                                            let filenamePath = directoryUser + "/" + fileName
+                                        
+                                            FileManager.default.createFile(atPath: filenamePath, contents:data.data(using: String.Encoding.utf8.rawValue), attributes:nil)
+                                        
+                                            filesName.append(fileName)
+                                        }
+                                    }
+                                    
+                                    if index + 1 == attachments.count {
+                                        
+                                        vc.performSelector(onMainThread: #selector(vc.reloadData), with:filesName, waitUntilDone: false)
+                                        hud.performSelector(onMainThread: #selector(CCHud.hideHud), with: nil, waitUntilDone: false)
+                                    }
+                                    
+                                } else {
+                                    
+                                    print("ERROR: \(error)")
+                                    hud.performSelector(onMainThread: #selector(CCHud.hideHud), with: nil, waitUntilDone: false)
+                                }
+                            })
+                            
+                        }
+                        
+                    } // end for
+
+                } else {
+                    
+                    vc.performSelector(onMainThread: #selector(vc.close), with: nil, waitUntilDone: false);
+                }
+            }
+            
+        } else {
+            
+            vc.performSelector(onMainThread: #selector(vc.close), with: nil, waitUntilDone: false);
+        }
+    }
+}

+ 89 - 0
Share/MainInterface.storyboard

@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yQd-yC-53O">
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
+        <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
+    </dependencies>
+    <scenes>
+        <!--Navigation Controller-->
+        <scene sceneID="ueh-Ta-TQZ">
+            <objects>
+                <navigationController id="yQd-yC-53O" sceneMemberID="viewController">
+                    <nil key="simulatedStatusBarMetrics"/>
+                    <navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="Qr0-yX-mDZ">
+                        <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
+                        <autoresizingMask key="autoresizingMask"/>
+                    </navigationBar>
+                    <connections>
+                        <segue destination="j1y-V4-xli" kind="relationship" relationship="rootViewController" id="dCI-hj-EK1"/>
+                    </connections>
+                </navigationController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="SCm-q2-twq" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="-1057" y="-210"/>
+        </scene>
+        <!--Share View Controller-->
+        <scene sceneID="ceB-am-kn3">
+            <objects>
+                <viewController id="j1y-V4-xli" customClass="ShareViewController" sceneMemberID="viewController">
+                    <layoutGuides>
+                        <viewControllerLayoutGuide type="top" id="8bI-gs-bmD"/>
+                        <viewControllerLayoutGuide type="bottom" id="d5i-Ba-RvD"/>
+                    </layoutGuides>
+                    <view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP">
+                        <rect key="frame" x="0.0" y="44" width="600" height="556"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <toolbar contentMode="scaleToFill" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gad-k1-Oh8">
+                                <rect key="frame" x="-4" y="512" width="604" height="44"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="44" id="rZR-ep-syc"/>
+                                </constraints>
+                                <items>
+                                    <barButtonItem style="plain" systemItem="flexibleSpace" id="ski-H2-N9g"/>
+                                    <barButtonItem title="Item" id="Dpo-t5-Knx">
+                                        <connections>
+                                            <action selector="destinyFolderButtonTapped:" destination="j1y-V4-xli" id="vt9-MN-l6i"/>
+                                        </connections>
+                                    </barButtonItem>
+                                    <barButtonItem style="plain" systemItem="flexibleSpace" id="eZh-WQ-5L1"/>
+                                </items>
+                            </toolbar>
+                            <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="110" sectionHeaderHeight="40" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="6bg-ed-mfL">
+                                <rect key="frame" x="1" y="0.0" width="598" height="512"/>
+                                <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                                <connections>
+                                    <outlet property="dataSource" destination="j1y-V4-xli" id="cqC-oT-nbV"/>
+                                    <outlet property="delegate" destination="j1y-V4-xli" id="WE4-Xb-ohZ"/>
+                                </connections>
+                            </tableView>
+                        </subviews>
+                        <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                        <constraints>
+                            <constraint firstAttribute="trailingMargin" secondItem="gad-k1-Oh8" secondAttribute="trailing" constant="-20" id="Ogc-Ss-sTA"/>
+                            <constraint firstItem="d5i-Ba-RvD" firstAttribute="top" secondItem="gad-k1-Oh8" secondAttribute="bottom" id="ZbI-py-8av"/>
+                            <constraint firstItem="6bg-ed-mfL" firstAttribute="leading" secondItem="wbc-yd-nQP" secondAttribute="leadingMargin" constant="-19" id="aoW-xE-g2g"/>
+                            <constraint firstAttribute="trailingMargin" secondItem="6bg-ed-mfL" secondAttribute="trailing" constant="-19" id="fyA-0H-E9s"/>
+                            <constraint firstItem="d5i-Ba-RvD" firstAttribute="top" secondItem="gad-k1-Oh8" secondAttribute="bottom" id="n1F-h4-Uxd"/>
+                            <constraint firstItem="gad-k1-Oh8" firstAttribute="top" secondItem="6bg-ed-mfL" secondAttribute="bottom" id="qEs-cg-DMH"/>
+                            <constraint firstItem="gad-k1-Oh8" firstAttribute="leadingMargin" secondItem="wbc-yd-nQP" secondAttribute="leadingMargin" constant="-16" id="qnK-zI-jNY"/>
+                            <constraint firstItem="6bg-ed-mfL" firstAttribute="top" secondItem="8bI-gs-bmD" secondAttribute="bottom" id="sKS-dx-tS9"/>
+                            <constraint firstItem="gad-k1-Oh8" firstAttribute="top" secondItem="6bg-ed-mfL" secondAttribute="bottom" id="xUM-bt-esX"/>
+                        </constraints>
+                    </view>
+                    <navigationItem key="navigationItem" id="DwO-O2-rAX"/>
+                    <nil key="simulatedStatusBarMetrics"/>
+                    <connections>
+                        <outlet property="constraintTopTableView" destination="sKS-dx-tS9" id="Cps-IG-Eih"/>
+                        <outlet property="destinyFolderButton" destination="Dpo-t5-Knx" id="9p8-c0-Ocm"/>
+                        <outlet property="shareTable" destination="6bg-ed-mfL" id="tzz-SO-m9D"/>
+                        <outlet property="toolBar" destination="gad-k1-Oh8" id="gAK-GL-EcZ"/>
+                    </connections>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="-290" y="-210"/>
+        </scene>
+    </scenes>
+</document>

+ 6 - 0
Share/Share-Bridging-Header.h

@@ -0,0 +1,6 @@
+//
+//  Use this file to import your target's public headers that you would like to expose to Swift.
+//
+
+#import "CCHud.h"
+#import "ShareViewController.h"

+ 74 - 0
Share/ShareViewController.h

@@ -0,0 +1,74 @@
+//
+//  ShareViewController.h
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 26/01/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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 <MagicalRecord/MagicalRecord.h>
+
+#import "OCCommunication.h"
+#import "AFURLSessionManager.h"
+#import "MBProgressHUD.h"
+#import "CCNetworking.h"
+#import "OCNetworking.h"
+#import "CCBKPasscode.h"
+#import "CCGlobal.h"
+#import "CCGraphics.h"
+#import "CCCellShareExt.h"
+#import "CCCoreData.h"
+#import "CCMove.h"
+#import "CCError.h"
+#import "CCHud.h"
+
+#import "TableAccount+CoreDataClass.h"
+
+@interface ShareViewController : UIViewController <UITableViewDelegate, OCNetworkingDelegate, MBProgressHUDDelegate, BKPasscodeViewControllerDelegate, CCNetworkingDelegate, CCMoveDelegate>
+
+@property (nonatomic, strong) NSOperationQueue *networkingOperationQueue;
+
+@property (nonatomic, strong) NSString *activeAccount;
+@property (nonatomic, strong) NSString *activeUrl;
+@property (nonatomic, strong) NSString *activeUser;
+@property (nonatomic, strong) NSString *activePassword;
+@property (nonatomic, strong) NSString *activeAccessToken;
+@property (nonatomic, strong) NSString *directoryUser;
+@property (nonatomic, strong) NSString *serverUrl;
+
+@property BOOL localCryptated;
+
+@property (nonatomic, retain) NSMutableArray *filesName;
+
+@property (nonatomic, weak) IBOutlet UITableView *shareTable;
+@property (nonatomic, weak) IBOutlet UIBarButtonItem *destinyFolderButton;
+@property (nonatomic, weak) IBOutlet NSLayoutConstraint *constraintTopTableView;
+@property (nonatomic, weak) IBOutlet UIToolbar *toolBar;
+
+// 
+@property (nonatomic, strong) CCBKPasscode *viewControllerBKInit;
+@property (nonatomic) NSUInteger failedAttempts;
+@property (nonatomic, strong) NSDate *lockUntilDate;
+
+//
+@property (nonatomic, strong) CCHud *hud;
+
+- (void)closeShareViewController;
+- (void)reloadData:(NSArray *)files;
+
+@end

+ 547 - 0
Share/ShareViewController.m

@@ -0,0 +1,547 @@
+//
+//  ShareViewController.m
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 26/01/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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 "ShareViewController.h"
+#import "NCBridgeSwift.h"
+
+@import MobileCoreServices;
+
+@interface ShareViewController ()
+{
+    NSURL *dirGroup;
+    NSUInteger totalSize;
+    
+    NSExtensionItem *inputItem;
+    CCMetadata *saveMetadataPlist;
+    
+    UIColor *barTintColor;
+    UIColor *tintColor;
+    
+    NSMutableArray *_filesSendCryptated;
+    BOOL _isCryptoCloudMode;
+}
+@end
+
+@implementation ShareViewController
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== View =====
+#pragma --------------------------------------------------------------------------------------------
+
+-(void)viewDidLoad
+{
+    dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:[NCBrandOptions sharedInstance].capabilitiesGroups];
+    
+    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(id)[dirGroup URLByAppendingPathComponent:[appDatabase stringByAppendingPathComponent:@"cryptocloud"]]];
+    [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff];
+
+    TableAccount *recordAccount = [CCCoreData getActiveAccount];
+    if (recordAccount == nil) {
+        
+        // close now
+        [self performSelector:@selector(closeShareViewController) withObject:nil afterDelay:0.1];
+        
+        return;
+        
+    } else {
+        
+        _activeAccount = recordAccount.account;
+        _activePassword = recordAccount.password;
+        _activeUrl = recordAccount.url;
+        _activeUser = recordAccount.user;
+        _directoryUser = [CCUtility getDirectoryActiveUser:self.activeUser activeUrl:self.activeUrl];
+        
+        if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
+            
+            _isCryptoCloudMode = NO;
+            
+        } else {
+            
+            _isCryptoCloudMode = YES;
+        }
+
+        
+        if ([_activeAccount isEqualToString:[CCUtility getActiveAccountShareExt]]) {
+            
+            // load
+            
+            _serverUrl = [CCUtility getServerUrlShareExt];
+            
+            _destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), [CCUtility getTitleServerUrlShareExt]];
+            
+            if (_isCryptoCloudMode)
+                _localCryptated = [CCUtility getCryptatedShareExt];
+            
+        } else {
+            
+            // Default settings
+            
+            [CCUtility setActiveAccountShareExt:self.activeAccount];
+
+            _serverUrl  = [CCUtility getHomeServerUrlActiveUrl:self.activeUrl];
+            [CCUtility setServerUrlShareExt:_serverUrl];
+
+            _destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), NSLocalizedString(@"_home_", nil)];
+            [CCUtility setTitleServerUrlShareExt:NSLocalizedString(@"_home_", nil)];
+
+            _localCryptated = NO;
+            [CCUtility setCryptatedShareExt:NO];
+        }
+    }
+
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
+    
+    _filesName = [[NSMutableArray alloc] init];
+    _filesSendCryptated = [[NSMutableArray alloc] init];
+    _hud = [[CCHud alloc] initWithView:self.navigationController.view];
+    
+    _networkingOperationQueue = [NSOperationQueue new];
+    _networkingOperationQueue.name = k_queue;
+    _networkingOperationQueue.maxConcurrentOperationCount = 1;
+    
+    [[CCNetworking sharedNetworking] settingDelegate:self];
+        
+    [self.shareTable registerNib:[UINib nibWithNibName:@"CCCellShareExt" bundle:nil] forCellReuseIdentifier:@"ShareExtCell"];
+    
+    [self navigationBarToolBar];
+    
+    [self loadDataSwift];
+}
+
+// Apparirà
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+    
+    // BUGFIX 2.17 - Change user Nextcloud App
+    [[CCNetworking sharedNetworking] settingAccount];
+    
+    if ([[CCUtility getBlockCode] length] > 0 && [CCUtility getOnlyLockDir] == NO)
+        [self openBKPasscode];
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+- (void)closeShareViewController
+{
+    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
+}
+
+//
+// L'applicazione terminerà
+//
+- (void)applicationWillTerminate:(UIApplication *)application
+{    
+    NSLog(@"[LOG] bye bye, Crypto Cloud Share Extension!");
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark == Action ==
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)navigationBarToolBar
+{    
+    UIBarButtonItem *rightButtonUpload, *rightButtonEncrypt, *leftButtonCancel;
+
+    // Theming
+    tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesForAccount:self.activeAccount];
+    if ([NCBrandOptions sharedInstance].use_themingColor && capabilities.themingColor.length > 0)
+        [NCBrandColor sharedInstance].brand = [CCGraphics colorFromHexString:capabilities.themingColor];
+
+    self.navigationController.navigationBar.barTintColor = [NCBrandColor sharedInstance].brand;
+    self.navigationController.navigationBar.tintColor = [NCBrandColor sharedInstance].navigationBarText;
+    
+    self.toolBar.barTintColor = [NCBrandColor sharedInstance].tabBar;
+    self.toolBar.tintColor = [NCBrandColor sharedInstance].brand;
+    
+    // Upload
+    if (self.localCryptated && _isCryptoCloudMode) {
+        
+        rightButtonUpload = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_save_encrypted_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectPost)];
+        [rightButtonUpload setTintColor:[NCBrandColor sharedInstance].cryptocloud];
+        
+    } else {
+        
+        rightButtonUpload = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_save_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectPost)];
+    }
+    
+    // Encrypt ICON
+    if (_isCryptoCloudMode) {
+        UIImage *icon = [[UIImage imageNamed:@"shareExtEncrypt"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
+        rightButtonEncrypt = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(changeEncrypt)];
+        if (self.localCryptated) [rightButtonEncrypt setTintColor:[NCBrandColor sharedInstance].cryptocloud];
+    }
+    
+    // Cancel
+    leftButtonCancel = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelPost)];
+    
+    // Title
+    [self.navigationController.navigationBar setTitleTextAttributes: @{NSForegroundColorAttributeName:self.navigationController.navigationBar.tintColor}];
+    
+    self.navigationItem.title = [NCBrandOptions sharedInstance].brand;
+    self.navigationItem.leftBarButtonItem = leftButtonCancel;
+    self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:rightButtonUpload, rightButtonEncrypt, nil];
+    self.navigationItem.hidesBackButton = YES;
+}
+
+- (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
+{
+    if (serverUrlTo)
+        _serverUrl = serverUrlTo;
+    
+    if (title) {
+        self.destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), title];
+        [CCUtility setTitleServerUrlShareExt:title];
+    } else {
+        self.destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), NSLocalizedString(@"_home_", nil)];
+        [CCUtility setTitleServerUrlShareExt:NSLocalizedString(@"_home_", nil)];
+    }
+    
+    [CCUtility setActiveAccountShareExt:self.activeAccount];
+    [CCUtility setServerUrlShareExt:_serverUrl];
+}
+
+- (IBAction)destinyFolderButtonTapped:(UIBarButtonItem *)sender
+{
+    UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
+    
+    CCMove *viewController = (CCMove *)navigationController.topViewController;
+    
+    viewController.delegate = self;
+    viewController.move.title = NSLocalizedString(@"_select_", nil);
+    viewController.tintColor = tintColor;
+    viewController.barTintColor = barTintColor;
+    viewController.tintColorTitle = tintColor;
+    viewController.networkingOperationQueue = _networkingOperationQueue;
+
+    [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
+    [self presentViewController:navigationController animated:YES completion:nil];
+}
+
+- (void)selectPost
+{
+    if ([self.filesName count] > 0) {
+    
+        NSString *fileName = [self.filesName objectAtIndex:0];
+        
+        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:_activeAccount];
+            
+        metadataNet.action = actionUploadFile;
+        metadataNet.cryptated = _localCryptated;
+        metadataNet.fileName = fileName;
+        metadataNet.fileNamePrint = fileName;
+        metadataNet.serverUrl = _serverUrl;
+        metadataNet.session = k_upload_session_foreground;
+        metadataNet.taskStatus = k_taskStatusResume;
+        
+        [self addNetworkingQueue:metadataNet];
+        
+        [self.hud visibleHudTitle:NSLocalizedString(@"_uploading_", nil) mode:MBProgressHUDModeDeterminateHorizontalBar color:self.view.tintColor];
+       
+        [self.hud AddButtonCancelWithTarget:self selector:@"cancelTransfer"];
+    }
+    else
+        [self closeShareViewController];
+}
+
+- (void)cancelPost
+{
+    // rimuoviamo i file+ico
+    for (NSString *fileName in self.filesName) {
+        
+        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil];
+        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName] error:nil];
+    }
+    
+    [self closeShareViewController];
+}
+
+- (void)changeEncrypt
+{
+    if (self.localCryptated) self.localCryptated = NO;
+    else self.localCryptated = YES;
+    
+    [CCUtility setCryptatedShareExt:self.localCryptated];
+
+    [self navigationBarToolBar];
+}
+
+- (void)cancelTransfer
+{
+    [_networkingOperationQueue cancelAllOperations];
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ======================= NetWorking ==================================
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)triggerProgressTask:(NSNotification *)notification
+{
+    NSDictionary *dict = notification.userInfo;
+    float progress = [[dict valueForKey:@"progress"] floatValue];
+
+    [self.hud progress:progress];
+}
+
+- (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
+{
+    [self.hud hideHud];
+    
+    // remove file 
+    [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, _activeAccount]];
+    
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileID] error:nil];
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, fileID] error:nil];
+
+    // message error
+    if (errorCode != kCFURLErrorCancelled) {
+        
+        UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
+                                                   handler:^(UIAlertAction * action) {
+                                                       [alert dismissViewControllerAnimated:YES completion:nil];
+                                                       [self closeShareViewController];
+                                                   }];
+        [alert addAction:ok];
+        [self presentViewController:alert animated:YES completion:nil];
+    }
+    else
+        [self closeShareViewController];
+}
+
+- (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
+{
+    [self.hud hideHud];
+    
+    CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, _activeAccount] context:nil];
+        
+    [self.filesName removeObject:metadata.fileNamePrint];
+    [self.shareTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
+    
+    [self performSelector:@selector(selectPost) withObject:nil afterDelay:0.1];
+}
+
+- (void)addNetworkingQueue:(CCMetadataNet *)metadataNet
+{
+    id operation;
+   
+    operation = [[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl isCryptoCloudMode:_isCryptoCloudMode];
+    
+    [operation setQueuePriority:metadataNet.priority];
+    
+    [_networkingOperationQueue addOperation:operation];
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Lock Password =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)openBKPasscode
+{
+    CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
+    viewController.delegate = self;
+    viewController.type = BKPasscodeViewControllerCheckPasscodeType;
+    viewController.inputViewTitlePassword = YES;
+    
+    if ([CCUtility getSimplyBlockCode]) {
+        
+        viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
+        viewController.passcodeInputView.maximumLength = 6;
+        
+    } else {
+        
+        viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
+        viewController.passcodeInputView.maximumLength = 64;
+    }
+    
+    BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
+    touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
+    viewController.touchIDManager = touchIDManager;
+    viewController.title = [NCBrandOptions sharedInstance].brand;
+    viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
+    viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
+    
+    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
+    [self presentViewController:navController animated:YES completion:nil];
+}
+
+- (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
+{
+    return self.failedAttempts;
+}
+
+- (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
+{
+    return self.lockUntilDate;
+}
+
+- (void)passcodeViewCloseButtonPressed:(id)sender
+{
+    [self dismissViewControllerAnimated:YES completion:^{
+        [self performSelector:@selector(closeShareViewController) withObject:nil];
+    }];
+}
+
+- (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
+{
+    if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
+        self.lockUntilDate = nil;
+        self.failedAttempts = 0;
+        aResultHandler(YES);
+    } else aResultHandler(NO);
+}
+
+- (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
+{
+    [aViewController dismissViewControllerAnimated:YES completion:nil];
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Swipe Table DELETE -> menu =====
+#pragma--------------------------------------------------------------------------------------------
+
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    [self setEditing:NO animated:YES];
+    
+    NSString *fileName = [self.filesName objectAtIndex:indexPath.row];
+    
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil];
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName] error:nil];
+
+    [self.filesName removeObjectAtIndex:indexPath.row];
+    
+    if ([self.filesName count] == 0) [self closeShareViewController];
+    else [self.shareTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark == Table ==
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)loadDataSwift
+{
+    CCloadItemData *loadItem = [[CCloadItemData alloc] init];
+    
+    [loadItem loadFiles:self.directoryUser extensionContext:self.extensionContext vc:self];
+}
+
+- (void)reloadData:(NSArray *)files
+{
+    totalSize = 0;
+
+    for (NSString *file in files) {
+        
+        NSUInteger fileSize = (NSInteger)[[[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, file] error:nil] fileSize];
+        
+        totalSize += fileSize;
+        
+        // creiamo l'ICO
+        CFStringRef fileExtension = (__bridge CFStringRef)[file pathExtension];
+        CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
+        
+        if (fileSize > 0 && ((UTTypeConformsTo(fileUTI, kUTTypeImage)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie)))) {
+            
+            NSString *typeFile;
+            if (UTTypeConformsTo(fileUTI, kUTTypeImage)) typeFile = k_metadataTypeFile_image;
+            if (UTTypeConformsTo(fileUTI, kUTTypeMovie)) typeFile = k_metadataTypeFile_video;
+            
+            [CCGraphics createNewImageFrom:file directoryUser:self.directoryUser fileNameTo:file fileNamePrint:nil size:@"m" imageForUpload:NO typeFile:typeFile writePreview:YES optimizedFileName:NO];
+        }
+    }
+    
+    if (totalSize > 0) {
+        
+        self.filesName = [[NSMutableArray alloc] initWithArray:files];
+        [self.shareTable reloadData];
+        
+    } else {
+        
+        [self closeShareViewController];
+    }
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    return 80;
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return [self.filesName count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    NSString *fileName = [self.filesName objectAtIndex:indexPath.row];
+    UIImage *image = nil;
+    
+    CFStringRef fileExtension = (__bridge CFStringRef)[fileName pathExtension];
+    CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
+
+    if (UTTypeConformsTo(fileUTI, kUTTypeZipArchive) && [(__bridge NSString *)fileUTI containsString:@"org.openxmlformats"] == NO) image = [UIImage imageNamed:@"file_compress"];
+    else if (UTTypeConformsTo(fileUTI, kUTTypeAudio)) image = [UIImage imageNamed:@"file_audio"];
+    else if ((UTTypeConformsTo(fileUTI, kUTTypeImage)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie))) {
+        
+        image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName]];
+        
+    }
+    else if (UTTypeConformsTo(fileUTI, kUTTypeContent)) {
+        
+        image = [UIImage imageNamed:@"document"];
+        
+        NSString *typeFile = (__bridge NSString *)fileUTI;
+        
+        if ([typeFile isEqualToString:@"com.adobe.pdf"]) image = [UIImage imageNamed:@"file_pdf"];
+        if ([typeFile isEqualToString:@"org.openxmlformats.spreadsheetml.sheet"]) image = [UIImage imageNamed:@"file_xls"];
+        if ([typeFile isEqualToString:@"public.plain-text"]) image = [UIImage imageNamed:@"file_txt"];
+    }
+    else image = [UIImage imageNamed:@"file"];
+    
+    CCCellShareExt *cell = (CCCellShareExt *)[tableView dequeueReusableCellWithIdentifier:@"ShareExtCell" forIndexPath:indexPath];
+    
+    NSUInteger fileSize = (NSInteger)[[[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil] fileSize];
+    
+    cell.labelInformazioni.text = [NSString stringWithFormat:@"%@\r\r%@", fileName, [CCUtility transformedSize:fileSize]];
+    cell.labelInformazioni.textColor = [UIColor blackColor];
+
+    cell.fileImageView.image = image;
+    
+    return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    [tableView deselectRowAtIndexPath:indexPath animated:YES];
+}
+
+@end