CCMedia.m 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. //
  2. // CCMedia.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 29/07/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCMedia.h"
  24. #import "AppDelegate.h"
  25. #import "CCManageAutoUpload.h"
  26. #import "TOScrollBar.h"
  27. #import "NCBridgeSwift.h"
  28. @interface CCMedia () <NCSelectDelegate>
  29. {
  30. AppDelegate *appDelegate;
  31. NSMutableArray *selectedMetadatas;
  32. CCSectionDataSourceMetadata *sectionDataSource;
  33. BOOL filterTypeFileImage;
  34. BOOL filterTypeFileVideo;
  35. BOOL isSearchMode;
  36. BOOL isEditMode;
  37. TOScrollBar *scrollBar;
  38. NSMutableDictionary *saveEtagForStartDirectory;
  39. // Fix Crash Thumbnail + collectionView ReloadData ?
  40. NSInteger counterThumbnail;
  41. BOOL collectionViewReloadDataInProgress;
  42. // Remenu
  43. REMenu *menu;
  44. REMenuItem *menuSelectMediaFolder;
  45. REMenuItem *menuFilterImage;
  46. REMenuItem *menuFilterVideo;
  47. REMenuItem *menuSelectItems;
  48. }
  49. @end
  50. @implementation CCMedia
  51. #pragma --------------------------------------------------------------------------------------------
  52. #pragma mark ===== Init =====
  53. #pragma --------------------------------------------------------------------------------------------
  54. - (id)initWithCoder:(NSCoder *)aDecoder
  55. {
  56. if (self = [super initWithCoder:aDecoder]) {
  57. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  58. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  59. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  60. appDelegate.activeMedia = self;
  61. }
  62. return self;
  63. }
  64. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  65. {
  66. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  67. if (self) {
  68. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  69. }
  70. return self;
  71. }
  72. #pragma --------------------------------------------------------------------------------------------
  73. #pragma mark ===== View =====
  74. #pragma --------------------------------------------------------------------------------------------
  75. - (void)viewDidLoad
  76. {
  77. [super viewDidLoad];
  78. saveEtagForStartDirectory = [NSMutableDictionary new];
  79. selectedMetadatas = [NSMutableArray new];
  80. self.addMetadatasFromUpload = [NSMutableArray new];
  81. // empty Data Source
  82. self.collectionView.emptyDataSetDelegate = self;
  83. self.collectionView.emptyDataSetSource = self;
  84. // scroll bar
  85. scrollBar = [TOScrollBar new];
  86. [self.collectionView to_addScrollBar:scrollBar];
  87. scrollBar.handleTintColor = [NCBrandColor sharedInstance].brand;
  88. scrollBar.handleWidth = 20;
  89. scrollBar.handleMinimiumHeight = 20;
  90. scrollBar.trackWidth = 0;
  91. scrollBar.edgeInset = 12;
  92. // Query data source
  93. [self queryDatasourceWithReloadData:YES];
  94. }
  95. - (void)viewWillAppear:(BOOL)animated
  96. {
  97. [super viewWillAppear:animated];
  98. // Color
  99. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  100. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  101. // Plus Button
  102. [appDelegate plusButtonVisibile:true];
  103. }
  104. - (void)viewDidAppear:(BOOL)animated
  105. {
  106. [super viewDidAppear:animated];
  107. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  108. [self reloadDatasource:nil action:k_action_NULL];
  109. });
  110. }
  111. - (void)viewSafeAreaInsetsDidChange
  112. {
  113. [super viewSafeAreaInsetsDidChange];
  114. self.collectionView.contentInset = self.view.safeAreaInsets;
  115. }
  116. - (void)changeTheming
  117. {
  118. if (self.isViewLoaded && self.view.window)
  119. [appDelegate changeTheming:self];
  120. scrollBar.handleTintColor = [NCBrandColor sharedInstance].brand;
  121. [self.collectionView reloadData];
  122. }
  123. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  124. {
  125. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  126. [menu close];
  127. // Before rotation
  128. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  129. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  130. // Portrait
  131. } else {
  132. // Landscape
  133. }
  134. [self.collectionView reloadData];
  135. }];
  136. }
  137. #pragma --------------------------------------------------------------------------------------------
  138. #pragma mark ===== Gestione Grafica Window =====
  139. #pragma --------------------------------------------------------------------------------------------
  140. - (void)openMenu
  141. {
  142. if (menu.isOpen) {
  143. [menu close];
  144. } else {
  145. [self createReMainMenu];
  146. [menu showFromNavigationController:self.navigationController];
  147. // Backgroun reMenu & (Gesture)
  148. [self createReMenuBackgroundView:menu];
  149. self.singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openMenu)];
  150. [self.reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  151. }
  152. }
  153. - (void)createReMenuBackgroundView:(REMenu *)menu
  154. {
  155. CGFloat safeAreaBottom = 0;
  156. CGFloat safeAreaTop = 0;
  157. CGFloat statusBar = 0;
  158. if (@available(iOS 11, *)) {
  159. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  160. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  161. }
  162. if ([UIApplication sharedApplication].isStatusBarHidden) {
  163. statusBar = 13;
  164. }
  165. CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
  166. UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
  167. CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
  168. self.reMenuBackgroundView = [UIView new];
  169. self.reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  170. self.reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
  171. [UIView animateWithDuration:0.2 animations:^{
  172. CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
  173. CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
  174. if (y>minimum) {
  175. self.reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
  176. [self.tabBarController.view addSubview:self.reMenuBackgroundView];
  177. }
  178. }];
  179. }
  180. - (void)createReMainMenu
  181. {
  182. menuSelectItems = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"select"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  183. if ([sectionDataSource.allRecordsDataSource count] > 0) {
  184. [self editingModeYES];
  185. }
  186. }];
  187. menuSelectMediaFolder = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_media_folder_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folderMedia"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  188. [self selectStartDirectoryPhotosTab];
  189. }];
  190. if (filterTypeFileImage) {
  191. menuFilterImage = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_media_viewimage_show_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"imageno"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  192. filterTypeFileImage = NO;
  193. [self reloadDatasource:nil action:k_action_NULL];
  194. }];
  195. } else {
  196. menuFilterImage = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_media_viewimage_hide_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"imageyes"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  197. filterTypeFileImage = YES;
  198. [self reloadDatasource:nil action:k_action_NULL];
  199. }];
  200. }
  201. if (filterTypeFileVideo) {
  202. menuFilterVideo = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_media_viewvideo_show_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"videono"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  203. filterTypeFileVideo = NO;
  204. [self reloadDatasource:nil action:k_action_NULL];
  205. }];
  206. } else {
  207. menuFilterVideo = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_media_viewvideo_hide_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"videoyes"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  208. filterTypeFileVideo = YES;
  209. [self reloadDatasource:nil action:k_action_NULL];
  210. }];
  211. }
  212. // REMENU --------------------------------------------------------------------------------------------------------------
  213. menu = [[REMenu alloc] initWithItems:@[menuSelectItems, menuSelectMediaFolder, menuFilterImage, menuFilterVideo]];
  214. menu.imageOffset = CGSizeMake(5, -1);
  215. menu.separatorOffset = CGSizeMake(50.0, 0.0);
  216. menu.imageOffset = CGSizeMake(0, 0);
  217. menu.waitUntilAnimationIsComplete = NO;
  218. menu.separatorHeight = 0.5;
  219. menu.separatorColor = [NCBrandColor sharedInstance].seperator;
  220. menu.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  221. menu.textColor = [UIColor blackColor];
  222. menu.textAlignment = NSTextAlignmentLeft;
  223. menu.textShadowColor = nil;
  224. menu.textOffset = CGSizeMake(50, 0.0);
  225. menu.font = [UIFont systemFontOfSize:14.0];
  226. menu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  227. menu.highlightedSeparatorColor = nil;
  228. menu.highlightedTextColor = [UIColor blackColor];
  229. menu.highlightedTextShadowColor = nil;
  230. menu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  231. menu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  232. menu.subtitleTextAlignment = NSTextAlignmentLeft;
  233. menu.subtitleTextShadowColor = nil;
  234. menu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  235. menu.subtitleTextOffset = CGSizeMake(50, 0.0);
  236. menu.subtitleFont = [UIFont systemFontOfSize:12.0];
  237. menu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  238. menu.subtitleHighlightedTextShadowColor = nil;
  239. menu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  240. menu.borderWidth = 0.3;
  241. menu.borderColor = [UIColor lightGrayColor];
  242. menu.animationDuration = 0.2;
  243. menu.closeAnimationDuration = 0.2;
  244. menu.bounce = NO;
  245. __weak typeof(self) weakSelf = self;
  246. [menu setClosePreparationBlock:^{
  247. // Backgroun reMenu (Gesture)
  248. [weakSelf.reMenuBackgroundView removeFromSuperview];
  249. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  250. }];
  251. }
  252. - (void)setUINavigationBarDefault
  253. {
  254. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  255. // curront folder search
  256. NSString *directory = [[NCManageDatabase sharedInstance] getAccountStartDirectoryMediaTabView:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
  257. NSString *home = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  258. NSString *folder = @"";
  259. if (home.length > 0) {
  260. folder = [directory stringByReplacingOccurrencesOfString:home withString:@""];
  261. }
  262. // Title
  263. NSString *title;
  264. if (folder.length == 0) {
  265. title = NSLocalizedString(@"_media_", nil);
  266. } else {
  267. title = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"_media_", nil), [folder substringFromIndex:1]];
  268. }
  269. self.navigationItem.titleView = nil;
  270. self.navigationItem.title = title;
  271. if (isSearchMode) {
  272. [CCGraphics addImageToTitle:title colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
  273. }
  274. // Button Item RIGHT
  275. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(openMenu)];
  276. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  277. self.navigationItem.leftBarButtonItems = nil;
  278. }
  279. - (void)setUINavigationBarSelected
  280. {
  281. UIBarButtonItem *buttonDelete = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"delete"] style:UIBarButtonItemStylePlain target:self action:@selector(deleteSelectedFiles)];
  282. // UIBarButtonItem *buttonOpenIn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(openSelectedFiles)];
  283. UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(editingModeNO)];
  284. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:cancelButton, nil];
  285. self.navigationItem.leftBarButtonItems = [[NSArray alloc] initWithObjects:buttonDelete, nil];
  286. // Title
  287. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)[selectedMetadatas count], (unsigned long)[sectionDataSource.allRecordsDataSource count]];
  288. }
  289. - (void)cellSelect:(BOOL)select indexPath:(NSIndexPath *)indexPath metadata:(tableMetadata *)metadata
  290. {
  291. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
  292. UIVisualEffectView *effect = [cell viewWithTag:200];
  293. UIImageView *checked = [cell viewWithTag:300];
  294. if (select) {
  295. effect.hidden = NO;
  296. effect.alpha = 0.4;
  297. checked.hidden = NO;
  298. [selectedMetadatas addObject:metadata];
  299. } else {
  300. effect.hidden = YES;
  301. checked.hidden = YES;
  302. [selectedMetadatas removeObject:metadata];
  303. }
  304. // Title
  305. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)[selectedMetadatas count], (unsigned long)[sectionDataSource.allRecordsDataSource count]];
  306. }
  307. - (void)scrollToTop
  308. {
  309. [self.collectionView setContentOffset:CGPointMake(0, - self.collectionView.contentInset.top) animated:NO];
  310. }
  311. - (void)getGeoLocationForSection:(NSInteger)section
  312. {
  313. NSString *addLocation = @"";
  314. NSArray *fileIDsForKey = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]];
  315. for (NSString *fileID in fileIDsForKey) {
  316. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  317. if ([localFile.exifLatitude floatValue] > 0 || [localFile.exifLongitude floatValue] > 0) {
  318. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  319. addLocation = [NSString stringWithFormat:@"%@, %@", addLocation, location];
  320. }
  321. }
  322. }
  323. #pragma --------------------------------------------------------------------------------------------
  324. #pragma mark ==== DZNEmptyDataSetSource Methods ====
  325. #pragma --------------------------------------------------------------------------------------------
  326. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  327. {
  328. return [NCBrandColor sharedInstance].backgroundView;
  329. }
  330. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  331. {
  332. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"mediaNoRecord"] multiplier:1 color:[NCBrandColor sharedInstance].graySoft];
  333. }
  334. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  335. {
  336. NSString *text;
  337. if (isSearchMode) {
  338. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_search_in_progress_", nil)];
  339. } else {
  340. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_photo_view_", nil)];
  341. }
  342. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  343. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  344. }
  345. /*
  346. #pragma --------------------------------------------------------------------------------------------
  347. #pragma mark ===== openSelectedFiles =====
  348. #pragma--------------------------------------------------------------------------------------------
  349. - (void)openSelectedFiles
  350. {
  351. NSMutableArray *dataToShare = [[NSMutableArray alloc] init];
  352. for (tableMetadata *metadata in selectedMetadatas) {
  353. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView];
  354. if ([CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView]) {
  355. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  356. NSData *data = [NSData dataWithData:UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:fileNamePath], 0.9)];
  357. [dataToShare addObject:data];
  358. }
  359. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  360. [dataToShare addObject:[NSURL fileURLWithPath:fileNamePath]];
  361. }
  362. }
  363. }
  364. if ([dataToShare count] > 0) {
  365. UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
  366. // iPad
  367. activityViewController.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
  368. self.navigationItem.leftBarButtonItem.enabled = NO;
  369. self.navigationItem.rightBarButtonItem.enabled = NO;
  370. [self presentViewController:activityViewController animated:YES completion:^{
  371. [activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
  372. self.navigationItem.leftBarButtonItem.enabled = YES;
  373. self.navigationItem.rightBarButtonItem.enabled = YES;
  374. [self editingModeNO];
  375. if (completed) {
  376. [self.collectionView reloadData];
  377. }
  378. }];
  379. }];
  380. }
  381. }
  382. */
  383. #pragma --------------------------------------------------------------------------------------------
  384. #pragma mark ===== Download =====
  385. #pragma--------------------------------------------------------------------------------------------
  386. - (void)triggerProgressTask:(NSNotification *)notification
  387. {
  388. //NSDictionary *dict = notification.userInfo;
  389. //float progress = [[dict valueForKey:@"progress"] floatValue];
  390. }
  391. - (void)downloadFileSuccessFailure:(NSString *)fileName fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector errorMessage:(NSString *)errorMessage errorCode:(NSInteger)errorCode
  392. {
  393. if (errorCode == 0) {
  394. NSIndexPath *indexPath;
  395. BOOL existsIcon = NO;
  396. if (fileID) {
  397. existsIcon = [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:fileID fileNameView:fileName]];
  398. indexPath = [sectionDataSource.fileIDIndexPath objectForKey:fileID];
  399. }
  400. if ([self indexPathIsValid:indexPath] && existsIcon) {
  401. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
  402. if (cell) {
  403. UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
  404. UIVisualEffectView *effect = [cell viewWithTag:200];
  405. UIImageView *checked = [cell viewWithTag:300];
  406. imageView.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:fileID fileNameView:fileName]];
  407. effect.hidden = YES;
  408. checked.hidden = YES;
  409. }
  410. }
  411. } else {
  412. [appDelegate messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  413. }
  414. }
  415. #pragma --------------------------------------------------------------------------------------------
  416. #pragma mark ===== Delete =====
  417. #pragma--------------------------------------------------------------------------------------------
  418. - (void)deleteFile:(NSArray *)metadatas e2ee:(BOOL)e2ee
  419. {
  420. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:false serverUrl:@"" folderFileID:@"" completion:^(NSInteger errorCode, NSString *message) {
  421. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:nil fileID:nil action:k_action_NULL];
  422. }];
  423. [self editingModeNO];
  424. }
  425. - (void)deleteSelectedFiles
  426. {
  427. if ([selectedMetadatas count] == 0)
  428. return;
  429. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  430. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  431. style:UIAlertActionStyleDestructive
  432. handler:^(UIAlertAction *action) {
  433. [self deleteFile:selectedMetadatas e2ee:false];
  434. }]];
  435. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  436. style:UIAlertActionStyleCancel
  437. handler:^(UIAlertAction *action) {
  438. }]];
  439. alertController.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItems.firstObject;
  440. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  441. [alertController.view layoutIfNeeded];
  442. [self presentViewController:alertController animated:YES completion:NULL];
  443. }
  444. #pragma --------------------------------------------------------------------------------------------
  445. #pragma mark ==== Download Thumbnail ====
  446. #pragma --------------------------------------------------------------------------------------------
  447. - (void)downloadThumbnail:(tableMetadata *)metadata indexPath:(NSIndexPath *)indexPath
  448. {
  449. counterThumbnail++;
  450. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  451. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  452. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  453. [ocNetworking downloadPreviewWithMetadata:metadata withWidth:width andHeight:height completion:^(NSString *message, NSInteger errorCode) {
  454. counterThumbnail--;
  455. if (errorCode == 0 && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] && [self indexPathIsValid:indexPath] && !collectionViewReloadDataInProgress) {
  456. [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
  457. }
  458. }];
  459. }
  460. #pragma --------------------------------------------------------------------------------------------
  461. #pragma mark ==== Change Start directory ====
  462. #pragma --------------------------------------------------------------------------------------------
  463. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  464. {
  465. if ([type isEqualToString:@"mediaFolder"]) {
  466. NSString *oldStartDirectoryMediaTabView = [[NCManageDatabase sharedInstance] getAccountStartDirectoryMediaTabView:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
  467. if (![serverUrl isEqualToString:oldStartDirectoryMediaTabView]) {
  468. // Save Start Directory
  469. [[NCManageDatabase sharedInstance] setAccountStartDirectoryMediaTabView:serverUrl];
  470. // search PhotoVideo with new start directory
  471. [self searchPhotoVideo];
  472. }
  473. }
  474. /*
  475. if ([type isEqualToString:@"automaticUploadFolder"]) {
  476. if (title == nil) {
  477. [appDelegate messageNotification:@"_error_" description:@"_media_error_select_folder_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  478. return;
  479. }
  480. NSString *serverUrl = [NSURL URLWithString:serverUrlTo].URLByDeletingLastPathComponent.absoluteString;
  481. if ([[serverUrl substringFromIndex:[serverUrl length] - 1] isEqualToString:@"/"])
  482. serverUrl = [serverUrl substringToIndex:[serverUrl length] - 1];
  483. // Clear data (old) Auto Upload
  484. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:[[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl] directoryID:nil];
  485. // Settings new folder Automatatic upload
  486. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:title];
  487. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:serverUrl activeUrl:appDelegate.activeUrl];
  488. // Clear data new Auto Upload
  489. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
  490. }
  491. */
  492. }
  493. - (void)selectStartDirectoryPhotosTab
  494. {
  495. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  496. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  497. viewController.delegate = self;
  498. viewController.hideButtonCreateFolder = true;
  499. viewController.selectFile = false;
  500. viewController.includeDirectoryE2EEncryption = false;
  501. viewController.includeImages = false;
  502. viewController.type = @"mediaFolder";
  503. viewController.titleButtonDone = NSLocalizedString(@"_select_", nil);
  504. viewController.layoutViewSelect = k_layout_view_move;
  505. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  506. [self presentViewController:navigationController animated:YES completion:nil];
  507. }
  508. #pragma --------------------------------------------------------------------------------------------
  509. #pragma mark ==== Search Photo/Video ====
  510. #pragma --------------------------------------------------------------------------------------------
  511. - (void)searchSuccessFailure:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas message:(NSString *)message errorCode:(NSInteger)errorCode
  512. {
  513. isSearchMode = NO;
  514. if (![metadataNet.account isEqualToString:appDelegate.activeAccount] || errorCode != 0) {
  515. [self reloadDatasource:nil action:k_action_NULL];
  516. } else {
  517. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  518. // Clear all Hardcoded new foto/video from CCNetworking
  519. [self.addMetadatasFromUpload removeAllObjects];
  520. [[NCManageDatabase sharedInstance] createTablePhotos:metadatas account:appDelegate.activeAccount];
  521. dispatch_async(dispatch_get_main_queue(), ^{
  522. [self reloadDatasource:nil action:k_action_NULL];
  523. });
  524. // Update date
  525. [[NCManageDatabase sharedInstance] setAccountDateSearchContentTypeImageVideo:[NSDate date]];
  526. // Save etag
  527. [saveEtagForStartDirectory setObject:metadataNet.etag forKey:metadataNet.serverUrl];
  528. });
  529. }
  530. }
  531. - (void)searchPhotoVideo
  532. {
  533. // test
  534. if (appDelegate.activeAccount.length == 0 || isSearchMode)
  535. return;
  536. // WAITING FOR d:creationdate
  537. //
  538. // tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
  539. // account.dateSearchContentTypeImageVideo
  540. NSString *startDirectory = [[NCManageDatabase sharedInstance] getAccountStartDirectoryMediaTabView:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
  541. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  542. [ocNetworking readFile:nil serverUrl:startDirectory account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
  543. if (![metadata.etag isEqualToString:[saveEtagForStartDirectory objectForKey:startDirectory]] || sectionDataSource.allRecordsDataSource.count == 0) {
  544. isSearchMode = YES;
  545. [self editingModeNO];
  546. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  547. metadataNet.action = actionSearch;
  548. metadataNet.contentType = @[@"image/%", @"video/%"];
  549. metadataNet.date = [NSDate distantPast];
  550. metadataNet.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:startDirectory];
  551. metadataNet.fileName = @"";
  552. metadataNet.etag = metadata.etag;
  553. metadataNet.depth = @"infinity";
  554. metadataNet.priority = NSOperationQueuePriorityHigh;
  555. metadataNet.selector = selectorSearchContentType;
  556. metadataNet.serverUrl = startDirectory;
  557. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  558. } else {
  559. [self reloadDatasource:nil action:k_action_NULL];
  560. }
  561. } failure:^(NSString *message, NSInteger errorCode) {
  562. }];
  563. }
  564. #pragma --------------------------------------------------------------------------------------------
  565. #pragma mark ==== Datasource ====
  566. #pragma --------------------------------------------------------------------------------------------
  567. - (void)reloadDatasource:(NSString *)fileID action:(NSInteger)action
  568. {
  569. // test
  570. if (appDelegate.activeAccount.length == 0 || self.view.window == nil) {
  571. return;
  572. }
  573. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  574. collectionViewReloadDataInProgress = YES;
  575. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO];
  576. dispatch_async(dispatch_get_main_queue(), ^{
  577. if (isEditMode)
  578. [self setUINavigationBarSelected];
  579. else
  580. [self setUINavigationBarDefault];
  581. sectionDataSource = sectionDataSourceTemp;
  582. [self.collectionView reloadData];
  583. [self.collectionView performBatchUpdates:^{} completion:^(BOOL finished) {
  584. collectionViewReloadDataInProgress = NO;
  585. }];
  586. });
  587. });
  588. }
  589. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData
  590. {
  591. // test
  592. if (appDelegate.activeAccount.length == 0) {
  593. return nil;
  594. }
  595. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  596. NSArray *metadatas = [[NCManageDatabase sharedInstance] getTablePhotosWithAddMetadatasFromUpload:self.addMetadatasFromUpload account:appDelegate.activeAccount];
  597. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:@"date" filterFileID:appDelegate.filterFileID filterTypeFileImage:filterTypeFileImage filterTypeFileVideo:filterTypeFileVideo activeAccount:appDelegate.activeAccount];
  598. if (withReloadData) {
  599. sectionDataSource = sectionDataSourceTemp;
  600. [self.collectionView reloadData];
  601. }
  602. return sectionDataSourceTemp;
  603. }
  604. - (void)editingModeYES
  605. {
  606. [self.collectionView setAllowsMultipleSelection:true];
  607. isEditMode = true;
  608. [selectedMetadatas removeAllObjects];
  609. [self setUINavigationBarSelected];
  610. collectionViewReloadDataInProgress = YES;
  611. [self.collectionView reloadData];
  612. [self.collectionView performBatchUpdates:^{} completion:^(BOOL finished) {
  613. collectionViewReloadDataInProgress = NO;
  614. }];
  615. }
  616. - (void)editingModeNO
  617. {
  618. [self.collectionView setAllowsMultipleSelection:false];
  619. isEditMode = false;
  620. [selectedMetadatas removeAllObjects];
  621. [self setUINavigationBarDefault];
  622. collectionViewReloadDataInProgress = YES;
  623. [self.collectionView reloadData];
  624. [self.collectionView performBatchUpdates:^{} completion:^(BOOL finished) {
  625. collectionViewReloadDataInProgress = NO;
  626. }];
  627. }
  628. #pragma --------------------------------------------------------------------------------------------
  629. #pragma mark ==== Collection ====
  630. #pragma --------------------------------------------------------------------------------------------
  631. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  632. {
  633. return indexPath.section < [self numberOfSectionsInCollectionView:self.collectionView] && indexPath.row < [self collectionView:self.collectionView numberOfItemsInSection:indexPath.section];
  634. }
  635. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  636. {
  637. return [[sectionDataSource.sectionArrayRow allKeys] count];
  638. }
  639. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  640. {
  641. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  642. }
  643. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  644. {
  645. UIInterfaceOrientation orientationOnLunch = [[UIApplication sharedApplication] statusBarOrientation];
  646. if (orientationOnLunch == UIInterfaceOrientationPortrait)
  647. return CGSizeMake(collectionView.frame.size.width / 5.1f, collectionView.frame.size.width / 5.1f);
  648. else
  649. return CGSizeMake(collectionView.frame.size.width / 7.1f, collectionView.frame.size.width / 7.1f);
  650. }
  651. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  652. {
  653. if ([sectionDataSource.sections count] - 1 == section)
  654. return CGSizeMake(collectionView.frame.size.width, 50);
  655. return CGSizeZero;
  656. }
  657. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  658. {
  659. if (kind == UICollectionElementKindSectionHeader) {
  660. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
  661. //headerView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  662. [self getGeoLocationForSection:indexPath.section];
  663. UILabel *titleLabel = (UILabel *)[headerView viewWithTag:100];
  664. titleLabel.textColor = [UIColor blackColor];
  665. if (sectionDataSource.sections.count > indexPath.section)
  666. titleLabel.text = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:indexPath.section]];
  667. return headerView;
  668. }
  669. if (kind == UICollectionElementKindSectionFooter) {
  670. UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
  671. UILabel *titleLabel = (UILabel *)[footerView viewWithTag:100];
  672. titleLabel.textColor = [UIColor grayColor];
  673. titleLabel.text = [NSString stringWithFormat:@"%lu %@, %lu %@", (long)sectionDataSource.image, NSLocalizedString(@"photo", nil), (long)sectionDataSource.video, NSLocalizedString(@"_video_", nil)];
  674. return footerView;
  675. }
  676. return nil;
  677. }
  678. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  679. {
  680. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  681. UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
  682. UIVisualEffectView *effect = [cell viewWithTag:200];
  683. UIImageView *checkedOverlay = [cell viewWithTag:300];
  684. checkedOverlay.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"checkedYes"] multiplier:2 color:[NCBrandColor sharedInstance].brand];
  685. UIImageView *videoOverlay = [cell viewWithTag:400];
  686. videoOverlay.image = [UIImage imageNamed:@"VideoOverlay"];
  687. NSArray *metadatasForKey = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]];
  688. if ([metadatasForKey count] > indexPath.row) {
  689. NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
  690. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  691. // Image
  692. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
  693. // insert Image
  694. imageView.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  695. } else {
  696. imageView.image = [UIImage imageNamed:@"file_photo"];
  697. if (metadata.hasPreview == 1 && ![CCUtility fileProviderStorageIconExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  698. [self downloadThumbnail:metadata indexPath:indexPath];
  699. }
  700. }
  701. // Cheched Overlay
  702. if (cell.selected) {
  703. checkedOverlay.hidden = NO;
  704. effect.hidden = NO;
  705. effect.alpha = 0.4;
  706. } else {
  707. checkedOverlay.hidden = YES;
  708. effect.hidden = YES;
  709. }
  710. // Video Overlay
  711. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  712. videoOverlay.hidden = NO;
  713. } else {
  714. videoOverlay.hidden = YES;
  715. }
  716. }
  717. return cell;
  718. }
  719. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  720. {
  721. NSArray *metadatasForKey = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]];
  722. if ([metadatasForKey count] > indexPath.row) {
  723. NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
  724. self.metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  725. if (isEditMode) {
  726. [self cellSelect:YES indexPath:indexPath metadata:self.metadata];
  727. } else {
  728. if ([self shouldPerformSegue])
  729. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  730. }
  731. }
  732. }
  733. - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
  734. {
  735. // test
  736. if (isEditMode == NO)
  737. return;
  738. NSArray *metadatasForKey = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]];
  739. if ([metadatasForKey count] > indexPath.row) {
  740. NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
  741. self.metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  742. [self cellSelect:NO indexPath:indexPath metadata:self.metadata];
  743. }
  744. }
  745. #pragma --------------------------------------------------------------------------------------------
  746. #pragma mark ===== Navigation ====
  747. #pragma --------------------------------------------------------------------------------------------
  748. - (BOOL)shouldPerformSegue
  749. {
  750. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground)
  751. return NO;
  752. // Not in first plain ? exit
  753. if (self.view.window == NO)
  754. return NO;
  755. // Collapsed but in first plain in detail exit
  756. if (self.splitViewController.isCollapsed)
  757. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window)
  758. return NO;
  759. // check if metadata is invalidated
  760. if ([[NCManageDatabase sharedInstance] isTableInvalidated:self.metadata]) {
  761. return NO;
  762. }
  763. // ok perform segue
  764. return YES;
  765. }
  766. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  767. {
  768. id controller = segue.destinationViewController;
  769. if ([controller isKindOfClass:[UINavigationController class]]) {
  770. UINavigationController *navigationController = controller;
  771. self.detailViewController = (CCDetail *)navigationController.topViewController;
  772. } else {
  773. self.detailViewController = segue.destinationViewController;
  774. }
  775. NSMutableArray *photoDataSource = [NSMutableArray new];
  776. for (NSString *fileID in sectionDataSource.allFileID) {
  777. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  778. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  779. [photoDataSource addObject:metadata];
  780. }
  781. self.detailViewController.photoDataSource = photoDataSource;
  782. self.detailViewController.metadataDetail = self.metadata;
  783. self.detailViewController.dateFilterQuery = self.metadata.date;
  784. [self.detailViewController setTitle:self.metadata.fileName];
  785. }
  786. @end