ShareViewController.m 22 KB

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