CCFavorite.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. //
  2. // CCFavorite.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 11/11/14.
  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 "CCFavorite.h"
  24. #import "AppDelegate.h"
  25. #import "CCSynchronization.h"
  26. #pragma GCC diagnostic ignored "-Wundeclared-selector"
  27. @interface CCFavorite ()
  28. {
  29. NSMutableArray *dataSource;
  30. }
  31. @end
  32. @implementation CCFavorite
  33. #pragma --------------------------------------------------------------------------------------------
  34. #pragma mark ===== Init =====
  35. #pragma --------------------------------------------------------------------------------------------
  36. - (id)initWithCoder:(NSCoder *)aDecoder
  37. {
  38. if (self = [super initWithCoder:aDecoder]) {
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTable) name:@"reloadTableFavorite" object:nil];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(synchronizedFavorites) name:@"synchronizedFavorites" object:nil];
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initToHome) name:@"initToHomeCCPreferitiViewController" object:nil];
  42. app.activeFavorite = self;
  43. }
  44. return self;
  45. }
  46. - (id)initWithStyle:(UITableViewStyle)style
  47. {
  48. self = [super initWithStyle:style];
  49. if (self) {
  50. // Custom initialization
  51. }
  52. return self;
  53. }
  54. #pragma --------------------------------------------------------------------------------------------
  55. #pragma mark ===== View =====
  56. #pragma --------------------------------------------------------------------------------------------
  57. - (void)viewDidLoad
  58. {
  59. [super viewDidLoad];
  60. // Custom Cell
  61. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellFavorite" bundle:nil] forCellReuseIdentifier:@"FavoriteCell"];
  62. // Settings initial dir
  63. if (![self.serverUrlLocal length]) self.serverUrlLocal = @"favorite";
  64. // dataSource
  65. dataSource = [[NSMutableArray alloc] init];
  66. // Metadata
  67. self.metadata = [[CCMetadata alloc] init];
  68. self.tableView.emptyDataSetDelegate = self;
  69. self.tableView.emptyDataSetSource = self;
  70. self.tableView.tableFooterView = [UIView new];
  71. // button
  72. UIImage *image;
  73. if ([self.serverUrlLocal isEqualToString:@"favorite"]) {
  74. image = [UIImage imageNamed:image_navBarLocal];
  75. self.textView = NSLocalizedString(@"_favorites_", nil);
  76. } else image = [UIImage imageNamed:image_navBarFavorite];
  77. UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(switchFavoriteLocal)];
  78. self.navigationItem.rightBarButtonItem=_btn;
  79. [self reloadTable];
  80. }
  81. // Apparirà
  82. - (void)viewWillAppear:(BOOL)animated
  83. {
  84. [super viewWillAppear:animated];
  85. // Color
  86. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  87. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  88. // title
  89. self.title = self.textView;
  90. [self reloadTable];
  91. }
  92. #pragma --------------------------------------------------------------------------------------------
  93. #pragma mark ===== Effetti Grafici =====
  94. #pragma --------------------------------------------------------------------------------------------
  95. - (void)forcedSwitchFavorite
  96. {
  97. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO)
  98. [self switchFavoriteLocal];
  99. }
  100. - (void)switchFavoriteLocal
  101. {
  102. UIImage *imageBarButton;
  103. if ([self.serverUrlLocal isEqualToString:@"favorite"]) {
  104. self.textView = NSLocalizedString(@"_local_storage_", nil);
  105. imageBarButton = [UIImage imageNamed:@"navBarFavorite"];
  106. // img Tab Bar
  107. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:1];
  108. item.selectedImage = [UIImage imageNamed:@"tabBarLocal"];
  109. item.image = [UIImage imageNamed:@"tabBarLocal"];
  110. self.serverUrlLocal = [CCUtility getDirectoryLocal];
  111. app.isLocalStorage = true;
  112. } else {
  113. self.textView = NSLocalizedString(@"_favorites_", nil);
  114. imageBarButton = [UIImage imageNamed:@"navBarLocal"];
  115. // Image Tab Bar
  116. UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:1];
  117. item.selectedImage = [UIImage imageNamed:@"tabBarFavorite"];
  118. item.image = [UIImage imageNamed:@"tabBarFavorite"];
  119. self.serverUrlLocal = @"favorite";
  120. app.isLocalStorage = false;
  121. }
  122. UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:imageBarButton style:UIBarButtonItemStylePlain target:self action:@selector(switchFavoriteLocal)];
  123. self.navigationItem.rightBarButtonItem=_btn;
  124. // init of Navigation Control
  125. [self.navigationController popToRootViewControllerAnimated:NO];
  126. // refresh
  127. if ([self.serverUrlLocal isEqualToString:@"favorite"])
  128. [[NSNotificationCenter defaultCenter] postNotificationName:@"initToHomeCCPreferitiViewController" object:nil];
  129. else
  130. [self reloadTable];
  131. }
  132. #pragma --------------------------------------------------------------------------------------------
  133. #pragma mark ==== DZNEmptyDataSetSource Methods ====
  134. #pragma --------------------------------------------------------------------------------------------
  135. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
  136. {
  137. if ([self.serverUrlLocal isEqualToString:@"favorite"] || [self.serverUrlLocal isEqualToString:[CCUtility getDirectoryLocal]]) return YES;
  138. else return NO;
  139. }
  140. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  141. {
  142. return 0.0f;
  143. }
  144. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
  145. {
  146. return - self.navigationController.navigationBar.frame.size.height;
  147. }
  148. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  149. {
  150. return [UIColor whiteColor];
  151. }
  152. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  153. {
  154. if ([self.serverUrlLocal isEqualToString:@"favorite"]) return [UIImage imageNamed:image_brandFavorite];
  155. else return [UIImage imageNamed:image_brandLocal];
  156. }
  157. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  158. {
  159. NSString *text;
  160. if ([self.serverUrlLocal isEqualToString:@"favorite"]) text = NSLocalizedString(@"_no_files_uploaded_", nil);
  161. else text = NSLocalizedString(@"_no_files_uploaded_", nil);
  162. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
  163. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  164. }
  165. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  166. {
  167. NSString *text;
  168. if ([self.serverUrlLocal isEqualToString:@"favorite"]) text = NSLocalizedString(@"_tutorial_favorite_view_", nil);
  169. else text = NSLocalizedString(@"_tutorial_local_view_", nil);
  170. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  171. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  172. paragraph.alignment = NSTextAlignmentCenter;
  173. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  174. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  175. }
  176. #pragma --------------------------------------------------------------------------------------------
  177. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  178. #pragma --------------------------------------------------------------------------------------------
  179. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  180. {
  181. // evitiamo il rimando della eventuale photo e/o video
  182. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  183. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  184. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  185. }
  186. }
  187. #pragma --------------------------------------------------------------------------------------------
  188. #pragma mark ==== Comandi ====
  189. #pragma --------------------------------------------------------------------------------------------
  190. - (void)openModel:(CCMetadata *)metadata
  191. {
  192. UIViewController *viewController;
  193. if ([metadata.model isEqualToString:@"cartadicredito"])
  194. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  195. if ([metadata.model isEqualToString:@"bancomat"])
  196. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  197. if ([metadata.model isEqualToString:@"contocorrente"])
  198. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  199. if ([metadata.model isEqualToString:@"accountweb"])
  200. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  201. if ([metadata.model isEqualToString:@"patenteguida"])
  202. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  203. if ([metadata.model isEqualToString:@"cartaidentita"])
  204. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  205. if ([metadata.model isEqualToString:@"passaporto"])
  206. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  207. if ([metadata.model isEqualToString:@"note"]) {
  208. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:app.isLocalStorage];
  209. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  210. [self presentViewController:navigationController animated:YES completion:nil];
  211. } else {
  212. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  213. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  214. [self presentViewController:navigationController animated:YES completion:nil];
  215. }
  216. }
  217. - (void)openWith:(CCMetadata *)metadata
  218. {
  219. NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", self.serverUrlLocal, metadata.fileNamePrint]];
  220. self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  221. self.docController.delegate = self;
  222. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  223. }
  224. #pragma --------------------------------------------------------------------------------------------
  225. #pragma mark ===== Synchronized favorite =====
  226. #pragma---------------------------------------------------------------------------------------------
  227. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  228. {
  229. // error
  230. }
  231. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
  232. {
  233. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  234. [[CCSynchronization sharedSynchronization] verifyChangeMedatas:[[NSArray alloc] initWithObjects:metadata, nil] serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount synchronization:NO];
  235. });
  236. [self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
  237. }
  238. - (void)synchronizedFavorites
  239. {
  240. if (app.activeAccount == nil || [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud] == nil) return;
  241. NSArray *metadatas = [[NSArray alloc] init];
  242. metadatas = [CCCoreData getFavoriteWithControlZombie:YES activeAccount:app.activeAccount directoryUser:app.directoryUser];
  243. for (CCMetadata *metadata in metadatas) {
  244. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  245. if (serverUrl == nil) continue;
  246. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  247. metadataNet.action = actionReadFile;
  248. metadataNet.fileName = metadata.fileName;
  249. metadataNet.fileNamePrint = metadata.fileNamePrint;
  250. metadataNet.serverUrl = serverUrl;
  251. metadataNet.selector = selectorReadFileFavorite;
  252. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  253. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet oneByOne:YES];
  254. }
  255. }
  256. #pragma --------------------------------------------------------------------------------------------
  257. #pragma mark ===== Swipe Table -> menu =====
  258. #pragma--------------------------------------------------------------------------------------------
  259. // more
  260. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  261. {
  262. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO) {
  263. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  264. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  265. CCMetadata *metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:self.serverUrlLocal activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  266. if (metadata.directory)
  267. return nil;
  268. else
  269. return NSLocalizedString(@"_more_", nil);
  270. } else return nil;
  271. }
  272. + (UIView *)headerActionSheet:(UITableViewController *)vc image:(UIImage *)image title:(NSString *)title cryptated:(BOOL)cryptated
  273. {
  274. CGFloat width = CGRectGetWidth(vc.view.bounds);
  275. //CGFloat height = CGRectGetHeight(vc.view.bounds);
  276. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
  277. headerView.backgroundColor = COLOR_NAVBAR_IOS7;
  278. // IMAGE
  279. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  280. imageView.frame = CGRectMake(13, 15, 30, 30);
  281. [headerView addSubview:imageView];
  282. // LABEL
  283. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(55, 0, width-55-10, 60)];
  284. label.numberOfLines = 0;
  285. label.text = title;
  286. if (cryptated) label.textColor = COLOR_ENCRYPTED;
  287. else label.textColor = COLOR_CLEAR;
  288. label.font = [UIFont systemFontOfSize:13];
  289. label.backgroundColor = [UIColor clearColor];
  290. [headerView addSubview:label];
  291. return headerView;
  292. }
  293. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  294. {
  295. UIImage *iconHeader;
  296. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  297. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  298. self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:self.serverUrlLocal activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  299. [self setEditing:NO animated:YES];
  300. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  301. actionSheet.blurRadius = 1.0f;
  302. actionSheet.buttonHeight = 50.0;
  303. actionSheet.cancelButtonHeight = 50.0f;
  304. actionSheet.selectedBackgroundColor = COLOR_SELECT_BACKGROUND;
  305. actionSheet.cryptoButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:17], NSForegroundColorAttributeName:COLOR_BRAND };
  306. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:17], NSForegroundColorAttributeName:COLOR_GRAY };
  307. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  308. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  309. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  310. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/.%@.ico", self.serverUrlLocal, self.metadata.fileNamePrint]])
  311. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", self.serverUrlLocal, self.metadata.fileNamePrint]];
  312. else
  313. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  314. UIView *headerView = [[self class] headerActionSheet:self image:iconHeader title:self.metadata.fileNamePrint cryptated:self.metadata.cryptated];
  315. actionSheet.headerView = headerView;
  316. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  317. image:[UIImage imageNamed:image_actionSheetOpenIn]
  318. type:AHKActionSheetButtonTypeDefault
  319. handler:^(AHKActionSheet *as) {
  320. [self performSelector:@selector(openWith:) withObject:self.metadata afterDelay:0.1];
  321. }];
  322. [actionSheet show];
  323. }
  324. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  325. {
  326. // close swip
  327. [self setEditing:NO animated:YES];
  328. if ([self.serverUrlLocal isEqualToString:@"favorite"]) {
  329. NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
  330. [CCCoreData removeFavoriteFromFileID:[record valueForKey:@"fileID"] activeAccount:app.activeAccount];
  331. }
  332. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO) {
  333. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", self.serverUrlLocal,[dataSource objectAtIndex:indexPath.row]];
  334. NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", self.serverUrlLocal,[dataSource objectAtIndex:indexPath.row]];
  335. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  336. [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
  337. }
  338. [self reloadTable];
  339. }
  340. #pragma --------------------------------------------------------------------------------------------
  341. #pragma mark ==== Table ====
  342. #pragma --------------------------------------------------------------------------------------------
  343. - (void)initToHome
  344. {
  345. self.serverUrlLocal = @"favorite";
  346. self.textView = NSLocalizedString(@"_favorites_", nil);
  347. UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:image_navBarLocal] style:UIBarButtonItemStylePlain target:self action:@selector(switchFavoriteLocal)];
  348. self.navigationItem.rightBarButtonItem=_btn;
  349. [self reloadTable];
  350. }
  351. - (void)reloadTable
  352. {
  353. // Datasource
  354. if ([self.serverUrlLocal isEqualToString:@"favorite"])
  355. dataSource = (NSMutableArray *)[CCCoreData getFavoriteWithControlZombie:YES activeAccount:app.activeAccount directoryUser:app.directoryUser];
  356. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO) {
  357. [dataSource removeAllObjects];
  358. NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.serverUrlLocal error:nil];
  359. for (NSString *subpath in subpaths)
  360. if (![[subpath lastPathComponent] hasPrefix:@"."]) [dataSource addObject:subpath];
  361. }
  362. // title
  363. self.title = self.textView;
  364. [self.tableView reloadData];
  365. }
  366. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  367. {
  368. return 60;
  369. }
  370. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  371. {
  372. return 1;
  373. }
  374. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  375. {
  376. return [dataSource count];
  377. }
  378. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  379. {
  380. CCCellFavorite *cell = (CCCellFavorite *)[tableView dequeueReusableCellWithIdentifier:@"FavoriteCell" forIndexPath:indexPath];
  381. // change color selection
  382. UIView *selectionColor = [[UIView alloc] init];
  383. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  384. cell.selectedBackgroundView = selectionColor;
  385. // i am in favorite
  386. if ([self.serverUrlLocal isEqualToString:@"favorite"]) {
  387. self.metadata = [dataSource objectAtIndex:indexPath.row];
  388. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadata.fileID]];
  389. }
  390. // i am in local
  391. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO) {
  392. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  393. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  394. self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:self.serverUrlLocal activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  395. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", self.serverUrlLocal, self.metadata.fileNamePrint]];
  396. if (!cell.fileImageView.image) {
  397. UIImage *icon = [CCGraphics createNewImageFrom:self.metadata.fileID directoryUser:self.serverUrlLocal fileNameTo:self.metadata.fileID fileNamePrint:self.metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  398. if (icon) {
  399. [CCGraphics saveIcoWithFileID:self.metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", self.serverUrlLocal, self.metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
  400. cell.fileImageView.image = icon;
  401. }
  402. }
  403. }
  404. // color and font
  405. if (self.metadata.cryptated) {
  406. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  407. //nameLabel.font = RalewayLight(13.0f);
  408. cell.labelInfoFile.textColor = [UIColor blackColor];
  409. //detailLabel.font = RalewayLight(9.0f);
  410. } else {
  411. cell.labelTitle.textColor = COLOR_CLEAR;
  412. //nameLabel.font = RalewayLight(13.0f);
  413. cell.labelInfoFile.textColor = [UIColor blackColor];
  414. //detailLabel.font = RalewayLight(9.0f);
  415. }
  416. if (self.metadata.directory) {
  417. cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
  418. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  419. }
  420. // File name
  421. cell.labelTitle.text = self.metadata.fileNamePrint;
  422. cell.labelInfoFile.text = @"";
  423. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  424. if (cell.fileImageView.image == nil)
  425. cell.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
  426. cell.statusImageView.image = nil;
  427. // it's encrypted ???
  428. if (self.metadata.cryptated && [self.metadata.type isEqualToString:metadataType_model] == NO)
  429. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  430. // it's in download mode
  431. if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound)
  432. cell.statusImageView.image = [UIImage imageNamed:image_attention];
  433. // text and length
  434. if (self.metadata.directory) {
  435. cell.labelInfoFile.text = [CCUtility dateDiff:self.metadata.date];
  436. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  437. } else {
  438. NSString *date = [CCUtility dateDiff:self.metadata.date];
  439. NSString *length = [CCUtility transformedSize:self.metadata.size];
  440. if ([self.metadata.type isEqualToString:metadataType_model])
  441. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  442. if ([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local])
  443. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", date, length];
  444. cell.accessoryType = UITableViewCellAccessoryNone;
  445. }
  446. return cell;
  447. }
  448. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  449. {
  450. // deselect row
  451. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  452. if ([self.serverUrlLocal isEqualToString:@"favorite"]) {
  453. NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
  454. self.fileIDPhoto = [record valueForKey:@"fileID"];
  455. self.directoryIDPhoto = nil;
  456. self.metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", self.fileIDPhoto, app.activeAccount] context:nil];
  457. }
  458. if ([self.serverUrlLocal isEqualToString:@"favorite"] == NO) {
  459. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  460. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  461. self.metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:self.serverUrlLocal activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  462. self.fileIDPhoto = self.metadata.fileID;
  463. self.directoryIDPhoto = self.serverUrlLocal;
  464. }
  465. // if is in download [do not touch]
  466. if ([self.metadata.session length] > 0 && [self.metadata.session rangeOfString:@"download"].location != NSNotFound) return;
  467. if (([self.metadata.type isEqualToString:metadataType_file] || [self.metadata.type isEqualToString:metadataType_local]) && self.metadata.directory == NO) {
  468. if ([self shouldPerformSegue])
  469. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  470. }
  471. if ([self.metadata.type isEqualToString:metadataType_model]) [self openModel:self.metadata];
  472. if (self.metadata.directory) [self performSegueDirectoryWithControlPasscode];
  473. }
  474. -(void)performSegueDirectoryWithControlPasscode
  475. {
  476. CCFavorite *viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCFavoriteVC"];
  477. viewController.serverUrlLocal = [CCUtility stringAppendServerUrl:self.serverUrlLocal addServerUrl:self.metadata.fileName];
  478. viewController.textView = self.metadata.fileName;
  479. [self.navigationController pushViewController:viewController animated:YES];
  480. }
  481. #pragma --------------------------------------------------------------------------------------------
  482. #pragma mark ===== Navigation ====
  483. #pragma --------------------------------------------------------------------------------------------
  484. - (BOOL)shouldPerformSegue
  485. {
  486. // if i am in background -> exit
  487. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  488. // if i am not window -> exit
  489. if (self.view.window == NO)
  490. return NO;
  491. // Collapsed but i am in detail -> exit
  492. if (self.splitViewController.isCollapsed)
  493. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  494. // Video in run -> exit
  495. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  496. return YES;
  497. }
  498. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  499. {
  500. id viewController = segue.destinationViewController;
  501. if ([viewController isKindOfClass:[UINavigationController class]]) {
  502. UINavigationController *nav = viewController;
  503. self.detailViewController = (CCDetail *)nav.topViewController;
  504. } else {
  505. self.detailViewController = segue.destinationViewController;
  506. }
  507. self.detailViewController.metadataDetail = self.metadata;
  508. if (app.isLocalStorage) self.detailViewController.sourceDirectory = sorceDirectoryLocal;
  509. else self.detailViewController.sourceDirectory = sorceDirectoryFavorite;
  510. self.detailViewController.dateFilterQuery = nil;
  511. self.detailViewController.isCameraUpload = NO;
  512. [self.detailViewController setTitle:self.metadata.fileNamePrint];
  513. }
  514. @end