CCMain.m 125 KB

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