CCMain.m 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927
  1. //
  2. // CCMain.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  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 "CCMain.h"
  24. #import "AppDelegate.h"
  25. #import "CCSynchronize.h"
  26. #import "OCActivity.h"
  27. #import "OCNotifications.h"
  28. #import "OCNotificationsAction.h"
  29. #import "OCFrameworkConstants.h"
  30. #import "OCCapabilities.h"
  31. #import "NCAutoUpload.h"
  32. #import "NCBridgeSwift.h"
  33. #import "NCNetworkingEndToEnd.h"
  34. #import "PKDownloadButton.h"
  35. @interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, NCSelectDelegate, UITextFieldDelegate, UIAdaptivePresentationControllerDelegate>
  36. {
  37. AppDelegate *appDelegate;
  38. BOOL _isRoot;
  39. BOOL _isViewDidLoad;
  40. NSMutableDictionary *_selectedocIdsMetadatas;
  41. UIImageView *_imageTitleHome;
  42. NSUInteger _failedAttempts;
  43. NSDate *_lockUntilDate;
  44. UIRefreshControl *refreshControl;
  45. CCHud *_hud;
  46. // Datasource
  47. CCSectionDataSourceMetadata *sectionDataSource;
  48. NSDate *_dateReadDataSource;
  49. // Search
  50. NSString *_searchFileName;
  51. NSMutableArray *_searchResultMetadatas;
  52. NSString *_noFilesSearchTitle;
  53. NSString *_noFilesSearchDescription;
  54. NSTimer *_timerWaitInput;
  55. // Automatic Upload Folder
  56. NSString *_autoUploadFileName;
  57. NSString *_autoUploadDirectory;
  58. // Folder
  59. BOOL _loadingFolder;
  60. tableMetadata *_metadataFolder;
  61. CGFloat heightRichWorkspace;
  62. CGFloat heightSearchBar;
  63. }
  64. @end
  65. @implementation CCMain
  66. #pragma --------------------------------------------------------------------------------------------
  67. #pragma mark ===== Init =====
  68. #pragma --------------------------------------------------------------------------------------------
  69. - (id)initWithCoder:(NSCoder *)aDecoder
  70. {
  71. if (self = [super initWithCoder:aDecoder]) {
  72. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  73. appDelegate.activeMain = self;
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:k_notificationCenter_initializeMain object:nil];
  75. }
  76. return self;
  77. }
  78. #pragma --------------------------------------------------------------------------------------------
  79. #pragma mark ===== View =====
  80. #pragma --------------------------------------------------------------------------------------------
  81. - (void)viewDidLoad
  82. {
  83. [super viewDidLoad];
  84. // init object
  85. self.metadata = [tableMetadata new];
  86. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  87. _selectedocIdsMetadatas = [NSMutableDictionary new];
  88. _isViewDidLoad = YES;
  89. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  90. _searchResultMetadatas = [NSMutableArray new];
  91. _searchFileName = @"";
  92. _noFilesSearchTitle = @"";
  93. _noFilesSearchDescription = @"";
  94. _cellFavouriteImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:[UIColor whiteColor]];
  95. _cellTrashImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor whiteColor]];
  96. // delegate
  97. self.tableView.tableFooterView = [UIView new];
  98. self.tableView.emptyDataSetDelegate = self;
  99. self.tableView.emptyDataSetSource = self;
  100. self.searchController.delegate = self;
  101. self.searchController.searchBar.delegate = self;
  102. // Notification
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:k_notificationCenter_clearDateReadDataSource object:nil];
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:k_notificationCenter_setTitleMain object:nil];
  105. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:k_notificationCenter_progressTask object:nil];
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteFile:) name:k_notificationCenter_deleteFile object:nil];
  107. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(favoriteFile:) name:k_notificationCenter_favoriteFile object:nil];
  108. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(renameFile:) name:k_notificationCenter_renameFile object:nil];
  109. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moveFile:) name:k_notificationCenter_moveFile object:nil];
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(copyFile:) name:k_notificationCenter_copyFile object:nil];
  111. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createFolder:) name:k_notificationCenter_createFolder object:nil];
  112. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  113. // Search
  114. self.definesPresentationContext = YES;
  115. self.searchController.searchResultsUpdater = self;
  116. self.searchController.dimsBackgroundDuringPresentation = NO;
  117. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  118. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  119. [searchButton setTitleColor:NCBrandColor.sharedInstance.brand forState:UIControlStateNormal];
  120. }
  121. UITextField *searchTextField = [self.searchController.searchBar valueForKey:@"searchField"];
  122. if (searchTextField && [searchTextField isKindOfClass:[UITextField class]]) {
  123. searchTextField.textColor = NCBrandColor.sharedInstance.textView;
  124. }
  125. // Load Rich Workspace
  126. self.viewRichWorkspace = [[[NSBundle mainBundle] loadNibNamed:@"NCRichWorkspace" owner:self options:nil] firstObject];
  127. UITapGestureRecognizer *viewRichWorkspaceTapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewRichWorkspaceTapAction:)];
  128. viewRichWorkspaceTapped.numberOfTapsRequired = 1;
  129. viewRichWorkspaceTapped.delegate = self;
  130. [self.viewRichWorkspace.richView addGestureRecognizer:viewRichWorkspaceTapped];
  131. self.sortButton = self.viewRichWorkspace.sortButton;
  132. heightSearchBar = self.viewRichWorkspace.topView.frame.size.height;
  133. [self.sortButton setTitleColor:NCBrandColor.sharedInstance.brand forState:UIControlStateNormal];
  134. [self.sortButton addTarget:self action:@selector(toggleReMainMenu) forControlEvents:UIControlEventTouchUpInside];
  135. heightRichWorkspace = UIScreen.mainScreen.bounds.size.height / 4 + heightSearchBar;
  136. [self.viewRichWorkspace setFrame:CGRectMake(0, 0, self.tableView.frame.size.width, heightRichWorkspace)];
  137. self.navigationItem.searchController = self.searchController;
  138. self.searchController.hidesNavigationBarDuringPresentation = true;
  139. self.navigationController.navigationBar.prefersLargeTitles = true;
  140. self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
  141. [self.navigationController.navigationBar sizeToFit];
  142. // Table Header View
  143. [self.tableView setTableHeaderView:self.viewRichWorkspace];
  144. // Register cell
  145. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  146. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  147. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0);
  148. // long press recognizer TableView
  149. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  150. [self.tableView addGestureRecognizer:longPressRecognizer];
  151. // Pull-to-Refresh
  152. [self createRefreshControl];
  153. // Register for 3D Touch Previewing if available
  154. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
  155. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  156. }
  157. // if this is not Main (the Main uses inizializeMain)
  158. if (_isRoot == NO && appDelegate.activeAccount.length > 0) {
  159. // Read (File) Folder
  160. [self readFileReloadFolder];
  161. }
  162. // Title
  163. [self setTitle];
  164. // changeTheming
  165. [self changeTheming];
  166. }
  167. - (void)willDismissSearchController:(UISearchController *)searchController
  168. {
  169. [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  170. }
  171. - (void)willPresentSearchController:(UISearchController *)searchController
  172. {
  173. [self updateNavBarShadow:self.tableView force:true];
  174. }
  175. - (void)viewWillAppear:(BOOL)animated
  176. {
  177. [super viewWillAppear:animated];
  178. [self updateNavBarShadow:self.tableView force:false];
  179. if(_isViewDidLoad && _isRoot) {
  180. self.navigationItem.hidesSearchBarWhenScrolling = false;
  181. [self.navigationController.navigationBar sizeToFit];
  182. }
  183. // test
  184. if (appDelegate.activeAccount.length == 0)
  185. return;
  186. if (_isSelectedMode)
  187. [self setUINavigationBarSelected];
  188. else
  189. [self setUINavigationBarDefault];
  190. // If not editing mode remove _selectedocIds
  191. if (!self.tableView.editing)
  192. [_selectedocIdsMetadatas removeAllObjects];
  193. // Check server URL "/"
  194. if (self.navigationController.viewControllers.firstObject == self && self.serverUrl == nil) {
  195. self.serverUrl = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  196. }
  197. // Query data source
  198. if (self.searchController.isActive == false) {
  199. [self queryDatasourceWithReloadData:YES serverUrl:self.serverUrl];
  200. }
  201. }
  202. - (void)viewDidAppear:(BOOL)animated
  203. {
  204. [super viewDidAppear:animated];
  205. if(_isViewDidLoad && _isRoot) {
  206. self.navigationItem.hidesSearchBarWhenScrolling = true;
  207. }
  208. // Active Main
  209. appDelegate.activeMain = self;
  210. // Test viewDidLoad
  211. if (_isViewDidLoad) {
  212. _isViewDidLoad = NO;
  213. } else {
  214. if (appDelegate.activeAccount.length > 0 && [_selectedocIdsMetadatas count] == 0) {
  215. // Read (file) Folder
  216. [self readFileReloadFolder];
  217. }
  218. }
  219. if (appDelegate.activeAccount.length > 0 && self.serverUrl != nil) {
  220. // Get Shares
  221. appDelegate.shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount serverUrl:self.serverUrl];
  222. // Get RichWorkspace
  223. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
  224. self.richWorkspaceText = directory.richWorkspace;
  225. }
  226. // Title
  227. [self setTitle];
  228. }
  229. - (void)viewWillDisappear:(BOOL)animated
  230. {
  231. [super viewWillDisappear:animated];
  232. }
  233. - (void) viewDidLayoutSubviews
  234. {
  235. [super viewDidLayoutSubviews];
  236. [self setTableViewHeader];
  237. }
  238. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  239. {
  240. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  241. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  242. [self setTableViewHeader];
  243. } completion:nil];
  244. }
  245. - (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
  246. {
  247. [self viewDidAppear:true];
  248. }
  249. - (BOOL)prefersStatusBarHidden
  250. {
  251. return NO;
  252. }
  253. // detect scroll for remove keyboard in search mode
  254. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  255. {
  256. if (self.searchController.isActive && scrollView == self.tableView) {
  257. [self.searchController.searchBar endEditing:YES];
  258. }
  259. }
  260. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  261. [self updateNavBarShadow:self.tableView force:false];
  262. }
  263. - (void)changeTheming
  264. {
  265. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:false];
  266. // createImagesThemingColor
  267. [[NCMainCommon sharedInstance] createImagesThemingColor];
  268. // Refresh control
  269. refreshControl.tintColor = UIColor.lightGrayColor;
  270. refreshControl.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  271. [self.sortButton setTitleColor:NCBrandColor.sharedInstance.brand forState:UIControlStateNormal];
  272. // color searchbar
  273. self.searchController.searchBar.tintColor = NCBrandColor.sharedInstance.brand;
  274. // color searchbbar button text (cancel)
  275. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  276. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  277. [searchButton setTitleColor:NCBrandColor.sharedInstance.brand forState:UIControlStateNormal];
  278. }
  279. // color textview searchbbar
  280. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  281. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  282. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  283. }
  284. // Rich Workspace
  285. [self.viewRichWorkspace loadWithRichWorkspaceText:self.richWorkspaceText];
  286. // Title
  287. [self setTitle];
  288. // Reload Table View
  289. [self tableViewReloadData];
  290. }
  291. #pragma --------------------------------------------------------------------------------------------
  292. #pragma mark ===== Initialization =====
  293. #pragma --------------------------------------------------------------------------------------------
  294. //
  295. // Callers :
  296. //
  297. // ChangeDefaultAccount (delegate)
  298. // Split : inizialize
  299. // Settings Advanced : removeAllFiles
  300. //
  301. - (void)initializeMain:(NSNotification *)notification
  302. {
  303. _dateReadDataSource = nil;
  304. // test
  305. if (appDelegate.activeAccount.length == 0)
  306. return;
  307. if ([appDelegate.listMainVC count] == 0 || _isRoot) {
  308. // This is Root home main add list
  309. appDelegate.homeMain = self;
  310. _isRoot = YES;
  311. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  312. [appDelegate.listMainVC setObject:self forKey:_serverUrl];
  313. // go Home
  314. [self.navigationController popToRootViewControllerAnimated:NO];
  315. // Remove search mode
  316. [self cancelSearchBar];
  317. // Clear error certificate
  318. [CCUtility setCertificateError:appDelegate.activeAccount error:NO];
  319. // Setting Theming
  320. [appDelegate settingThemingColorBrand];
  321. // Detail
  322. // If AVPlayer in play -> Stop
  323. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  324. [appDelegate.player pause];
  325. }
  326. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_menuDetailClose object:nil];
  327. // Not Photos Video in library ? then align and Init Auto Upload
  328. NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
  329. if ([recordsPhotoLibrary count] == 0) {
  330. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  331. }
  332. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  333. NSLog(@"[LOG] Request Service Server Nextcloud");
  334. [[NCService sharedInstance] startRequestServicesServer];
  335. // Clear datasorce
  336. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  337. // Read this folder
  338. [self readFileReloadFolder];
  339. } else {
  340. // reload datasource
  341. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  342. }
  343. // Registeration push notification
  344. [appDelegate pushNotification];
  345. // Registeration domain File Provider
  346. if (k_fileProvider_domain) {
  347. [FileProviderDomain.sharedInstance registerDomain];
  348. } else {
  349. [FileProviderDomain.sharedInstance removeAllDomain];
  350. }
  351. }
  352. #pragma --------------------------------------------------------------------------------------------
  353. #pragma mark ==== NotificationCenter ====
  354. #pragma --------------------------------------------------------------------------------------------
  355. - (void)deleteFile:(NSNotification *)notification
  356. {
  357. if (self.view.window == nil) { return; }
  358. NSDictionary *userInfo = notification.userInfo;
  359. tableMetadata *metadata = userInfo[@"metadata"];
  360. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  361. NSString *errorDescription = userInfo[@"errorDescription"];
  362. if (errorCode == 0 && metadata) {
  363. if ([metadata.serverUrl isEqualToString:self.serverUrl]) {
  364. if ([metadata.fileNameView.lowercaseString isEqualToString:k_fileNameRichWorkspace.lowercaseString]) {
  365. [self readFileReloadFolder];
  366. } else {
  367. if (self.searchController.isActive) {
  368. [self readFolder:self.serverUrl];
  369. } else {
  370. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  371. }
  372. }
  373. }
  374. } else {
  375. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  376. }
  377. }
  378. - (void)moveFile:(NSNotification *)notification
  379. {
  380. if (self.view.window == nil) { return; }
  381. NSDictionary *userInfo = notification.userInfo;
  382. tableMetadata *metadata = userInfo[@"metadata"];
  383. tableMetadata *metadataNew = userInfo[@"metadataNew"];
  384. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  385. NSString *errorDescription = userInfo[@"errorDescription"];
  386. if (errorCode == 0) {
  387. if ([metadata.serverUrl isEqualToString:self.serverUrl] || [metadataNew.serverUrl isEqualToString:self.serverUrl]) {
  388. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  389. }
  390. } else {
  391. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  392. }
  393. }
  394. - (void)copyFile:(NSNotification *)notification
  395. {
  396. if (self.view.window == nil) { return; }
  397. NSDictionary *userInfo = notification.userInfo;
  398. tableMetadata *metadata = userInfo[@"metadata"];
  399. NSString *serverUrlTo = userInfo[@"serverUrlTo"];
  400. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  401. NSString *errorDescription = userInfo[@"errorDescription"];
  402. if (errorCode == 0) {
  403. if ([metadata.serverUrl isEqualToString:self.serverUrl] || [serverUrlTo isEqualToString:self.serverUrl]) {
  404. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  405. }
  406. } else {
  407. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  408. }
  409. }
  410. - (void)favoriteFile:(NSNotification *)notification
  411. {
  412. if (self.view.window == nil) { return; }
  413. NSDictionary *userInfo = notification.userInfo;
  414. tableMetadata *metadata = userInfo[@"metadata"];
  415. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  416. NSString *errorDescription = userInfo[@"errorDescription"];
  417. BOOL favorite = [userInfo[@"favorite"] boolValue];
  418. if (errorCode == 0) {
  419. _dateReadDataSource = nil;
  420. if (self.searchController.isActive) {
  421. [self readFolder:self.serverUrl];
  422. } else {
  423. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  424. }
  425. if (metadata.directory && favorite) {
  426. NSString *selector;
  427. if ([CCUtility getFavoriteOffline])
  428. selector = selectorReadFolderWithDownload;
  429. else
  430. selector = selectorReadFolder;
  431. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName] selector:selector account:appDelegate.activeAccount];
  432. }
  433. if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
  434. metadata.favorite = favorite;
  435. metadata.session = k_download_session;
  436. metadata.sessionError = @"";
  437. metadata.sessionSelector = selectorDownloadSynchronize;
  438. metadata.status = k_metadataStatusWaitDownload;
  439. // Add Metadata for Download
  440. [[NCManageDatabase sharedInstance] addMetadata:metadata];
  441. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  442. [appDelegate startLoadAutoDownloadUpload];
  443. }
  444. } else {
  445. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  446. }
  447. }
  448. - (void)renameFile:(NSNotification *)notification {
  449. if (self.view.window == nil) { return; }
  450. NSDictionary *userInfo = notification.userInfo;
  451. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  452. NSString *errorDescription = userInfo[@"errorDescription"];
  453. if (errorCode == 0) {
  454. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  455. } else {
  456. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  457. }
  458. }
  459. - (void)createFolder:(NSNotification *)notification {
  460. if (self.view.window == nil) { return; }
  461. NSDictionary *userInfo = notification.userInfo;
  462. NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
  463. NSString *errorDescription = userInfo[@"errorDescription"];
  464. if (errorCode == 0) {
  465. [self reloadDatasource:self.serverUrl ocId:nil action:k_action_NULL];
  466. } else {
  467. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  468. }
  469. }
  470. #pragma --------------------------------------------------------------------------------------------
  471. #pragma mark ==== DZNEmptyDataSetSource ====
  472. #pragma --------------------------------------------------------------------------------------------
  473. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
  474. {
  475. if (_loadingFolder)
  476. return NO;
  477. else
  478. return YES;
  479. }
  480. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  481. {
  482. return NCBrandColor.sharedInstance.backgroundView;
  483. }
  484. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  485. {
  486. if (self.searchController.isActive)
  487. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"search"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  488. else
  489. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  490. }
  491. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
  492. {
  493. if (_loadingFolder && refreshControl.isRefreshing == NO) {
  494. UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  495. activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  496. activityView.color = NCBrandColor.sharedInstance.brandElement;
  497. [activityView startAnimating];
  498. return activityView;
  499. }
  500. return nil;
  501. }
  502. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  503. {
  504. NSString *text;
  505. if (self.searchController.isActive) {
  506. text = _noFilesSearchTitle;
  507. } else {
  508. text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
  509. }
  510. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  511. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  512. }
  513. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  514. {
  515. NSString *text;
  516. if (self.searchController.isActive) {
  517. text = _noFilesSearchDescription;
  518. } else {
  519. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
  520. }
  521. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  522. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  523. paragraph.alignment = NSTextAlignmentCenter;
  524. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  525. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  526. }
  527. #pragma --------------------------------------------------------------------------------------------
  528. #pragma mark ===== Text Field =====
  529. #pragma --------------------------------------------------------------------------------------------
  530. - (void)minCharTextFieldDidChange:(UITextField *)sender
  531. {
  532. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  533. if (alertController)
  534. {
  535. UITextField *fileName = alertController.textFields.firstObject;
  536. UIAlertAction *okAction = alertController.actions.lastObject;
  537. okAction.enabled = fileName.text.length > 0;
  538. }
  539. }
  540. - (void)textFieldDidBeginEditing:(UITextField *)textField
  541. {
  542. [CCUtility selectFileNameFrom:textField];
  543. }
  544. #pragma --------------------------------------------------------------------------------------------
  545. #pragma mark ===== Graphic Window =====
  546. #pragma --------------------------------------------------------------------------------------------
  547. - (void)createRefreshControl
  548. {
  549. refreshControl = [NCMainRefreshControl new];
  550. self.tableView.refreshControl = refreshControl;
  551. refreshControl.tintColor = UIColor.lightGrayColor;
  552. refreshControl.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  553. [refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
  554. }
  555. - (void)deleteRefreshControl
  556. {
  557. [refreshControl endRefreshing];
  558. [refreshControl removeFromSuperview];
  559. refreshControl = nil;
  560. }
  561. - (void)refreshControlTarget
  562. {
  563. [self readFolder:_serverUrl];
  564. // Actuate `Peek` feedback (weak boom)
  565. AudioServicesPlaySystemSound(1519);
  566. }
  567. - (void)setTitle
  568. {
  569. if (_isSelectedMode) {
  570. NSUInteger totali = [sectionDataSource.allRecordsDataSource count];
  571. NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
  572. self.navigationItem.titleView = nil;
  573. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
  574. } else {
  575. if (_isRoot) {
  576. self.navigationItem.title = NCBrandOptions.sharedInstance.brand;
  577. } else {
  578. self.navigationItem.title = _titleMain;
  579. }
  580. }
  581. [self SetSortButtonText];
  582. }
  583. - (void)setUINavigationBarDefault
  584. {
  585. UIBarButtonItem *buttonSelect = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_select_", @"") style:UIBarButtonItemStylePlain target:self action:@selector(tableViewToggle)];
  586. self.navigationController.navigationBar.hidden = NO;
  587. self.navigationItem.rightBarButtonItem = buttonSelect;
  588. self.navigationItem.leftBarButtonItem = nil;
  589. }
  590. - (void)setUINavigationBarSelected
  591. {
  592. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationMore"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
  593. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
  594. self.navigationItem.leftBarButtonItem = leftButton;
  595. self.navigationItem.rightBarButtonItem = buttonMore; //[[NSArray alloc] initWithObjects:buttonMore, nil];
  596. }
  597. - (void)cancelSelect
  598. {
  599. [self tableViewSelect:false];
  600. }
  601. #pragma --------------------------------------------------------------------------------------------
  602. #pragma mark ===== Document Picker =====
  603. #pragma --------------------------------------------------------------------------------------------
  604. - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
  605. {
  606. NSLog(@"[LOG] Cancelled");
  607. }
  608. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
  609. {
  610. NSLog(@"[LOG] Cancelled");
  611. }
  612. - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
  613. {
  614. documentPicker.delegate = self;
  615. [self presentViewController:documentPicker animated:YES completion:nil];
  616. }
  617. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
  618. {
  619. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  620. NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
  621. __block NSError *error;
  622. [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
  623. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  624. NSString *fileName = [url lastPathComponent];
  625. NSString *ocId = [[NSUUID UUID] UUIDString];
  626. NSData *data = [NSData dataWithContentsOfURL:newURL];
  627. if (data && error == nil) {
  628. if ([data writeToFile:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
  629. tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:ocId serverUrl:serverUrl url:@"" contentType:@""];
  630. metadataForUpload.session = k_upload_session;
  631. metadataForUpload.sessionSelector = selectorUploadFile;
  632. metadataForUpload.size = data.length;
  633. metadataForUpload.status = k_metadataStatusWaitUpload;
  634. if ([[NCUtility sharedInstance] getMetadataConflictWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileName] != nil) {
  635. NCCreateFormUploadConflict *conflict = [[UIStoryboard storyboardWithName:@"NCCreateFormUploadConflict" bundle:nil] instantiateInitialViewController];
  636. conflict.serverUrl = self.serverUrl;
  637. conflict.metadatasUploadInConflict = @[metadataForUpload];
  638. [self presentViewController:conflict animated:YES completion:nil];
  639. } else {
  640. [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  641. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  642. [appDelegate startLoadAutoDownloadUpload];
  643. }
  644. } else {
  645. [[NCContentPresenter shared] messageNotification:@"_error_" description:error.description delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  646. }
  647. } else {
  648. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_read_file_error_" delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  649. }
  650. }];
  651. }
  652. }
  653. - (void)openImportDocumentPicker
  654. {
  655. UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
  656. documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
  657. documentProviderMenu.popoverPresentationController.sourceView = self.tabBarController.tabBar;
  658. documentProviderMenu.popoverPresentationController.sourceRect = self.tabBarController.tabBar.bounds;
  659. documentProviderMenu.delegate = self;
  660. [self presentViewController:documentProviderMenu animated:YES completion:nil];
  661. }
  662. #pragma --------------------------------------------------------------------------------------------
  663. #pragma mark ===== Assets Picker =====
  664. #pragma --------------------------------------------------------------------------------------------
  665. -(void)dismissFormUploadAssets
  666. {
  667. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  668. }
  669. - (void)openAssetsPickerController
  670. {
  671. NCPhotosPickerViewController *viewController = [[NCPhotosPickerViewController alloc] init:self maxSelectedAssets:100 singleSelectedMode:false];
  672. [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nullable assets, NSArray<NSURL *> * urls) {
  673. if (assets.count > 0) {
  674. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  675. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  676. NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets urls:(NSMutableArray *)urls cryptated:NO session:k_upload_session delegate:self];
  677. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
  678. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  679. [self presentViewController:navigationController animated:YES completion:nil];
  680. });
  681. }
  682. }];
  683. }
  684. #pragma --------------------------------------------------------------------------------------------
  685. #pragma mark ===== Save selected File =====
  686. #pragma --------------------------------------------------------------------------------------------
  687. - (void)saveToPhotoAlbum:(tableMetadata *)metadata
  688. {
  689. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
  690. PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
  691. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
  692. UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
  693. if (image)
  694. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  695. else
  696. [[NCContentPresenter shared] messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  697. }
  698. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
  699. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
  700. UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  701. } else {
  702. [[NCContentPresenter shared] messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  703. }
  704. }
  705. if (status != PHAuthorizationStatusAuthorized) {
  706. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  707. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  708. [alertController addAction:okAction];
  709. [self presentViewController:alertController animated:YES completion:nil];
  710. }
  711. }
  712. - (void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  713. {
  714. if (error) {
  715. [[NCContentPresenter shared] messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  716. }
  717. }
  718. - (void)saveSelectedFiles
  719. {
  720. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  721. return;
  722. NSLog(@"[LOG] Start download selected files ...");
  723. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  724. NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  725. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  726. for (tableMetadata *metadata in metadatas) {
  727. if (metadata.directory == NO && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
  728. metadata.session = k_download_session;
  729. metadata.sessionError = @"";
  730. metadata.sessionSelector = selectorSave;
  731. metadata.status = k_metadataStatusWaitDownload;
  732. // Add Metadata for Download
  733. [[NCManageDatabase sharedInstance] addMetadata:metadata];
  734. [appDelegate startLoadAutoDownloadUpload];
  735. }
  736. }
  737. [_hud hideHud];
  738. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  739. });
  740. [self tableViewSelect:false];
  741. }
  742. #pragma mark -
  743. #pragma --------------------------------------------------------------------------------------------
  744. #pragma mark ===== Peek & Pop =====
  745. #pragma --------------------------------------------------------------------------------------------
  746. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  747. {
  748. CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];
  749. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
  750. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  751. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  752. if (cell) {
  753. previewingContext.sourceRect = cell.frame;
  754. CCPeekPop *viewController = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  755. viewController.metadata = metadata;
  756. viewController.imageFile = cell.file.image;
  757. viewController.showOpenIn = true;
  758. viewController.showShare = true;
  759. viewController.showOpenQuickLook = [[NCUtility sharedInstance] isQuickLookDisplayableWithMetadata:metadata];
  760. return viewController;
  761. }
  762. return nil;
  763. }
  764. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  765. {
  766. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  767. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  768. }
  769. #pragma --------------------------------------------------------------------------------------------
  770. #pragma mark ==== Download ====
  771. #pragma --------------------------------------------------------------------------------------------
  772. - (void)downloadSelectedFilesFolders
  773. {
  774. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  775. return;
  776. NSLog(@"[LOG] Start download selected ...");
  777. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  778. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  779. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  780. for (tableMetadata *metadata in selectedMetadatas) {
  781. if (metadata.directory) {
  782. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  783. } else {
  784. [[CCSynchronize sharedSynchronize] readFile:metadata.ocId fileName:metadata.fileName serverUrl:metadata.serverUrl selector:selectorReadFileWithDownload account:appDelegate.activeAccount];
  785. }
  786. }
  787. [_hud hideHud];
  788. });
  789. [self tableViewSelect:false];
  790. }
  791. #pragma --------------------------------------------------------------------------------------------
  792. #pragma mark ===== Upload new Photos/Videos =====
  793. #pragma --------------------------------------------------------------------------------------------
  794. //
  795. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  796. //
  797. - (void)uploadFileAsset:(NSMutableArray *)assets urls:(NSMutableArray *)urls serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  798. {
  799. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  800. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
  801. // if request create the folder for Auto Upload & the subfolders
  802. if ([autoUploadPath isEqualToString:serverUrl])
  803. if (![[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
  804. return;
  805. dispatch_async(dispatch_get_main_queue(), ^{
  806. [self uploadFileAsset:assets urls:urls serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
  807. });
  808. });
  809. }
  810. - (void)uploadFileAsset:(NSArray *)assets urls:(NSArray *)urls serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  811. {
  812. NSMutableArray *metadatasNOConflict = [NSMutableArray new];
  813. NSMutableArray *metadatasMOV = [NSMutableArray new];
  814. NSMutableArray *metadatasUploadInConflict = [NSMutableArray new];
  815. for (PHAsset *asset in assets) {
  816. NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType keyFileNameOriginal:k_keyFileNameOriginal];
  817. NSDate *assetDate = asset.creationDate;
  818. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  819. // Create serverUrl if use sub folder
  820. if (useSubFolder) {
  821. [formatter setDateFormat:@"yyyy"];
  822. NSString *yearString = [formatter stringFromDate:assetDate];
  823. [formatter setDateFormat:@"MM"];
  824. NSString *monthString = [formatter stringFromDate:assetDate];
  825. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
  826. }
  827. // Check if is in upload
  828. NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", appDelegate.activeAccount, serverUrl, fileName] sorted:nil ascending:NO];
  829. if ([isRecordInSessions count] > 0)
  830. continue;
  831. // Prepare record metadata
  832. tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrl url:@"" contentType:@""];
  833. metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
  834. metadataForUpload.session = session;
  835. metadataForUpload.sessionSelector = selectorUploadFile;
  836. metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
  837. metadataForUpload.status = k_metadataStatusWaitUpload;
  838. if ([[NCUtility sharedInstance] getMetadataConflictWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileName] != nil) {
  839. [metadatasUploadInConflict addObject:metadataForUpload];
  840. } else {
  841. [metadatasNOConflict addObject:metadataForUpload];
  842. }
  843. // Add Medtadata MOV LIVE PHOTO for upload
  844. if ((asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive+PHAssetMediaSubtypePhotoHDR) && CCUtility.getLivePhoto && urls.count == assets.count) {
  845. NSUInteger index = [assets indexOfObject:asset];
  846. NSURL *url = [urls objectAtIndex:index];
  847. NSString *fileNameNoExt = [fileName stringByDeletingPathExtension];
  848. NSString *fileName = [NSString stringWithFormat:@"%@.mov", fileNameNoExt];
  849. unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
  850. tableMetadata *metadataMOVForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrl url:@"" contentType:@""];
  851. metadataMOVForUpload.session = session;
  852. metadataMOVForUpload.sessionSelector = selectorUploadFile;
  853. metadataMOVForUpload.size = fileSize;
  854. metadataMOVForUpload.status = k_metadataStatusWaitUpload;
  855. // Prepare file and directory
  856. [CCUtility moveFileAtPath:url.path toPath:[CCUtility getDirectoryProviderStorageOcId:metadataMOVForUpload.ocId fileNameView:fileName]];
  857. [metadatasMOV addObject:metadataMOVForUpload];
  858. }
  859. }
  860. // Verify if file(s) exists
  861. if (metadatasUploadInConflict.count > 0) {
  862. NCCreateFormUploadConflict *conflict = [[UIStoryboard storyboardWithName:@"NCCreateFormUploadConflict" bundle:nil] instantiateInitialViewController];
  863. conflict.serverUrl = self.serverUrl;
  864. conflict.metadatasNOConflict = metadatasNOConflict;
  865. conflict.metadatasMOV = metadatasMOV;
  866. conflict.metadatasUploadInConflict = metadatasUploadInConflict;
  867. [self presentViewController:conflict animated:YES completion:nil];
  868. } else {
  869. [[NCManageDatabase sharedInstance] addMetadatas:metadatasNOConflict];
  870. [[NCManageDatabase sharedInstance] addMetadatas:metadatasMOV];
  871. [appDelegate startLoadAutoDownloadUpload];
  872. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  873. }
  874. }
  875. #pragma --------------------------------------------------------------------------------------------
  876. #pragma mark ==== Read Folder ====
  877. #pragma --------------------------------------------------------------------------------------------
  878. - (void)readFolder:(NSString *)serverUrl
  879. {
  880. // init control
  881. if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
  882. [refreshControl endRefreshing];
  883. return;
  884. }
  885. // Search Mode
  886. if (self.searchController.isActive) {
  887. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  888. _searchFileName = @""; // forced reload searchg
  889. [self updateSearchResultsForSearchController:self.searchController];
  890. return;
  891. }
  892. _loadingFolder = YES;
  893. [refreshControl endRefreshing];
  894. [self tableViewReloadData];
  895. [[NCNetworking sharedInstance] readFolderWithServerUrl:serverUrl account:appDelegate.activeAccount completion:^(NSString *account, tableMetadata *metadataFolder, NSArray *metadatas, NSInteger errorCode, NSString *errorDescription) {
  896. if (errorCode == 0 ) {
  897. _metadataFolder = metadataFolder;
  898. BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:serverUrl e2eEncrypted:_metadataFolder.e2eEncrypted account:appDelegate.activeAccount];
  899. [self setTitle];
  900. // File is changed ??
  901. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  902. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatas serverUrl:serverUrl account:account withDownload:NO];
  903. });
  904. // E2EE Is encrypted folder get metadata
  905. if (isFolderEncrypted) {
  906. if ([CCUtility isEndToEndEnabled:account]) {
  907. [[NCCommunication shared] getE2EEMetadataWithFileId:metadataFolder.fileId e2eToken:nil customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSString *e2eeMetadata, NSInteger errorCode, NSString *errorDescription) {
  908. if (errorCode == 0 && e2eeMetadata != nil) {
  909. BOOL result = [[NCEndToEndMetadata sharedInstance] decoderMetadata:e2eeMetadata privateKey:[CCUtility getEndToEndPrivateKey:account] serverUrl:self.serverUrl account:account url:appDelegate.activeUrl];
  910. if (result == false) {
  911. [[NCContentPresenter shared] messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" delay:k_dismissAfterSecond type:messageTypeError errorCode:-999];
  912. }
  913. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  914. } else if (errorCode != kOCErrorServerPathNotFound) {
  915. [[NCContentPresenter shared] messageNotification:@"_e2e_error_get_metadata_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  916. }
  917. }];
  918. } else {
  919. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  920. }
  921. }
  922. if ([serverUrl isEqualToString:_serverUrl]) {
  923. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  924. }
  925. } else {
  926. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  927. }
  928. _loadingFolder = NO;
  929. }];
  930. }
  931. - (void)readFileReloadFolder
  932. {
  933. if (!_serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode)
  934. return;
  935. // RichWorkspace
  936. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
  937. self.richWorkspaceText = directory.richWorkspace;
  938. [self setTableViewHeader];
  939. // Load Datasource
  940. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  941. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  942. });
  943. [[NCNetworking sharedInstance] readFileWithServerUrlFileName:self.serverUrl account:appDelegate.activeAccount completion:^(NSString *account, tableMetadata *metadata, NSInteger errorCode, NSString *errorDescription) {
  944. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  945. // Rich Workspace
  946. [[NCManageDatabase sharedInstance] setDirectoryWithOcId:metadata.ocId serverUrl:self.serverUrl richWorkspace:metadata.richWorkspace account:account];
  947. self.richWorkspaceText = metadata.richWorkspace;
  948. [self setTableViewHeader];
  949. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, self.serverUrl]];
  950. // Read folder: No record, Change etag or BLINK
  951. if ([sectionDataSource.allRecordsDataSource count] == 0 || [metadata.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
  952. [self readFolder:self.serverUrl];
  953. }
  954. } else if (errorCode != 0) {
  955. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  956. }
  957. }];
  958. }
  959. #pragma mark -
  960. #pragma --------------------------------------------------------------------------------------------
  961. #pragma mark ===== Search =====
  962. #pragma --------------------------------------------------------------------------------------------
  963. - (void)searchStartTimer
  964. {
  965. if (self.searchController.isActive == false) {
  966. return;
  967. }
  968. [[NCCommunication shared] searchLiteralWithServerUrl:appDelegate.activeUrl depth:@"infinity" literal:_searchFileName showHiddenFiles:[CCUtility getShowHiddenFiles] customUserAgent:nil addCustomHeaders:nil user:appDelegate.activeUser completionHandler:^(NSString *account, NSArray *files, NSInteger errorCode, NSString *errorDescription) {
  969. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount] && files != nil) {
  970. [[NCManageDatabase sharedInstance] convertNCCommunicationFilesToMetadatas:files useMetadataFolder:false account:account completion:^(tableMetadata *metadataFolder, NSArray<tableMetadata *> *metadatasFolder, NSArray<tableMetadata *> *metadatas) {
  971. NSMutableArray *metadatasDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas];
  972. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasDB];
  973. _metadataFolder = nil;
  974. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  975. [self tableViewReloadData];
  976. [self setTitle];
  977. }];
  978. } else {
  979. if (errorCode != 0) {
  980. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  981. }
  982. _searchFileName = @"";
  983. }
  984. }];
  985. _noFilesSearchTitle = @"";
  986. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  987. [self.tableView reloadEmptyDataSet];
  988. }
  989. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  990. {
  991. // Color text "Cancel"
  992. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:NCBrandColor.sharedInstance.brand];
  993. if (searchController.isActive) {
  994. [self deleteRefreshControl];
  995. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  996. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  997. _searchFileName = fileName;
  998. _metadataFolder = nil;
  999. // First : filter
  1000. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView CONTAINS[cd] %@", appDelegate.activeAccount, _serverUrl, fileName] sorted:nil ascending:NO];
  1001. [_searchResultMetadatas removeAllObjects];
  1002. for (tableMetadata *record in records) {
  1003. [_searchResultMetadatas addObject:record];
  1004. }
  1005. // Version >= 12
  1006. NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesVersionMajor];
  1007. if (serverVersionMajor >= 12) {
  1008. [_timerWaitInput invalidate];
  1009. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1010. }
  1011. [self setTitle];
  1012. }
  1013. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1014. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1015. }
  1016. } else {
  1017. [self createRefreshControl];
  1018. [self reloadDatasource:self.serverUrl ocId:nil action:k_action_NULL];
  1019. }
  1020. }
  1021. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1022. {
  1023. [self cancelSearchBar];
  1024. }
  1025. - (void)cancelSearchBar
  1026. {
  1027. if (self.searchController.active) {
  1028. [self.searchController setActive:NO];
  1029. _searchFileName = @"";
  1030. _dateReadDataSource = nil;
  1031. _searchResultMetadatas = [NSMutableArray new];
  1032. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1033. }
  1034. }
  1035. #pragma mark -
  1036. #pragma --------------------------------------------------------------------------------------------
  1037. #pragma mark ===== Delete File or Folder =====
  1038. #pragma --------------------------------------------------------------------------------------------
  1039. - (void)deleteMetadatas
  1040. {
  1041. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1042. return;
  1043. if ([_selectedocIdsMetadatas count] > 0) {
  1044. [appDelegate.arrayDeleteMetadata addObjectsFromArray:[_selectedocIdsMetadatas allValues]];
  1045. } else {
  1046. [appDelegate.arrayDeleteMetadata addObject:self.metadata];
  1047. }
  1048. [[NCNetworking sharedInstance] deleteMetadata:appDelegate.arrayDeleteMetadata.firstObject account:appDelegate.activeAccount url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
  1049. [appDelegate.arrayDeleteMetadata removeObjectAtIndex:0];
  1050. // End Select Table View
  1051. [self tableViewSelect:false];
  1052. }
  1053. #pragma --------------------------------------------------------------------------------------------
  1054. #pragma mark ===== Move / Copy =====
  1055. #pragma --------------------------------------------------------------------------------------------
  1056. - (void)moveCopyFileOrFolderMetadata:(tableMetadata *)metadata serverUrlTo:(NSString *)serverUrlTo move:(BOOL)move overwrite:(BOOL)overwrite
  1057. {
  1058. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1059. return;
  1060. NSMutableArray *arrayMetadata, *arrayServerUrlTo;
  1061. if (move) {
  1062. arrayMetadata = appDelegate.arrayMoveMetadata;
  1063. arrayServerUrlTo = appDelegate.arrayMoveServerUrlTo;
  1064. } else {
  1065. arrayMetadata = appDelegate.arrayCopyMetadata;
  1066. arrayServerUrlTo = appDelegate.arrayCopyServerUrlTo;
  1067. }
  1068. if ([_selectedocIdsMetadatas count] > 0) {
  1069. for (NSString *key in _selectedocIdsMetadatas) {
  1070. tableMetadata *metadata = [_selectedocIdsMetadatas objectForKey:key];
  1071. [arrayMetadata addObject:metadata];
  1072. [arrayServerUrlTo addObject:serverUrlTo];
  1073. }
  1074. } else {
  1075. [arrayMetadata addObject:metadata];
  1076. [arrayServerUrlTo addObject:serverUrlTo];
  1077. }
  1078. if (move) {
  1079. [[NCNetworking sharedInstance] moveMetadata:arrayMetadata.firstObject serverUrlTo:arrayServerUrlTo.firstObject overwrite:overwrite completion:^(NSInteger errorCode, NSString * errorDesctiption) { }];
  1080. } else {
  1081. [[NCNetworking sharedInstance] copyMetadata:arrayMetadata.firstObject serverUrlTo:arrayServerUrlTo.firstObject overwrite:overwrite completion:^(NSInteger errorCode, NSString * errorDesctiption) { }];
  1082. }
  1083. [arrayMetadata removeObjectAtIndex:0];
  1084. [arrayServerUrlTo removeObjectAtIndex:0];
  1085. // End Select Table View
  1086. [self tableViewSelect:false];
  1087. }
  1088. // DELEGATE : Select
  1089. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type buttonType:(NSString *)buttonType overwrite:(BOOL)overwrite
  1090. {
  1091. if (serverUrl == nil) {
  1092. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1093. } else {
  1094. // E2EE DENIED
  1095. if ([CCUtility isFolderEncrypted:serverUrl e2eEncrypted:metadata.e2eEncrypted account:appDelegate.activeAccount]) {
  1096. [[NCContentPresenter shared] messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  1097. return;
  1098. }
  1099. BOOL move = true;
  1100. if ([buttonType isEqualToString:@"done1"]) { move = false; }
  1101. if ([_selectedocIdsMetadatas count] > 0) {
  1102. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1103. [self moveCopyFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrl move:move overwrite:overwrite];
  1104. } else {
  1105. [self moveCopyFileOrFolderMetadata:self.metadata serverUrlTo:serverUrl move:move overwrite:overwrite];
  1106. }
  1107. }
  1108. }
  1109. - (void)moveOpenWindow:(NSArray *)indexPaths
  1110. {
  1111. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1112. return;
  1113. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  1114. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  1115. viewController.delegate = self;
  1116. viewController.hideButtonCreateFolder = false;
  1117. viewController.selectFile = false;
  1118. viewController.includeDirectoryE2EEncryption = false;
  1119. viewController.includeImages = false;
  1120. viewController.type = @"";
  1121. viewController.titleButtonDone = NSLocalizedString(@"_move_", nil);
  1122. viewController.titleButtonDone1 = NSLocalizedString(@"_copy_", nil);
  1123. viewController.isButtonDone1Hide = false;
  1124. viewController.isOverwriteHide = false;
  1125. viewController.layoutViewSelect = k_layout_view_move;
  1126. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  1127. [self presentViewController:navigationController animated:YES completion:nil];
  1128. }
  1129. #pragma --------------------------------------------------------------------------------------------
  1130. #pragma mark ===== Create folder =====
  1131. #pragma --------------------------------------------------------------------------------------------
  1132. - (void)createFolder
  1133. {
  1134. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  1135. NSString *message;
  1136. UIAlertController *alertController;
  1137. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  1138. message = @"/";
  1139. } else {
  1140. message = [serverUrl lastPathComponent];
  1141. }
  1142. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  1143. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1144. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  1145. textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
  1146. }];
  1147. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1148. NSLog(@"[LOG] Cancel action");
  1149. }];
  1150. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1151. UITextField *fileName = alertController.textFields.firstObject;
  1152. [[NCNetworking sharedInstance] createFolderWithFileName:fileName.text serverUrl:serverUrl account:appDelegate.activeAccount url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
  1153. }];
  1154. okAction.enabled = NO;
  1155. [alertController addAction:cancelAction];
  1156. [alertController addAction:okAction];
  1157. [self presentViewController:alertController animated:YES completion:nil];
  1158. }
  1159. #pragma --------------------------------------------------------------------------------------------
  1160. #pragma mark ===== Progress & Task Button =====
  1161. #pragma --------------------------------------------------------------------------------------------
  1162. - (void)triggerProgressTask:(NSNotification *)notification
  1163. {
  1164. if (sectionDataSource.ocIdIndexPath != nil) {
  1165. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
  1166. }
  1167. }
  1168. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1169. {
  1170. UITouch *touch = [[event allTouches] anyObject];
  1171. CGPoint location = [touch locationInView:self.tableView];
  1172. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1173. if ([self indexPathIsValid:indexPath]) {
  1174. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1175. if (metadataSection) {
  1176. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataSection.ocId]];
  1177. if (metadata)
  1178. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  1179. }
  1180. }
  1181. }
  1182. - (void)cancelAllTask:(id)sender
  1183. {
  1184. CGPoint location = [sender locationInView:self.tableView];
  1185. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1186. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1187. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1188. [NCUtility.sharedInstance startActivityIndicatorWithView:self.view bottom:0];
  1189. [[NCMainCommon sharedInstance] cancelAllTransfer];
  1190. [NCUtility.sharedInstance stopActivityIndicator];
  1191. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:nil ocId:nil action:k_action_NULL];
  1192. }]];
  1193. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  1194. alertController.popoverPresentationController.sourceView = self.tableView;
  1195. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1196. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1197. [alertController.view layoutIfNeeded];
  1198. [self presentViewController:alertController animated:YES completion:nil];
  1199. }
  1200. #pragma --------------------------------------------------------------------------------------------
  1201. #pragma mark ===== Tap =====
  1202. #pragma --------------------------------------------------------------------------------------------
  1203. - (void)tapActionComment:(UITapGestureRecognizer *)tapGesture
  1204. {
  1205. CGPoint location = [tapGesture locationInView:self.tableView];
  1206. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1207. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1208. if (metadata && ![CCUtility isFolderEncrypted:self.serverUrl e2eEncrypted:metadata.e2eEncrypted account:appDelegate.activeAccount]) {
  1209. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:1];
  1210. }
  1211. }
  1212. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  1213. {
  1214. CGPoint location = [tapGesture locationInView:self.tableView];
  1215. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1216. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1217. if (metadata && ![CCUtility isFolderEncrypted:self.serverUrl e2eEncrypted:metadata.e2eEncrypted account:appDelegate.activeAccount]) {
  1218. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  1219. }
  1220. }
  1221. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  1222. {
  1223. CGPoint location = [tapGesture locationInView:self.tableView];
  1224. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1225. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1226. if (metadata) {
  1227. }
  1228. }
  1229. #pragma --------------------------------------------------------------------------------------------
  1230. #pragma mark ===== Rich Workspace =====
  1231. #pragma --------------------------------------------------------------------------------------------
  1232. - (void)viewRichWorkspaceTapAction:(UITapGestureRecognizer *)tapGesture
  1233. {
  1234. [UIView animateWithDuration:0.5 animations:^{
  1235. [self.tableView setContentOffset:CGPointMake(0, heightSearchBar)];
  1236. } completion:^(BOOL finished) {
  1237. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCViewerRichWorkspace" bundle:nil] instantiateInitialViewController];
  1238. NCViewerRichWorkspace *viewerRichWorkspace = (NCViewerRichWorkspace *)[navigationController topViewController];
  1239. viewerRichWorkspace.richWorkspaceText = self.richWorkspaceText;
  1240. viewerRichWorkspace.serverUrl = self.serverUrl;
  1241. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  1242. [self presentViewController:navigationController animated:NO completion:NULL];
  1243. }];
  1244. }
  1245. - (void)createRichWorkspace
  1246. {
  1247. NCRichWorkspaceCommon *richWorkspaceCommon = [NCRichWorkspaceCommon new];
  1248. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, self.serverUrl, k_fileNameRichWorkspace.lowercaseString]];
  1249. if (metadata) {
  1250. [richWorkspaceCommon openViewerNextcloudTextWithServerUrl:self.serverUrl viewController:self];
  1251. } else {
  1252. [richWorkspaceCommon createViewerNextcloudTextWithServerUrl:self.serverUrl viewController:self];
  1253. }
  1254. }
  1255. #pragma --------------------------------------------------------------------------------------------
  1256. #pragma mark ==== Menu LOGO ====
  1257. #pragma --------------------------------------------------------------------------------------------
  1258. - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
  1259. {
  1260. // Brand
  1261. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  1262. return;
  1263. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  1264. NSMutableArray *menuArray = [NSMutableArray new];
  1265. for (NSString *account in listAccount) {
  1266. CCMenuItem *item = [[CCMenuItem alloc] init];
  1267. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  1268. item.argument = account;
  1269. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
  1270. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
  1271. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  1272. if (avatar) {
  1273. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
  1274. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  1275. CGSize imageSize = avatarImageView.bounds.size;
  1276. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1277. CGContextRef context = UIGraphicsGetCurrentContext();
  1278. [avatarImageView.layer renderInContext:context];
  1279. avatar = UIGraphicsGetImageFromCurrentImageContext();
  1280. UIGraphicsEndImageContext();
  1281. } else {
  1282. avatar = [UIImage imageNamed:@"menuLogoUser"];
  1283. }
  1284. item.image = avatar;
  1285. item.target = self;
  1286. if ([account isEqualToString:appDelegate.activeAccount]) {
  1287. item.action = nil;
  1288. [menuArray insertObject:item atIndex:0];
  1289. } else {
  1290. item.action = @selector(changeDefaultAccount:);
  1291. [menuArray addObject:item];
  1292. }
  1293. }
  1294. // Add + new account
  1295. CCMenuItem *item = [[CCMenuItem alloc] init];
  1296. item.title = NSLocalizedString(@"_add_account_", nil);
  1297. item.argument = @"";
  1298. item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] width:50 height:50 color:NCBrandColor.sharedInstance.textView];
  1299. item.target = self;
  1300. item.action = @selector(addNewAccount:);
  1301. [menuArray addObject:item];
  1302. OptionalConfiguration options;
  1303. Color backgroundColor;
  1304. const CGFloat *componentsBackgroundColor = CGColorGetComponents(NCBrandColor.sharedInstance.backgroundForm.CGColor);
  1305. backgroundColor.R = componentsBackgroundColor[0];
  1306. backgroundColor.G = componentsBackgroundColor[1];
  1307. backgroundColor.B = componentsBackgroundColor[2];
  1308. options.arrowSize = 9;
  1309. options.marginXSpacing = 7;
  1310. options.marginYSpacing = 10;
  1311. options.intervalSpacing = 20;
  1312. options.menuCornerRadius = 6.5;
  1313. options.maskToBackground = NO;
  1314. options.shadowOfMenu = YES;
  1315. options.hasSeperatorLine = YES;
  1316. options.seperatorLineHasInsets = YES;
  1317. options.textColor = NCBrandColor.sharedInstance.textView;
  1318. options.menuBackgroundColor = backgroundColor;
  1319. options.separatorColor = NCBrandColor.sharedInstance.separator;
  1320. CGRect rect = self.view.frame;
  1321. CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
  1322. CGFloat safeAreaTop = 0;
  1323. CGFloat offsetY = 35;
  1324. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
  1325. rect.origin.y = locationY + safeAreaTop + offsetY;
  1326. rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
  1327. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  1328. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  1329. }
  1330. - (void)changeDefaultAccount:(CCMenuItem *)sender
  1331. {
  1332. // LOGOUT
  1333. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  1334. if (tableAccount) {
  1335. // LOGIN
  1336. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  1337. // go to home sweet home
  1338. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
  1339. }
  1340. }
  1341. - (void)addNewAccount:(CCMenuItem *)sender
  1342. {
  1343. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  1344. }
  1345. - (void)toggleReMainMenu
  1346. {
  1347. [self toggleMenuWithViewController:self.navigationController];
  1348. }
  1349. - (void)toggleReSelectMenu
  1350. {
  1351. [self toggleSelectMenuWithViewController:self.navigationController];
  1352. }
  1353. #pragma --------------------------------------------------------------------------------------------
  1354. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  1355. #pragma --------------------------------------------------------------------------------------------
  1356. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  1357. {
  1358. if (recognizer.state == UIGestureRecognizerStateBegan) {
  1359. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  1360. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  1361. NSMutableArray *items = [NSMutableArray new];
  1362. if ([self indexPathIsValid:indexPath])
  1363. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1364. [self becomeFirstResponder];
  1365. UIMenuController *menuController = [UIMenuController sharedMenuController];
  1366. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyTouchFile:)]];
  1367. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyTouchFiles:)]];
  1368. if ([NCBrandOptions sharedInstance].disable_openin_file == false) {
  1369. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinTouchFile:)]];
  1370. }
  1371. if ([[NCUtility sharedInstance] isQuickLookDisplayableWithMetadata:self.metadata]) {
  1372. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_quicklook_", nil) action:@selector(openQuickLookTouch:)]];
  1373. }
  1374. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteTouchFile:)]];
  1375. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteTouchFiles:)]];
  1376. [menuController setMenuItems:items];
  1377. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  1378. [menuController setMenuVisible:YES animated:YES];
  1379. }
  1380. }
  1381. - (BOOL)canBecomeFirstResponder
  1382. {
  1383. return YES;
  1384. }
  1385. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  1386. {
  1387. // For copy file, copy files, Open in ... :
  1388. //
  1389. // NO Directory
  1390. // NO Error Passcode
  1391. // NO In Session mode (download/upload)
  1392. // NO Template
  1393. if (@selector(copyTouchFile:) == action || @selector(openinTouchFile:) == action || @selector(openQuickLookTouch:) == action) {
  1394. if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
  1395. else return NO;
  1396. }
  1397. if (@selector(copyTouchFiles:) == action) {
  1398. if (_isSelectedMode) {
  1399. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1400. for (tableMetadata *metadata in selectedMetadatas) {
  1401. if (!metadata.directory && metadata.status == k_metadataStatusNormal)
  1402. return YES;
  1403. }
  1404. }
  1405. return NO;
  1406. }
  1407. if (@selector(pasteTouchFile:) == action) {
  1408. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1409. NSArray *items = [pasteboard items];
  1410. if ([items count] == 1) {
  1411. // Value : (NSData) ocId
  1412. NSDictionary *dic = [items objectAtIndex:0];
  1413. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1414. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1415. if (ocId) {
  1416. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1417. if (metadata) {
  1418. return [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView];
  1419. } else {
  1420. return NO;
  1421. }
  1422. }
  1423. }
  1424. return NO;
  1425. }
  1426. if (@selector(pasteTouchFiles:) == action) {
  1427. BOOL isValid = NO;
  1428. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1429. NSArray *items = [pasteboard items];
  1430. if ([items count] <= 1) return NO;
  1431. for (NSDictionary *dic in items) {
  1432. // Value : (NSData) ocId
  1433. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1434. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1435. if (ocId) {
  1436. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1437. if (metadata) {
  1438. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1439. isValid = YES;
  1440. } else {
  1441. isValid = NO;
  1442. break;
  1443. }
  1444. } else {
  1445. isValid = NO;
  1446. break;
  1447. }
  1448. } else {
  1449. isValid = NO;
  1450. break;
  1451. }
  1452. }
  1453. return isValid;
  1454. }
  1455. return NO;
  1456. }
  1457. /************************************ COPY ************************************/
  1458. - (void)copyTouchFile:(id)sender
  1459. {
  1460. // Remove all item
  1461. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1462. pasteboard.items = [[NSArray alloc] init];
  1463. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  1464. [self copyFileToPasteboard:self.metadata];
  1465. } else {
  1466. self.metadata.session = k_download_session;
  1467. self.metadata.sessionError = @"";
  1468. self.metadata.sessionSelector = selectorLoadCopy;
  1469. self.metadata.status = k_metadataStatusWaitDownload;
  1470. // Add Metadata for Download
  1471. [[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  1472. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  1473. [appDelegate startLoadAutoDownloadUpload];
  1474. }
  1475. }
  1476. - (void)copyTouchFiles:(id)sender
  1477. {
  1478. // Remove all item
  1479. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1480. pasteboard.items = [[NSArray alloc] init];
  1481. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1482. for (tableMetadata *metadata in selectedMetadatas) {
  1483. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1484. [self copyFileToPasteboard:metadata];
  1485. } else {
  1486. metadata.session = k_download_session;
  1487. metadata.sessionError = @"";
  1488. metadata.sessionSelector = selectorLoadCopy;
  1489. metadata.status = k_metadataStatusWaitDownload;
  1490. // Add Metadata for Download
  1491. [[NCManageDatabase sharedInstance] addMetadata:metadata];
  1492. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1493. [appDelegate startLoadAutoDownloadUpload];
  1494. }
  1495. }
  1496. [self tableViewSelect:false];
  1497. }
  1498. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  1499. {
  1500. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1501. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  1502. // Value : (NSData) ocId
  1503. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.ocId], k_metadataKeyedUnarchiver,nil];
  1504. [items addObject:item];
  1505. [pasteboard setItems:items];
  1506. }
  1507. /************************************ OPEN IN ... ******************************/
  1508. - (void)openinTouchFile:(id)sender
  1509. {
  1510. [[NCMainCommon sharedInstance] downloadOpenWithMetadata:self.metadata selector:selectorOpenIn];
  1511. }
  1512. /************************************ OPEN QUICK LOOK ******************************/
  1513. - (void)openQuickLookTouch:(id)sender
  1514. {
  1515. [[NCMainCommon sharedInstance] downloadOpenWithMetadata:self.metadata selector:selectorLoadFileQuickLook];
  1516. }
  1517. /************************************ PASTE ************************************/
  1518. - (void)pasteTouchFile:(id)sender
  1519. {
  1520. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1521. [self uploadFilePasteArray:[pasteboard items]];
  1522. }
  1523. - (void)pasteTouchFiles:(id)sender
  1524. {
  1525. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1526. [self uploadFilePasteArray:[pasteboard items]];
  1527. }
  1528. - (void)uploadFilePasteArray:(NSArray *)items
  1529. {
  1530. for (NSDictionary *dic in items) {
  1531. // Value : (NSData) ocId
  1532. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1533. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1534. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1535. if (metadata) {
  1536. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1537. NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView serverUrl:self.serverUrl account:appDelegate.activeAccount];
  1538. NSString *ocId = [[NSUUID UUID] UUIDString];
  1539. [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName]];
  1540. // Prepare record metadata
  1541. tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:ocId serverUrl:self.serverUrl url:@"" contentType:@""];
  1542. metadataForUpload.session = k_upload_session;
  1543. metadataForUpload.sessionSelector = selectorUploadFile;
  1544. metadataForUpload.size = metadata.size;
  1545. metadataForUpload.status = k_metadataStatusWaitUpload;
  1546. // Add Medtadata for upload
  1547. [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  1548. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1549. }
  1550. }
  1551. }
  1552. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1553. [appDelegate startLoadAutoDownloadUpload];
  1554. }
  1555. #pragma mark -
  1556. #pragma --------------------------------------------------------------------------------------------
  1557. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  1558. #pragma --------------------------------------------------------------------------------------------
  1559. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  1560. {
  1561. if (metadata == nil || _metadataFolder == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || metadata.status != k_metadataStatusNormal || [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])
  1562. return NO;
  1563. // E2EE
  1564. if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
  1565. return NO;
  1566. return YES;
  1567. }
  1568. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  1569. {
  1570. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  1571. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1572. return [self canOpenMenuAction:metadata];
  1573. }
  1574. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  1575. {
  1576. }
  1577. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  1578. {
  1579. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  1580. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1581. if (direction == MGSwipeDirectionRightToLeft) {
  1582. [self actionDelete:indexPath];
  1583. }
  1584. if (direction == MGSwipeDirectionLeftToRight) {
  1585. [[NCNetworking sharedInstance] favoriteMetadata:self.metadata url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
  1586. }
  1587. return YES;
  1588. }
  1589. - (void)actionDelete:(NSIndexPath *)indexPath
  1590. {
  1591. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1592. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  1593. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1594. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1595. [self performSelector:@selector(deleteMetadatas) withObject:nil];
  1596. }]];
  1597. if (localFile) {
  1598. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1599. tableMetadata *metadataLivePhoto = [[NCUtility sharedInstance] isLivePhotoWithMetadata:metadata];
  1600. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  1601. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] error:nil];
  1602. if (metadataLivePhoto) {
  1603. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataLivePhoto.ocId]];
  1604. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadataLivePhoto.ocId] error:nil];
  1605. }
  1606. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1607. }]];
  1608. }
  1609. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1610. }]];
  1611. alertController.popoverPresentationController.sourceView = self.tableView;
  1612. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1613. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1614. [alertController.view layoutIfNeeded];
  1615. [self presentViewController:alertController animated:YES completion:nil];
  1616. }
  1617. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  1618. {
  1619. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  1620. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  1621. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1622. [self toggleMoreMenuWithViewController:self.tabBarController indexPath:indexPath metadata:self.metadata metadataFolder:_metadataFolder];
  1623. }
  1624. #pragma --------------------------------------------------------------------------------------------
  1625. #pragma mark - ==== Datasource ====
  1626. #pragma --------------------------------------------------------------------------------------------
  1627. - (void)clearDateReadDataSource:(NSNotification *)notification
  1628. {
  1629. _dateReadDataSource = Nil;
  1630. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1631. }
  1632. - (void)reloadDatasource:(NSString *)serverUrl ocId:(NSString *)ocId action:(NSInteger)action
  1633. {
  1634. // test
  1635. if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
  1636. return;
  1637. // Search Mode
  1638. if (self.searchController.isActive) {
  1639. // Create metadatas
  1640. NSMutableArray *metadatas = [NSMutableArray new];
  1641. for (tableMetadata *resultMetadata in _searchResultMetadatas) {
  1642. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", resultMetadata.ocId]];
  1643. if (metadata) {
  1644. [metadatas addObject:metadata];
  1645. }
  1646. }
  1647. // [CCUtility getGroupBySettings]
  1648. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:nil filterTypeFileImage:NO filterTypeFileVideo:NO sorted:@"fileName" ascending:NO activeAccount:appDelegate.activeAccount];
  1649. [self tableViewReloadData];
  1650. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  1651. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  1652. _noFilesSearchDescription = @"";
  1653. }
  1654. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  1655. _noFilesSearchTitle = @"";
  1656. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  1657. }
  1658. [self.tableView reloadEmptyDataSet];
  1659. return;
  1660. }
  1661. // Se non siamo nella dir appropriata esci
  1662. if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
  1663. return;
  1664. }
  1665. // Controllo data lettura Data Source
  1666. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  1667. if (tableDirectory == nil) {
  1668. return;
  1669. }
  1670. // Get MetadataFolder
  1671. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
  1672. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, k_serverUrl_root]];
  1673. else
  1674. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tableDirectory.ocId]];
  1675. // Remove optimization for encrypted directory
  1676. if (_metadataFolder.e2eEncrypted)
  1677. _dateReadDataSource = nil;
  1678. NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
  1679. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  1680. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  1681. _dateReadDataSource = [NSDate date];
  1682. // Data Source
  1683. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1684. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
  1685. dispatch_async(dispatch_get_main_queue(), ^{
  1686. sectionDataSource = sectionDataSourceTemp;
  1687. [self tableViewReloadData];
  1688. });
  1689. });
  1690. } else {
  1691. [self tableViewReloadData];
  1692. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  1693. }
  1694. // BLINK
  1695. if (self.blinkFileNamePath != nil) {
  1696. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  1697. for (NSString *key in sectionDataSource.allRecordsDataSource) {
  1698. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:key];
  1699. NSString *metadataFileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1700. if ([metadataFileNamePath isEqualToString:self.blinkFileNamePath]) {
  1701. for (NSString *key in sectionDataSource.ocIdIndexPath) {
  1702. if ([key isEqualToString:metadata.ocId]) {
  1703. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:key];
  1704. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  1705. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  1706. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  1707. if (cell) {
  1708. self.blinkFileNamePath = nil;
  1709. [[NCUtility sharedInstance] blinkWithCell:cell];
  1710. }
  1711. });
  1712. }
  1713. }
  1714. }
  1715. }
  1716. });
  1717. }
  1718. }
  1719. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
  1720. {
  1721. // test
  1722. if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
  1723. return nil;
  1724. }
  1725. // get auto upload folder
  1726. _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  1727. _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
  1728. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  1729. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl] sorted:nil ascending:NO];
  1730. // [CCUtility getGroupBySettings]
  1731. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil filterTypeFileImage:NO filterTypeFileVideo:NO sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings] activeAccount:appDelegate.activeAccount];
  1732. if (withReloadData) {
  1733. sectionDataSource = sectionDataSourceTemp;
  1734. [self tableViewReloadData];
  1735. }
  1736. return sectionDataSourceTemp;
  1737. }
  1738. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  1739. {
  1740. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1741. if (selectedRows.count > 0) {
  1742. for (NSIndexPath *selectionIndex in selectedRows) {
  1743. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  1744. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  1745. [metadatas addObject:metadata];
  1746. }
  1747. }
  1748. return metadatas;
  1749. }
  1750. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  1751. {
  1752. NSInteger totSections =[sectionDataSource.sections count] ;
  1753. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  1754. return nil;
  1755. }
  1756. id valueSection = [sectionDataSource.sections objectAtIndex:section];
  1757. return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
  1758. }
  1759. #pragma --------------------------------------------------------------------------------------------
  1760. #pragma mark - ==== Table ====
  1761. #pragma --------------------------------------------------------------------------------------------
  1762. - (void)tableViewToggle
  1763. {
  1764. [self tableViewSelect:!_isSelectedMode];
  1765. }
  1766. - (void)tableViewSelect:(BOOL)toggle
  1767. {
  1768. _isSelectedMode = toggle;
  1769. // chiudiamo eventuali swipe aperti
  1770. if (_isSelectedMode)
  1771. [self.tableView setEditing:NO animated:NO];
  1772. [self.tableView setAllowsMultipleSelectionDuringEditing:_isSelectedMode];
  1773. [self.tableView setEditing:_isSelectedMode animated:YES];
  1774. if (_isSelectedMode)
  1775. [self setUINavigationBarSelected];
  1776. else
  1777. [self setUINavigationBarDefault];
  1778. [_selectedocIdsMetadatas removeAllObjects];
  1779. [self setTitle];
  1780. }
  1781. - (void)tableViewReloadData
  1782. {
  1783. // store selected cells before relod
  1784. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  1785. // reload table view
  1786. [self.tableView reloadData];
  1787. // selected cells stored
  1788. for (NSIndexPath *path in indexPaths)
  1789. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  1790. [self setTableViewHeader];
  1791. [self setTableViewFooter];
  1792. if (self.tableView.editing)
  1793. [self setTitle];
  1794. [self.tableView reloadEmptyDataSet];
  1795. }
  1796. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  1797. {
  1798. if (tableView.editing == 1) {
  1799. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1800. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  1801. return NO;
  1802. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  1803. return NO;
  1804. else
  1805. return YES;
  1806. } else {
  1807. [_selectedocIdsMetadatas removeAllObjects];
  1808. }
  1809. return YES;
  1810. }
  1811. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  1812. {
  1813. return 60;
  1814. }
  1815. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1816. {
  1817. return [[sectionDataSource.sectionArrayRow allKeys] count];
  1818. }
  1819. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1820. {
  1821. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  1822. }
  1823. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1824. {
  1825. NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
  1826. NSString *sectionTitle = [sections objectAtIndex:section];
  1827. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  1828. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  1829. if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  1830. return 20.f;
  1831. }
  1832. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1833. {
  1834. float shift;
  1835. UIVisualEffectView *visualEffectView;
  1836. NSString *titleSection;
  1837. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  1838. return nil;
  1839. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  1840. titleSection = [sectionDataSource.sections objectAtIndex:section];
  1841. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  1842. titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  1843. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  1844. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  1845. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  1846. else titleSection = NSLocalizedString(titleSection,nil);
  1847. // Format title
  1848. UIVisualEffect *blurEffect;
  1849. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  1850. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  1851. visualEffectView.backgroundColor = [NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.2];
  1852. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
  1853. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1854. shift = - 35;
  1855. else
  1856. shift = - 20;
  1857. } else shift = - 10;
  1858. // Title
  1859. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  1860. titleLabel.backgroundColor = [UIColor clearColor];
  1861. titleLabel.textColor = NCBrandColor.sharedInstance.textView;
  1862. titleLabel.font = [UIFont systemFontOfSize:12];
  1863. titleLabel.textAlignment = NSTextAlignmentLeft;
  1864. titleLabel.text = titleSection;
  1865. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1866. [visualEffectView.contentView addSubview:titleLabel];
  1867. // Elements
  1868. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  1869. elementLabel.backgroundColor = [UIColor clearColor];
  1870. elementLabel.textColor = NCBrandColor.sharedInstance.textView;
  1871. elementLabel.font = [UIFont systemFontOfSize:12];
  1872. elementLabel.textAlignment = NSTextAlignmentRight;
  1873. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1874. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  1875. NSUInteger rowsCount = [metadatas count];
  1876. if (rowsCount == 0) return nil;
  1877. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  1878. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  1879. [visualEffectView.contentView addSubview:elementLabel];
  1880. return visualEffectView;
  1881. }
  1882. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  1883. {
  1884. return [sectionDataSource.sections indexOfObject:title];
  1885. }
  1886. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  1887. {
  1888. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
  1889. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  1890. else
  1891. return nil;
  1892. }
  1893. /*
  1894. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  1895. {
  1896. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  1897. }
  1898. }
  1899. */
  1900. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1901. {
  1902. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1903. tableShare *shareCell;
  1904. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || (_metadataFolder != nil && [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])) {
  1905. return [CCCellMain new];
  1906. }
  1907. for (tableShare *share in appDelegate.shares) {
  1908. if ([share.serverUrl isEqualToString:metadata.serverUrl] && [share.fileName isEqualToString:metadata.fileName]) {
  1909. shareCell = share;
  1910. break;
  1911. }
  1912. }
  1913. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory tableShare:shareCell];
  1914. // NORMAL - > MAIN
  1915. if ([cell isKindOfClass:[CCCellMain class]]) {
  1916. // Comment tap
  1917. if (metadata.commentsUnread) {
  1918. UITapGestureRecognizer *tapComment = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionComment:)];
  1919. [tapComment setNumberOfTapsRequired:1];
  1920. ((CCCellMain *)cell).comment.userInteractionEnabled = YES;
  1921. [((CCCellMain *)cell).comment addGestureRecognizer:tapComment];
  1922. }
  1923. // Share add Tap
  1924. UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  1925. [tapShare setNumberOfTapsRequired:1];
  1926. ((CCCellMain *)cell).viewShared.userInteractionEnabled = YES;
  1927. [((CCCellMain *)cell).viewShared addGestureRecognizer:tapShare];
  1928. // More
  1929. if ([self canOpenMenuAction:metadata]) {
  1930. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  1931. [tapMore setNumberOfTapsRequired:1];
  1932. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  1933. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  1934. }
  1935. // MGSwipeButton
  1936. ((CCCellMain *)cell).delegate = self;
  1937. // LEFT
  1938. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellFavouriteImage backgroundColor:NCBrandColor.sharedInstance.yellowFavorite padding:25]];
  1939. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  1940. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  1941. //centerIconOverText
  1942. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  1943. [favoriteButton centerIconOverText];
  1944. // RIGHT
  1945. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellTrashImage backgroundColor:[UIColor redColor] padding:25]];
  1946. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  1947. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  1948. //centerIconOverText
  1949. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  1950. [deleteButton centerIconOverText];
  1951. }
  1952. // TRANSFER
  1953. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  1954. // gesture Transfer
  1955. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  1956. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  1957. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  1958. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  1959. }
  1960. return cell;
  1961. }
  1962. - (void)setTableViewHeader
  1963. {
  1964. NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesVersionMajor];
  1965. NSString *trimmedRichWorkspaceText = [self.richWorkspaceText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  1966. if (serverVersionMajor < k_nextcloud_version_18_0 || trimmedRichWorkspaceText.length == 0 ) {
  1967. [self.tableView.tableHeaderView setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightSearchBar)];
  1968. } else {
  1969. [self.viewRichWorkspace setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightRichWorkspace)];
  1970. }
  1971. if (self.searchController.isActive == true) {
  1972. [self.tableView.tableHeaderView setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, 0)];
  1973. }
  1974. [self.viewRichWorkspace setNeedsLayout];
  1975. [self.viewRichWorkspace loadWithRichWorkspaceText:self.richWorkspaceText];
  1976. }
  1977. - (void)setTableViewFooter
  1978. {
  1979. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  1980. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  1981. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  1982. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  1983. UIFont *appFont = [UIFont systemFontOfSize:12];
  1984. footerLabel.font = appFont;
  1985. footerLabel.textColor = [UIColor grayColor];
  1986. footerLabel.backgroundColor = [UIColor clearColor];
  1987. footerLabel.textAlignment = NSTextAlignmentCenter;
  1988. NSString *folders;
  1989. NSString *files;
  1990. NSString *footerText;
  1991. if (sectionDataSource.directories > 1) {
  1992. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  1993. } else if (sectionDataSource.directories == 1){
  1994. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  1995. } else {
  1996. folders = @"";
  1997. }
  1998. if (sectionDataSource.files > 1) {
  1999. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2000. } else if (sectionDataSource.files == 1){
  2001. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2002. } else {
  2003. files = @"";
  2004. }
  2005. if ([folders isEqualToString:@""]) {
  2006. footerText = files;
  2007. } else if ([files isEqualToString:@""]) {
  2008. footerText = folders;
  2009. } else {
  2010. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  2011. }
  2012. footerLabel.text = footerText;
  2013. [footerView addSubview:footerLabel];
  2014. [self.tableView setTableFooterView:footerView];
  2015. }
  2016. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2017. {
  2018. CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
  2019. // settiamo il record file.
  2020. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2021. if (!self.metadata)
  2022. return;
  2023. // se non può essere selezionata deseleziona
  2024. if ([cell isEditing] == NO)
  2025. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  2026. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  2027. if (self.tableView.editing) {
  2028. [_selectedocIdsMetadatas setObject:self.metadata forKey:self.metadata.ocId];
  2029. [self setTitle];
  2030. return;
  2031. }
  2032. // se è in corso una sessione
  2033. if (self.metadata.status != k_metadataStatusNormal)
  2034. return;
  2035. // file
  2036. if (self.metadata.directory == NO) {
  2037. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  2038. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2039. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_downloadedFile object:nil userInfo:@{@"metadata": self.metadata, @"selector": selectorLoadFileView, @"errorCode": @(0), @"errorDescription": @""}];
  2040. } else {
  2041. if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2042. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2043. } else {
  2044. if (([self.metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) && _metadataFolder.e2eEncrypted == NO) {
  2045. [self shouldPerformSegue:self.metadata selector:@""];
  2046. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isDirectEditing:self.metadata] != nil) {
  2047. if (NCCommunication.shared.isNetworkReachable) {
  2048. [self shouldPerformSegue:self.metadata selector:@""];
  2049. } else {
  2050. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2051. }
  2052. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isRichDocument:self.metadata]) {
  2053. if (NCCommunication.shared.isNetworkReachable) {
  2054. [self shouldPerformSegue:self.metadata selector:@""];
  2055. } else {
  2056. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2057. }
  2058. } else {
  2059. if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  2060. [self shouldPerformSegue:self.metadata selector:selectorLoadFileView];
  2061. }
  2062. self.metadata.session = k_download_session;
  2063. self.metadata.sessionError = @"";
  2064. self.metadata.sessionSelector = selectorLoadFileView;
  2065. self.metadata.status = k_metadataStatusWaitDownload;
  2066. // Add Metadata for Download
  2067. [[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2068. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2069. [appDelegate startLoadAutoDownloadUpload];
  2070. }
  2071. }
  2072. }
  2073. }
  2074. if (self.metadata.directory) {
  2075. [self performSegueDirectoryWithMetadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2076. }
  2077. }
  2078. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  2079. {
  2080. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2081. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  2082. [self setTitle];
  2083. }
  2084. - (void)didSelectAll
  2085. {
  2086. for (int i = 0; i < self.tableView.numberOfSections; i++) {
  2087. for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
  2088. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2089. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2090. [_selectedocIdsMetadatas setObject:metadata forKey:metadata.ocId];
  2091. [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  2092. }
  2093. }
  2094. [self setTitle];
  2095. }
  2096. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  2097. {
  2098. if (!indexPath)
  2099. return NO;
  2100. NSInteger section = indexPath.section;
  2101. NSInteger row = indexPath.row;
  2102. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  2103. if (section > lastSectionIndex || lastSectionIndex < 0)
  2104. return NO;
  2105. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  2106. if (rowCount < 0)
  2107. return NO;
  2108. return row <= rowCount;
  2109. }
  2110. #pragma --------------------------------------------------------------------------------------------
  2111. #pragma mark ===== Navigation ====
  2112. #pragma --------------------------------------------------------------------------------------------
  2113. - (void)shouldPerformSegue:(tableMetadata *)metadata selector:(NSString *)selector
  2114. {
  2115. // if background return
  2116. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  2117. if (self.view.window == NO)
  2118. return;
  2119. // Collapsed ma siamo già in detail esci
  2120. if (self.splitViewController.isCollapsed) {
  2121. if (appDelegate.activeDetail.isViewLoaded && appDelegate.activeDetail.view.window) return;
  2122. }
  2123. // Metadata for push detail
  2124. self.metadataForPushDetail = metadata;
  2125. self.selectorForPushDetail = selector;
  2126. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  2127. }
  2128. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  2129. {
  2130. tableMetadata *metadata;
  2131. NSMutableArray *photoDataSource = [NSMutableArray new];
  2132. UINavigationController *navigationController = segue.destinationViewController;
  2133. NCDetailViewController *detailViewController = (NCDetailViewController *)navigationController.topViewController;
  2134. if ([sender isKindOfClass:[tableMetadata class]]) {
  2135. metadata = sender;
  2136. [photoDataSource addObject:sender];
  2137. } else {
  2138. metadata = self.metadataForPushDetail;
  2139. for (NSString *ocId in sectionDataSource.allOcId) {
  2140. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2141. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  2142. [photoDataSource addObject:metadata];
  2143. }
  2144. }
  2145. detailViewController.metadata = metadata;
  2146. detailViewController.selector = self.selectorForPushDetail;
  2147. [detailViewController setTitle:metadata.fileNameView];
  2148. }
  2149. // can i go to next viewcontroller
  2150. - (void)performSegueDirectoryWithMetadata:(tableMetadata *)metadata blinkFileNamePath:(NSString *)blinkFileNamePath
  2151. {
  2152. NSString *nomeDir;
  2153. if (self.tableView.editing == NO) {
  2154. // E2EE Check enable
  2155. if (metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
  2156. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2157. return;
  2158. }
  2159. nomeDir = metadata.fileName;
  2160. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:nomeDir];
  2161. CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
  2162. if (!viewController) {
  2163. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
  2164. viewController.serverUrl = serverUrlPush;
  2165. viewController.titleMain = metadata.fileNameView;
  2166. viewController.blinkFileNamePath = blinkFileNamePath;
  2167. // save self
  2168. [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
  2169. [self.navigationController pushViewController:viewController animated:YES];
  2170. } else {
  2171. if (viewController.isViewLoaded) {
  2172. viewController.titleMain = metadata.fileNameView;
  2173. viewController.blinkFileNamePath = blinkFileNamePath;
  2174. // Fix : Application tried to present modally an active controller
  2175. if ([self.navigationController isBeingPresented]) {
  2176. // being presented
  2177. } else if ([self.navigationController isMovingToParentViewController]) {
  2178. // being pushed
  2179. } else {
  2180. [self.navigationController pushViewController:viewController animated:YES];
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. @end