ShareViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //
  2. // ShareViewController.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/01/16.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "ShareViewController.h"
  24. #ifdef CUSTOM_BUILD
  25. #import "CustomSwiftShare.h"
  26. #else
  27. #import "Share-Swift.h"
  28. #endif
  29. @import MobileCoreServices;
  30. @interface ShareViewController ()
  31. {
  32. NSURL *dirGroup;
  33. NSUInteger totalSize;
  34. NSExtensionItem *inputItem;
  35. CCMetadata *saveMetadataPlist;
  36. UIColor *barTintColor;
  37. UIColor *tintColor;
  38. NSMutableArray *_filesSendCryptated;
  39. BOOL _isCryptoCloudMode;
  40. }
  41. @end
  42. @implementation ShareViewController
  43. #pragma --------------------------------------------------------------------------------------------
  44. #pragma mark ===== View =====
  45. #pragma --------------------------------------------------------------------------------------------
  46. -(void)viewDidLoad
  47. {
  48. dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  49. [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(id)[dirGroup URLByAppendingPathComponent:[appDatabase stringByAppendingPathComponent:@"cryptocloud"]]];
  50. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff];
  51. TableAccount *recordAccount = [CCCoreData getActiveAccount];
  52. if (recordAccount == nil) {
  53. // close now
  54. [self performSelector:@selector(closeShareViewController) withObject:nil afterDelay:0.1];
  55. return;
  56. } else {
  57. _activeAccount = recordAccount.account;
  58. _activePassword = recordAccount.password;
  59. _activeUrl = recordAccount.url;
  60. _activeUser = recordAccount.user;
  61. _directoryUser = [CCUtility getDirectoryActiveUser:self.activeUser activeUrl:self.activeUrl];
  62. if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
  63. _isCryptoCloudMode = NO;
  64. } else {
  65. _isCryptoCloudMode = YES;
  66. }
  67. if ([_activeAccount isEqualToString:[CCUtility getActiveAccountShareExt]]) {
  68. // load
  69. _serverUrl = [CCUtility getServerUrlShareExt];
  70. _destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), [CCUtility getTitleServerUrlShareExt]];
  71. if (_isCryptoCloudMode)
  72. _localCryptated = [CCUtility getCryptatedShareExt];
  73. } else {
  74. // Default settings
  75. [CCUtility setActiveAccountShareExt:self.activeAccount];
  76. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:self.activeUrl];
  77. [CCUtility setServerUrlShareExt:_serverUrl];
  78. _destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), NSLocalizedString(@"_home_", nil)];
  79. [CCUtility setTitleServerUrlShareExt:NSLocalizedString(@"_home_", nil)];
  80. _localCryptated = NO;
  81. [CCUtility setCryptatedShareExt:NO];
  82. }
  83. }
  84. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  85. _filesName = [[NSMutableArray alloc] init];
  86. _filesSendCryptated = [[NSMutableArray alloc] init];
  87. _hud = [[CCHud alloc] initWithView:self.navigationController.view];
  88. _networkingOperationQueue = [NSOperationQueue new];
  89. _networkingOperationQueue.name = k_queue;
  90. _networkingOperationQueue.maxConcurrentOperationCount = 1;
  91. [[CCNetworking sharedNetworking] settingDelegate:self];
  92. [self.shareTable registerNib:[UINib nibWithNibName:@"CCCellShareExt" bundle:nil] forCellReuseIdentifier:@"ShareExtCell"];
  93. [self navigationBarToolBar];
  94. [self loadDataSwift];
  95. }
  96. // Apparirà
  97. - (void)viewWillAppear:(BOOL)animated
  98. {
  99. [super viewWillAppear:animated];
  100. // BUGFIX 2.17 - Change user Nextcloud App
  101. [[CCNetworking sharedNetworking] settingAccount];
  102. if ([[CCUtility getBlockCode] length] > 0 && [CCUtility getOnlyLockDir] == NO)
  103. [self openBKPasscode];
  104. }
  105. - (void)didReceiveMemoryWarning
  106. {
  107. [super didReceiveMemoryWarning];
  108. // Dispose of any resources that can be recreated.
  109. }
  110. - (void)closeShareViewController
  111. {
  112. [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
  113. }
  114. //
  115. // L'applicazione terminerà
  116. //
  117. - (void)applicationWillTerminate:(UIApplication *)application
  118. {
  119. NSLog(@"[LOG] bye bye, Crypto Cloud Share Extension!");
  120. }
  121. #pragma --------------------------------------------------------------------------------------------
  122. #pragma mark == Action ==
  123. #pragma --------------------------------------------------------------------------------------------
  124. - (void)navigationBarToolBar
  125. {
  126. UIBarButtonItem *rightButtonUpload, *rightButtonEncrypt, *leftButtonCancel;
  127. // Theming
  128. TableCapabilities *tableCapabilities = [CCCoreData getCapabilitesForAccount:self.activeAccount];
  129. if (k_option_use_themingColor && tableCapabilities.themingColor.length > 0)
  130. [NCBrandColor sharedInstance].brand = [CCGraphics colorFromHexString:tableCapabilities.themingColor];
  131. self.navigationController.navigationBar.barTintColor = [NCBrandColor sharedInstance].brand;
  132. self.navigationController.navigationBar.tintColor = [NCBrandColor sharedInstance].navigationBarText;
  133. self.toolBar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  134. self.toolBar.tintColor = [NCBrandColor sharedInstance].brand;
  135. // Upload
  136. if (self.localCryptated && _isCryptoCloudMode) {
  137. rightButtonUpload = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_save_encrypted_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectPost)];
  138. [rightButtonUpload setTintColor:[NCBrandColor sharedInstance].cryptocloud];
  139. } else {
  140. rightButtonUpload = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_save_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectPost)];
  141. }
  142. // Encrypt ICON
  143. if (_isCryptoCloudMode) {
  144. UIImage *icon = [[UIImage imageNamed:image_shareExtEncrypt] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  145. rightButtonEncrypt = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(changeEncrypt)];
  146. if (self.localCryptated) [rightButtonEncrypt setTintColor:[NCBrandColor sharedInstance].cryptocloud];
  147. }
  148. // Cancel
  149. leftButtonCancel = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelPost)];
  150. // Title
  151. [self.navigationController.navigationBar setTitleTextAttributes: @{NSForegroundColorAttributeName:self.navigationController.navigationBar.tintColor}];
  152. self.navigationItem.title = k_brand;
  153. self.navigationItem.leftBarButtonItem = leftButtonCancel;
  154. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:rightButtonUpload, rightButtonEncrypt, nil];
  155. self.navigationItem.hidesBackButton = YES;
  156. }
  157. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  158. {
  159. if (serverUrlTo)
  160. _serverUrl = serverUrlTo;
  161. if (title) {
  162. self.destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), title];
  163. [CCUtility setTitleServerUrlShareExt:title];
  164. } else {
  165. self.destinyFolderButton.title = [NSString stringWithFormat:NSLocalizedString(@"_destiny_folder_", nil), NSLocalizedString(@"_home_", nil)];
  166. [CCUtility setTitleServerUrlShareExt:NSLocalizedString(@"_home_", nil)];
  167. }
  168. [CCUtility setActiveAccountShareExt:self.activeAccount];
  169. [CCUtility setServerUrlShareExt:_serverUrl];
  170. }
  171. - (IBAction)destinyFolderButtonTapped:(UIBarButtonItem *)sender
  172. {
  173. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  174. CCMove *viewController = (CCMove *)navigationController.topViewController;
  175. viewController.delegate = self;
  176. viewController.move.title = NSLocalizedString(@"_select_", nil);
  177. viewController.tintColor = tintColor;
  178. viewController.barTintColor = barTintColor;
  179. viewController.tintColorTitle = tintColor;
  180. viewController.networkingOperationQueue = _networkingOperationQueue;
  181. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  182. [self presentViewController:navigationController animated:YES completion:nil];
  183. }
  184. - (void)selectPost
  185. {
  186. if ([self.filesName count] > 0) {
  187. NSString *fileName = [self.filesName objectAtIndex:0];
  188. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:_activeAccount];
  189. metadataNet.action = actionUploadFile;
  190. metadataNet.cryptated = _localCryptated;
  191. metadataNet.fileName = fileName;
  192. metadataNet.fileNamePrint = fileName;
  193. metadataNet.serverUrl = _serverUrl;
  194. metadataNet.session = k_upload_session_foreground;
  195. metadataNet.taskStatus = k_taskStatusResume;
  196. [self addNetworkingQueue:metadataNet];
  197. [self.hud visibleHudTitle:NSLocalizedString(@"_uploading_", nil) mode:MBProgressHUDModeDeterminateHorizontalBar color:self.view.tintColor];
  198. [self.hud AddButtonCancelWithTarget:self selector:@"cancelTransfer"];
  199. }
  200. else
  201. [self closeShareViewController];
  202. }
  203. - (void)cancelPost
  204. {
  205. // rimuoviamo i file+ico
  206. for (NSString *fileName in self.filesName) {
  207. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil];
  208. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName] error:nil];
  209. }
  210. [self closeShareViewController];
  211. }
  212. - (void)changeEncrypt
  213. {
  214. if (self.localCryptated) self.localCryptated = NO;
  215. else self.localCryptated = YES;
  216. [CCUtility setCryptatedShareExt:self.localCryptated];
  217. [self navigationBarToolBar];
  218. }
  219. - (void)cancelTransfer
  220. {
  221. [_networkingOperationQueue cancelAllOperations];
  222. }
  223. #pragma --------------------------------------------------------------------------------------------
  224. #pragma mark ======================= NetWorking ==================================
  225. #pragma --------------------------------------------------------------------------------------------
  226. - (void)triggerProgressTask:(NSNotification *)notification
  227. {
  228. NSDictionary *dict = notification.userInfo;
  229. float progress = [[dict valueForKey:@"progress"] floatValue];
  230. [self.hud progress:progress];
  231. }
  232. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  233. {
  234. [self.hud hideHud];
  235. // remove file
  236. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, _activeAccount]];
  237. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileID] error:nil];
  238. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, fileID] error:nil];
  239. // message error
  240. if (errorCode != kCFURLErrorCancelled) {
  241. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  242. UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
  243. handler:^(UIAlertAction * action) {
  244. [alert dismissViewControllerAnimated:YES completion:nil];
  245. [self closeShareViewController];
  246. }];
  247. [alert addAction:ok];
  248. [self presentViewController:alert animated:YES completion:nil];
  249. }
  250. else
  251. [self closeShareViewController];
  252. }
  253. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  254. {
  255. [self.hud hideHud];
  256. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, _activeAccount] context:nil];
  257. [self.filesName removeObject:metadata.fileNamePrint];
  258. [self.shareTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  259. [self performSelector:@selector(selectPost) withObject:nil afterDelay:0.1];
  260. }
  261. - (void)addNetworkingQueue:(CCMetadataNet *)metadataNet
  262. {
  263. id operation;
  264. operation = [[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:_activeUser withPassword:_activePassword withUrl:_activeUrl isCryptoCloudMode:_isCryptoCloudMode];
  265. [operation setQueuePriority:metadataNet.priority];
  266. [_networkingOperationQueue addOperation:operation];
  267. }
  268. #pragma --------------------------------------------------------------------------------------------
  269. #pragma mark ===== Lock Password =====
  270. #pragma --------------------------------------------------------------------------------------------
  271. - (void)openBKPasscode
  272. {
  273. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  274. viewController.delegate = self;
  275. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  276. viewController.inputViewTitlePassword = YES;
  277. if ([CCUtility getSimplyBlockCode]) {
  278. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  279. viewController.passcodeInputView.maximumLength = 6;
  280. } else {
  281. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  282. viewController.passcodeInputView.maximumLength = 64;
  283. }
  284. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  285. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  286. viewController.touchIDManager = touchIDManager;
  287. viewController.title = k_brand;
  288. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  289. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  290. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  291. [self presentViewController:navController animated:YES completion:nil];
  292. }
  293. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  294. {
  295. return self.failedAttempts;
  296. }
  297. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  298. {
  299. return self.lockUntilDate;
  300. }
  301. - (void)passcodeViewCloseButtonPressed:(id)sender
  302. {
  303. [self dismissViewControllerAnimated:YES completion:^{
  304. [self performSelector:@selector(closeShareViewController) withObject:nil];
  305. }];
  306. }
  307. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  308. {
  309. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  310. self.lockUntilDate = nil;
  311. self.failedAttempts = 0;
  312. aResultHandler(YES);
  313. } else aResultHandler(NO);
  314. }
  315. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  316. {
  317. [aViewController dismissViewControllerAnimated:YES completion:nil];
  318. }
  319. #pragma --------------------------------------------------------------------------------------------
  320. #pragma mark ===== Swipe Table DELETE -> menu =====
  321. #pragma--------------------------------------------------------------------------------------------
  322. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  323. {
  324. [self setEditing:NO animated:YES];
  325. NSString *fileName = [self.filesName objectAtIndex:indexPath.row];
  326. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil];
  327. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName] error:nil];
  328. [self.filesName removeObjectAtIndex:indexPath.row];
  329. if ([self.filesName count] == 0) [self closeShareViewController];
  330. else [self.shareTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  331. }
  332. #pragma --------------------------------------------------------------------------------------------
  333. #pragma mark == Table ==
  334. #pragma --------------------------------------------------------------------------------------------
  335. - (void)loadDataSwift
  336. {
  337. CCloadItemData *loadItem = [[CCloadItemData alloc] init];
  338. [loadItem loadFiles:self.directoryUser extensionContext:self.extensionContext vc:self];
  339. }
  340. - (void)reloadData:(NSArray *)files
  341. {
  342. totalSize = 0;
  343. for (NSString *file in files) {
  344. NSUInteger fileSize = (NSInteger)[[[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, file] error:nil] fileSize];
  345. totalSize += fileSize;
  346. // creiamo l'ICO
  347. CFStringRef fileExtension = (__bridge CFStringRef)[file pathExtension];
  348. CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
  349. if (fileSize > 0 && ((UTTypeConformsTo(fileUTI, kUTTypeImage)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie)))) {
  350. NSString *typeFile;
  351. if (UTTypeConformsTo(fileUTI, kUTTypeImage)) typeFile = k_metadataTypeFile_image;
  352. if (UTTypeConformsTo(fileUTI, kUTTypeMovie)) typeFile = k_metadataTypeFile_video;
  353. [CCGraphics createNewImageFrom:file directoryUser:self.directoryUser fileNameTo:file fileNamePrint:nil size:@"m" imageForUpload:NO typeFile:typeFile writePreview:YES optimizedFileName:NO];
  354. }
  355. }
  356. if (totalSize > 0) {
  357. self.filesName = [[NSMutableArray alloc] initWithArray:files];
  358. [self.shareTable reloadData];
  359. } else {
  360. [self closeShareViewController];
  361. }
  362. }
  363. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  364. {
  365. return 80;
  366. }
  367. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  368. {
  369. return 1;
  370. }
  371. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  372. {
  373. return [self.filesName count];
  374. }
  375. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  376. {
  377. NSString *fileName = [self.filesName objectAtIndex:indexPath.row];
  378. UIImage *image = nil;
  379. CFStringRef fileExtension = (__bridge CFStringRef)[fileName pathExtension];
  380. CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
  381. if (UTTypeConformsTo(fileUTI, kUTTypeZipArchive) && [(__bridge NSString *)fileUTI containsString:@"org.openxmlformats"] == NO) image = [UIImage imageNamed:image_file_compress];
  382. else if (UTTypeConformsTo(fileUTI, kUTTypeAudio)) image = [UIImage imageNamed:image_file_audio];
  383. else if ((UTTypeConformsTo(fileUTI, kUTTypeImage)) || (UTTypeConformsTo(fileUTI, kUTTypeMovie))) {
  384. image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileName]];
  385. }
  386. else if (UTTypeConformsTo(fileUTI, kUTTypeContent)) {
  387. image = [UIImage imageNamed:image_document];
  388. NSString *typeFile = (__bridge NSString *)fileUTI;
  389. if ([typeFile isEqualToString:@"com.adobe.pdf"]) image = [UIImage imageNamed:image_file_pdf];
  390. if ([typeFile isEqualToString:@"org.openxmlformats.spreadsheetml.sheet"]) image = [UIImage imageNamed:image_file_xls];
  391. if ([typeFile isEqualToString:@"public.plain-text"]) image = [UIImage imageNamed:image_file_txt];
  392. }
  393. else image = [UIImage imageNamed:image_file];
  394. CCCellShareExt *cell = (CCCellShareExt *)[tableView dequeueReusableCellWithIdentifier:@"ShareExtCell" forIndexPath:indexPath];
  395. NSUInteger fileSize = (NSInteger)[[[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileName] error:nil] fileSize];
  396. cell.labelInformazioni.text = [NSString stringWithFormat:@"%@\r\r%@", fileName, [CCUtility transformedSize:fileSize]];
  397. cell.labelInformazioni.textColor = [UIColor blackColor];
  398. cell.fileImageView.image = image;
  399. return cell;
  400. }
  401. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  402. {
  403. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  404. }
  405. @end