CCMain.m 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092
  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 <JDStatusBarNotification/JDStatusBarNotification.h>
  24. #import "CCMain.h"
  25. #import "AppDelegate.h"
  26. #import "CCSynchronize.h"
  27. #import "OCActivity.h"
  28. #import "OCNotifications.h"
  29. #import "OCNotificationsAction.h"
  30. #import "OCFrameworkConstants.h"
  31. #import "OCCapabilities.h"
  32. #import "NCAutoUpload.h"
  33. #import "NCBridgeSwift.h"
  34. #import "NCNetworkingEndToEnd.h"
  35. #import "PKDownloadButton.h"
  36. @interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, NCSelectDelegate, UITextFieldDelegate>
  37. {
  38. AppDelegate *appDelegate;
  39. BOOL _isRoot;
  40. BOOL _isViewDidLoad;
  41. NSMutableDictionary *_selectedocIdsMetadatas;
  42. NSUInteger _numSelectedocIdsMetadatas;
  43. UIImageView *_imageTitleHome;
  44. NSUInteger _failedAttempts;
  45. NSDate *_lockUntilDate;
  46. UIRefreshControl *refreshControl;
  47. CCHud *_hud;
  48. // Datasource
  49. CCSectionDataSourceMetadata *sectionDataSource;
  50. NSDate *_dateReadDataSource;
  51. // Search
  52. BOOL _isSearchMode;
  53. NSString *_searchFileName;
  54. NSMutableArray *_searchResultMetadatas;
  55. NSString *_noFilesSearchTitle;
  56. NSString *_noFilesSearchDescription;
  57. NSTimer *_timerWaitInput;
  58. // Automatic Upload Folder
  59. NSString *_autoUploadFileName;
  60. NSString *_autoUploadDirectory;
  61. // Folder
  62. BOOL _loadingFolder;
  63. tableMetadata *_metadataFolder;
  64. }
  65. @end
  66. @implementation CCMain
  67. #pragma --------------------------------------------------------------------------------------------
  68. #pragma mark ===== Init =====
  69. #pragma --------------------------------------------------------------------------------------------
  70. - (id)initWithCoder:(NSCoder *)aDecoder
  71. {
  72. if (self = [super initWithCoder:aDecoder]) {
  73. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  74. appDelegate.activeMain = self;
  75. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
  76. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
  77. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
  78. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  79. }
  80. return self;
  81. }
  82. #pragma --------------------------------------------------------------------------------------------
  83. #pragma mark ===== View =====
  84. #pragma --------------------------------------------------------------------------------------------
  85. - (void)viewDidLoad
  86. {
  87. [super viewDidLoad];
  88. // init object
  89. self.metadata = [tableMetadata new];
  90. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  91. _selectedocIdsMetadatas = [NSMutableDictionary new];
  92. _isViewDidLoad = YES;
  93. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  94. _searchResultMetadatas = [NSMutableArray new];
  95. _searchFileName = @"";
  96. _noFilesSearchTitle = @"";
  97. _noFilesSearchDescription = @"";
  98. _cellFavouriteImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:[UIColor whiteColor]];
  99. _cellTrashImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor whiteColor]];
  100. // delegate
  101. self.tableView.delegate = self;
  102. self.tableView.tableFooterView = [UIView new];
  103. self.tableView.emptyDataSetDelegate = self;
  104. self.tableView.emptyDataSetSource = self;
  105. self.searchController.delegate = self;
  106. self.searchController.searchBar.delegate = self;
  107. // Register cell
  108. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  109. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  110. // long press recognizer TableView
  111. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  112. [self.tableView addGestureRecognizer:longPressRecognizer];
  113. // Pull-to-Refresh
  114. [self createRefreshControl];
  115. // Register for 3D Touch Previewing if available
  116. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
  117. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  118. }
  119. // reMenu Background
  120. _reMenuBackgroundView = [UIView new];
  121. _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  122. // if this is not Main (the Main uses inizializeMain)
  123. if (_isRoot == NO && appDelegate.activeAccount.length > 0) {
  124. // Read (File) Folder
  125. [self readFileReloadFolder];
  126. }
  127. // Title
  128. [self setTitle];
  129. // changeTheming
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  131. [self changeTheming];
  132. }
  133. - (void)viewWillAppear:(BOOL)animated
  134. {
  135. [super viewWillAppear:animated];
  136. // test
  137. if (appDelegate.activeAccount.length == 0)
  138. return;
  139. if (_isSelectedMode)
  140. [self setUINavigationBarSelected];
  141. else
  142. [self setUINavigationBarDefault];
  143. // If not editing mode remove _selectedocIds
  144. if (!self.tableView.editing)
  145. [_selectedocIdsMetadatas removeAllObjects];
  146. // Search Bar
  147. if ([CCUtility isFolderEncrypted:self.serverUrl account:appDelegate.activeAccount]) {
  148. [self searchEnabled:NO];
  149. } else {
  150. [self searchEnabled:YES];
  151. }
  152. // Get Shares
  153. appDelegate.shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount serverUrl:self.serverUrl];
  154. // Query data source
  155. if (!_isSearchMode) {
  156. [self queryDatasourceWithReloadData:YES serverUrl:self.serverUrl];
  157. }
  158. }
  159. - (void)viewDidAppear:(BOOL)animated
  160. {
  161. [super viewDidAppear:animated];
  162. // Active Main
  163. appDelegate.activeMain = self;
  164. // Test viewDidLoad
  165. if (_isViewDidLoad) {
  166. _isViewDidLoad = NO;
  167. } else {
  168. if (appDelegate.activeAccount.length > 0 && [_selectedocIdsMetadatas count] == 0) {
  169. // Read (file) Folder
  170. [self readFileReloadFolder];
  171. }
  172. }
  173. // Title
  174. [self setTitle];
  175. }
  176. - (void)viewWillDisappear:(BOOL)animated
  177. {
  178. [super viewWillDisappear:animated];
  179. [self closeAllMenu];
  180. }
  181. - (void)didReceiveMemoryWarning
  182. {
  183. [super didReceiveMemoryWarning];
  184. // Dispose of any resources that can be recreated.
  185. }
  186. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  187. {
  188. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  189. [self closeAllMenu];
  190. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  191. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  192. // Portrait
  193. } else {
  194. // Landscape
  195. }
  196. [self.tableView reloadData];
  197. }];
  198. }
  199. - (BOOL)prefersStatusBarHidden
  200. {
  201. return NO;
  202. }
  203. // detect scroll for remove keyboard in search mode
  204. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  205. {
  206. if (_isSearchMode && scrollView == self.tableView) {
  207. [self.searchController.searchBar endEditing:YES];
  208. }
  209. }
  210. - (void)changeTheming
  211. {
  212. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:false];
  213. // createImagesThemingColor
  214. [[NCMainCommon sharedInstance] createImagesThemingColor];
  215. // Refresh control
  216. refreshControl.tintColor = NCBrandColor.sharedInstance.brandText;
  217. refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand;
  218. // color searchbar
  219. self.searchController.searchBar.barTintColor = NCBrandColor.sharedInstance.brand;
  220. self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.brand;
  221. // color searchbbar button text (cancel)
  222. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  223. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  224. [searchButton setTitleColor:NCBrandColor.sharedInstance.brandText forState:UIControlStateNormal];
  225. }
  226. // color textview searchbbar
  227. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  228. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  229. searchTextView.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  230. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  231. }
  232. // Title
  233. [self setTitle];
  234. // Reload Table View
  235. [self tableViewReloadData];
  236. }
  237. #pragma --------------------------------------------------------------------------------------------
  238. #pragma mark ===== Initialization =====
  239. #pragma --------------------------------------------------------------------------------------------
  240. //
  241. // Callers :
  242. //
  243. // ChangeDefaultAccount (delegate)
  244. // Split : inizialize
  245. // Settings Advanced : removeAllFiles
  246. //
  247. - (void)initializeMain:(NSNotification *)notification
  248. {
  249. _dateReadDataSource = nil;
  250. // test
  251. if (appDelegate.activeAccount.length == 0)
  252. return;
  253. if ([appDelegate.listMainVC count] == 0 || _isRoot) {
  254. // This is Root home main add list
  255. appDelegate.homeMain = self;
  256. _isRoot = YES;
  257. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  258. [appDelegate.listMainVC setObject:self forKey:_serverUrl];
  259. // go Home
  260. [self.navigationController popToRootViewControllerAnimated:NO];
  261. // Remove search mode
  262. [self cancelSearchBar];
  263. // Clear error certificate
  264. [CCUtility setCertificateError:appDelegate.activeAccount error:NO];
  265. // Setting Theming
  266. [appDelegate settingThemingColorBrand];
  267. // Detail
  268. // If AVPlayer in play -> Stop
  269. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  270. [appDelegate.player pause];
  271. }
  272. for (UIView *view in [appDelegate.activeDetail.view subviews]) {
  273. if ([view isKindOfClass:[UIImageView class]] == NO) { // View Image Nextcloud
  274. [view removeFromSuperview];
  275. }
  276. }
  277. appDelegate.activeDetail.title = nil;
  278. // remove all Notification Messages
  279. [appDelegate.listOfNotifications removeAllObjects];
  280. // Not Photos Video in library ? then align and Init Auto Upload
  281. NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
  282. if ([recordsPhotoLibrary count] == 0) {
  283. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  284. }
  285. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  286. NSLog(@"[LOG] Request Service Server Nextcloud");
  287. [[NCService sharedInstance] startRequestServicesServer];
  288. // Clear datasorce
  289. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  290. // Read this folder
  291. [self readFileReloadFolder];
  292. } else {
  293. // reload datasource
  294. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  295. }
  296. // Registeration push notification
  297. [appDelegate pushNotification];
  298. // Registeration domain File Provider
  299. if (@available(iOS 11, *) ) {
  300. if (k_fileProvider_domain) {
  301. [FileProviderDomain.sharedInstance registerDomain];
  302. } else {
  303. [FileProviderDomain.sharedInstance removeAllDomain];
  304. }
  305. }
  306. }
  307. #pragma --------------------------------------------------------------------------------------------
  308. #pragma mark ==== DZNEmptyDataSetSource ====
  309. #pragma --------------------------------------------------------------------------------------------
  310. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
  311. {
  312. if (_loadingFolder)
  313. return NO;
  314. else
  315. return YES;
  316. }
  317. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  318. {
  319. return NCBrandColor.sharedInstance.backgroundView;
  320. }
  321. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  322. {
  323. if (_isSearchMode)
  324. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"search"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  325. else
  326. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  327. }
  328. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
  329. {
  330. if (_loadingFolder && refreshControl.isRefreshing == NO) {
  331. UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  332. activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  333. activityView.color = NCBrandColor.sharedInstance.brandElement;
  334. [activityView startAnimating];
  335. return activityView;
  336. }
  337. return nil;
  338. }
  339. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  340. {
  341. NSString *text;
  342. if (_isSearchMode) {
  343. text = _noFilesSearchTitle;
  344. } else {
  345. text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
  346. }
  347. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  348. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  349. }
  350. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  351. {
  352. NSString *text;
  353. if (_isSearchMode) {
  354. text = _noFilesSearchDescription;
  355. } else {
  356. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
  357. }
  358. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  359. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  360. paragraph.alignment = NSTextAlignmentCenter;
  361. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  362. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  363. }
  364. #pragma --------------------------------------------------------------------------------------------
  365. #pragma mark ===== Text Field =====
  366. #pragma --------------------------------------------------------------------------------------------
  367. - (void)minCharTextFieldDidChange:(UITextField *)sender
  368. {
  369. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  370. if (alertController)
  371. {
  372. UITextField *fileName = alertController.textFields.firstObject;
  373. UIAlertAction *okAction = alertController.actions.lastObject;
  374. okAction.enabled = fileName.text.length > 0;
  375. }
  376. }
  377. - (void)textFieldDidBeginEditing:(UITextField *)textField
  378. {
  379. [CCUtility selectFileNameFrom:textField];
  380. }
  381. #pragma --------------------------------------------------------------------------------------------
  382. #pragma mark ===== Graphic Window =====
  383. #pragma --------------------------------------------------------------------------------------------
  384. - (void)createRefreshControl
  385. {
  386. refreshControl = [UIRefreshControl new];
  387. if (@available(iOS 10, *)) {
  388. _tableView.refreshControl = refreshControl;
  389. } else {
  390. [_tableView addSubview:refreshControl];
  391. }
  392. refreshControl.tintColor = NCBrandColor.sharedInstance.brandText;
  393. refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand;
  394. [refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
  395. }
  396. - (void)deleteRefreshControl
  397. {
  398. [refreshControl endRefreshing];
  399. for (UIView *subview in [_tableView subviews]) {
  400. if (subview == refreshControl)
  401. [subview removeFromSuperview];
  402. }
  403. if (@available(iOS 10, *)) {
  404. self.tableView.refreshControl = nil;
  405. }
  406. refreshControl = nil;
  407. }
  408. - (void)refreshControlTarget
  409. {
  410. [self readFolder:_serverUrl];
  411. // Actuate `Peek` feedback (weak boom)
  412. AudioServicesPlaySystemSound(1519);
  413. }
  414. - (void)setTitle
  415. {
  416. if (_isSelectedMode) {
  417. NSUInteger totali = [sectionDataSource.allRecordsDataSource count];
  418. NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
  419. self.navigationItem.titleView = nil;
  420. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
  421. } else {
  422. // we are in home : LOGO BRAND
  423. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  424. self.navigationItem.title = nil;
  425. UIImage *image = [self getImageLogoHome];
  426. _imageTitleHome = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; // IMAGE = 120 x 60
  427. _imageTitleHome.contentMode = UIViewContentModeScaleAspectFill;
  428. _imageTitleHome.translatesAutoresizingMaskIntoConstraints = NO;
  429. _imageTitleHome.image = image;
  430. // backbutton
  431. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
  432. [_imageTitleHome setUserInteractionEnabled:YES];
  433. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuLogo:)];
  434. [singleTap setNumberOfTapsRequired:1];
  435. [_imageTitleHome addGestureRecognizer:singleTap];
  436. self.navigationItem.titleView = _imageTitleHome;
  437. } else {
  438. self.navigationItem.title = _titleMain;
  439. self.navigationItem.titleView = nil;
  440. }
  441. }
  442. }
  443. - (UIImage *)getImageLogoHome
  444. {
  445. UIImage *image = [UIImage imageNamed:@"themingLogo"];
  446. if ([NCBrandOptions sharedInstance].use_themingLogo) {
  447. image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@-themingLogo.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl]]];
  448. if (image == nil) image = [UIImage imageNamed:@"themingLogo"];
  449. }
  450. if ([appDelegate.reachability isReachable] == NO) {
  451. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"nonetwork"] width:50 height:50 color:NCBrandColor.sharedInstance.icon];
  452. } else {
  453. return image;
  454. }
  455. }
  456. - (void)setUINavigationBarDefault
  457. {
  458. UIBarButtonItem *buttonMore, *buttonNotification;
  459. // =
  460. buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
  461. buttonMore.enabled = true;
  462. // <
  463. self.navigationController.navigationBar.hidden = NO;
  464. // Notification
  465. if ([appDelegate.listOfNotifications count] > 0) {
  466. buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"notification"] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
  467. buttonNotification.tintColor = NCBrandColor.sharedInstance.brandText;
  468. buttonNotification.enabled = true;
  469. }
  470. if (buttonNotification)
  471. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
  472. else
  473. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  474. self.navigationItem.leftBarButtonItem = nil;
  475. }
  476. - (void)setUINavigationBarSelected
  477. {
  478. UIImage *icon = [UIImage imageNamed:@"navigationControllerMenu"];
  479. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
  480. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
  481. self.navigationItem.leftBarButtonItem = leftButton;
  482. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  483. }
  484. - (void)cancelSelect
  485. {
  486. [self tableViewSelect:NO];
  487. [appDelegate.reSelectMenu close];
  488. }
  489. - (void)closeAllMenu
  490. {
  491. // close Menu
  492. [appDelegate.reSelectMenu close];
  493. [appDelegate.reMainMenu close];
  494. // Close Menu Logo
  495. [CCMenuAccount dismissMenu];
  496. }
  497. #pragma --------------------------------------------------------------------------------------------
  498. #pragma mark ===== Document Picker =====
  499. #pragma --------------------------------------------------------------------------------------------
  500. - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
  501. {
  502. NSLog(@"[LOG] Cancelled");
  503. }
  504. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
  505. {
  506. NSLog(@"[LOG] Cancelled");
  507. }
  508. - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
  509. {
  510. documentPicker.delegate = self;
  511. [self presentViewController:documentPicker animated:YES completion:nil];
  512. }
  513. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
  514. {
  515. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  516. NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
  517. __block NSError *error;
  518. [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
  519. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  520. NSString *fileName = [[NCUtility sharedInstance] createFileName:[url lastPathComponent] serverUrl:serverUrl account:appDelegate.activeAccount];
  521. NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
  522. NSData *data = [NSData dataWithContentsOfURL:newURL];
  523. if (data && error == nil) {
  524. if ([data writeToFile:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
  525. tableMetadata *metadataForUpload = [tableMetadata new];
  526. metadataForUpload.account = appDelegate.activeAccount;
  527. metadataForUpload.date = [NSDate new];
  528. metadataForUpload.ocId = ocId;
  529. metadataForUpload.fileName = fileName;
  530. metadataForUpload.fileNameView = fileName;
  531. metadataForUpload.serverUrl = serverUrl;
  532. metadataForUpload.session = k_upload_session;
  533. metadataForUpload.sessionSelector = selectorUploadFile;
  534. metadataForUpload.size = data.length;
  535. metadataForUpload.status = k_metadataStatusWaitUpload;
  536. // Check il file already exists
  537. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileName]];
  538. if (metadata) {
  539. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  540. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  541. // NO OVERWITE
  542. }];
  543. UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  544. // Remove record metadata
  545. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  546. // Add Medtadata for upload
  547. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  548. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  549. [appDelegate startLoadAutoDownloadUpload];
  550. }];
  551. [alertController addAction:cancelAction];
  552. [alertController addAction:overwriteAction];
  553. UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  554. alertWindow.rootViewController = [[UIViewController alloc]init];
  555. alertWindow.windowLevel = UIWindowLevelAlert + 1;
  556. [alertWindow makeKeyAndVisible];
  557. [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
  558. } else {
  559. // Add Medtadata for upload
  560. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  561. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  562. [appDelegate startLoadAutoDownloadUpload];
  563. }
  564. } else {
  565. [appDelegate messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  566. }
  567. } else {
  568. [appDelegate messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  569. }
  570. }];
  571. }
  572. }
  573. - (void)openImportDocumentPicker
  574. {
  575. UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
  576. documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
  577. documentProviderMenu.popoverPresentationController.sourceView = self.tabBarController.tabBar;
  578. documentProviderMenu.popoverPresentationController.sourceRect = self.tabBarController.tabBar.bounds;
  579. documentProviderMenu.delegate = self;
  580. [self presentViewController:documentProviderMenu animated:YES completion:nil];
  581. }
  582. #pragma --------------------------------------------------------------------------------------------
  583. #pragma mark ===== Assets Picker =====
  584. #pragma --------------------------------------------------------------------------------------------
  585. -(void)dismissFormUploadAssets
  586. {
  587. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  588. }
  589. - (void)openAssetsPickerController
  590. {
  591. NCPhotosPickerViewController *viewController = [[NCPhotosPickerViewController alloc] init:self maxSelectedAssets:100];
  592. [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nonnull assets) {
  593. if (assets.count > 0) {
  594. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  595. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  596. NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets cryptated:NO session:k_upload_session delegate:self];
  597. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
  598. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  599. [self presentViewController:navigationController animated:YES completion:nil];
  600. });
  601. }
  602. }];
  603. }
  604. #pragma --------------------------------------------------------------------------------------------
  605. #pragma mark ===== Save selected File =====
  606. #pragma --------------------------------------------------------------------------------------------
  607. - (void)saveToPhotoAlbum:(tableMetadata *)metadata
  608. {
  609. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
  610. PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
  611. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
  612. UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
  613. if (image)
  614. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  615. else
  616. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  617. }
  618. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
  619. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
  620. UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  621. } else {
  622. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  623. }
  624. }
  625. if (status != PHAuthorizationStatusAuthorized) {
  626. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  627. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  628. [alertController addAction:okAction];
  629. [self presentViewController:alertController animated:YES completion:nil];
  630. }
  631. }
  632. - (void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  633. {
  634. if (error)
  635. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  636. else
  637. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  638. }
  639. - (void)saveSelectedFiles
  640. {
  641. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  642. return;
  643. NSLog(@"[LOG] Start download selected files ...");
  644. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  645. NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  646. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  647. for (tableMetadata *metadata in metadatas) {
  648. if (metadata.directory == NO && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
  649. metadata.session = k_download_session;
  650. metadata.sessionError = @"";
  651. metadata.sessionSelector = selectorSave;
  652. metadata.status = k_metadataStatusWaitDownload;
  653. // Add Metadata for Download
  654. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  655. [appDelegate startLoadAutoDownloadUpload];
  656. }
  657. }
  658. [_hud hideHud];
  659. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  660. });
  661. [self tableViewSelect:NO];
  662. }
  663. #pragma --------------------------------------------------------------------------------------------
  664. #pragma mark ==== View Notification ====
  665. #pragma --------------------------------------------------------------------------------------------
  666. - (void)viewNotification
  667. {
  668. if ([appDelegate.listOfNotifications count] > 0) {
  669. CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
  670. [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
  671. [self presentViewController:notificationVC animated:YES completion:nil];
  672. }
  673. }
  674. #pragma mark -
  675. #pragma --------------------------------------------------------------------------------------------
  676. #pragma mark ===== Peek & Pop =====
  677. #pragma --------------------------------------------------------------------------------------------
  678. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  679. {
  680. CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];
  681. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
  682. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  683. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  684. if (cell) {
  685. previewingContext.sourceRect = cell.frame;
  686. CCPeekPop *viewController = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  687. viewController.metadata = metadata;
  688. viewController.imageFile = cell.file.image;
  689. viewController.showOpenIn = true;
  690. viewController.showShare = true;
  691. return viewController;
  692. }
  693. return nil;
  694. }
  695. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  696. {
  697. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  698. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  699. }
  700. #pragma --------------------------------------------------------------------------------------------
  701. #pragma mark ==== Download ====
  702. #pragma --------------------------------------------------------------------------------------------
  703. - (void)downloadSelectedFilesFolders
  704. {
  705. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  706. return;
  707. NSLog(@"[LOG] Start download selected ...");
  708. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  709. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  710. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  711. for (tableMetadata *metadata in selectedMetadatas) {
  712. if (metadata.directory) {
  713. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  714. } else {
  715. [[CCSynchronize sharedSynchronize] readFile:metadata.ocId fileName:metadata.fileName serverUrl:metadata.serverUrl selector:selectorReadFileWithDownload account:appDelegate.activeAccount];
  716. }
  717. }
  718. [_hud hideHud];
  719. });
  720. [self tableViewSelect:NO];
  721. }
  722. #pragma --------------------------------------------------------------------------------------------
  723. #pragma mark ===== Upload new Photos/Videos =====
  724. #pragma --------------------------------------------------------------------------------------------
  725. //
  726. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  727. //
  728. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  729. {
  730. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  731. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
  732. // if request create the folder for Auto Upload & the subfolders
  733. if ([autoUploadPath isEqualToString:serverUrl])
  734. if (![[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
  735. return;
  736. dispatch_async(dispatch_get_main_queue(), ^{
  737. [self uploadFileAsset:assets serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
  738. });
  739. });
  740. }
  741. - (void)uploadFileAsset:(NSArray *)assets serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  742. {
  743. for (PHAsset *asset in assets) {
  744. tableMetadata *metadata;
  745. NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType keyFileNameOriginal:k_keyFileNameOriginal];
  746. NSDate *assetDate = asset.creationDate;
  747. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  748. // Create serverUrl if use sub folder
  749. if (useSubFolder) {
  750. [formatter setDateFormat:@"yyyy"];
  751. NSString *yearString = [formatter stringFromDate:assetDate];
  752. [formatter setDateFormat:@"MM"];
  753. NSString *monthString = [formatter stringFromDate:assetDate];
  754. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
  755. }
  756. // Check if is in upload
  757. NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", appDelegate.activeAccount, serverUrl, fileName] sorted:nil ascending:NO];
  758. if ([isRecordInSessions count] > 0)
  759. continue;
  760. // Prepare record metadata
  761. tableMetadata *metadataForUpload = [tableMetadata new];
  762. metadataForUpload.account = appDelegate.activeAccount;
  763. metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
  764. metadataForUpload.date = [NSDate new];
  765. metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
  766. metadataForUpload.fileName = fileName;
  767. metadataForUpload.fileNameView = fileName;
  768. metadataForUpload.serverUrl = serverUrl;
  769. metadataForUpload.session = session;
  770. metadataForUpload.sessionSelector = selectorUploadFile;
  771. metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
  772. metadataForUpload.status = k_metadataStatusWaitUpload;
  773. NSString *fileNameExtension = [fileName pathExtension];
  774. NSString *fileNameWithoutExtension = [fileName stringByDeletingPathExtension];
  775. if ([[fileNameExtension lowercaseString] isEqualToString:@"heic"] && [CCUtility getFormatCompatibility]) {
  776. NSString *fileNameCompatibility = [fileNameWithoutExtension stringByAppendingString:@".jpg"];
  777. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileNameCompatibility]];
  778. } else {
  779. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileName]];
  780. }
  781. // Check il file already exists
  782. if (metadata) {
  783. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileNameWithoutExtension message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  784. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }];
  785. UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  786. // Remove record metadata
  787. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  788. // Add Medtadata for upload
  789. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  790. [appDelegate startLoadAutoDownloadUpload];
  791. }];
  792. [alertController addAction:cancelAction];
  793. [alertController addAction:overwriteAction];
  794. UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  795. alertWindow.rootViewController = [[UIViewController alloc]init];
  796. alertWindow.windowLevel = UIWindowLevelAlert + 1;
  797. [alertWindow makeKeyAndVisible];
  798. [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
  799. } else {
  800. // Add Medtadata for upload
  801. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  802. [appDelegate startLoadAutoDownloadUpload];
  803. }
  804. }
  805. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  806. }
  807. #pragma --------------------------------------------------------------------------------------------
  808. #pragma mark ==== Read File ====
  809. #pragma --------------------------------------------------------------------------------------------
  810. - (void)readFileReloadFolder
  811. {
  812. if (!_serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode)
  813. return;
  814. // Load Datasource
  815. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  816. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  817. });
  818. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:_serverUrl fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
  819. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  820. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  821. // Read folder: No record, Change etag or BLINK
  822. if ([sectionDataSource.allRecordsDataSource count] == 0 || [metadata.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
  823. [self readFolder:metadata.serverUrl];
  824. }
  825. } else if (errorCode != 0) {
  826. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  827. } else {
  828. NSLog(@"[LOG] It has been changed user during networking process, error.");
  829. }
  830. }];
  831. }
  832. #pragma --------------------------------------------------------------------------------------------
  833. #pragma mark ==== Read Folder ====
  834. #pragma --------------------------------------------------------------------------------------------
  835. - (void)insertMetadatasWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas
  836. {
  837. // stoprefresh
  838. [refreshControl endRefreshing];
  839. // save metadataFolder
  840. _metadataFolder = metadataFolder;
  841. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
  842. if (tableAccount == nil) {
  843. return;
  844. }
  845. if (_isSearchMode == NO) {
  846. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag ocId:metadataFolder.ocId encrypted:metadataFolder.e2eEncrypted account:account];
  847. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide]];
  848. [[NCManageDatabase sharedInstance] setDateReadDirectoryWithServerUrl:serverUrl account:account];
  849. }
  850. NSArray *metadatasInDownload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError] sorted:nil ascending:NO];
  851. // insert in Database
  852. NSMutableArray *metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas];
  853. // insert in Database the /
  854. if (metadataFolder != nil) {
  855. _metadataFolder = [[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
  856. }
  857. // reinsert metadatas in Download
  858. if (metadatasInDownload) {
  859. (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload];
  860. }
  861. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  862. // File is changed ??
  863. if (!_isSearchMode && metadatasToInsertInDB)
  864. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:serverUrl account:account withDownload:NO];
  865. });
  866. // Search Mode
  867. if (_isSearchMode) {
  868. // Fix managed -> Unmanaged _searchResultMetadatas
  869. if (metadatasToInsertInDB)
  870. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
  871. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  872. }
  873. // this is the same directory
  874. if ([serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
  875. // reload
  876. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  877. [self tableViewReloadData];
  878. }
  879. // E2EE Is encrypted folder get metadata
  880. if (_metadataFolder.e2eEncrypted) {
  881. NSString *metadataFolderocId = metadataFolder.ocId;
  882. // Read Metadata
  883. if ([CCUtility isEndToEndEnabled:account]) {
  884. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  885. NSString *metadata;
  886. NSError *error = [[NCNetworkingEndToEnd sharedManager] getEndToEndMetadata:&metadata ocId:metadataFolderocId user:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] url:tableAccount.url];
  887. dispatch_async(dispatch_get_main_queue(), ^{
  888. if (error) {
  889. if (error.code != kOCErrorServerPathNotFound)
  890. [appDelegate messageNotification:@"_e2e_error_get_metadata_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  891. } else {
  892. if ([[NCEndToEndMetadata sharedInstance] decoderMetadata:metadata privateKey:[CCUtility getEndToEndPrivateKey:account] serverUrl:self.serverUrl account:account url:tableAccount.url] == false)
  893. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  894. else
  895. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  896. }
  897. });
  898. });
  899. } else {
  900. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  901. }
  902. }
  903. // rewrite title
  904. [self setTitle];
  905. }
  906. - (void)readFolder:(NSString *)serverUrl
  907. {
  908. // init control
  909. if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
  910. [refreshControl endRefreshing];
  911. return;
  912. }
  913. // Search Mode
  914. if (_isSearchMode) {
  915. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  916. _searchFileName = @""; // forced reload searchg
  917. [self updateSearchResultsForSearchController:self.searchController];
  918. return;
  919. }
  920. _loadingFolder = YES;
  921. [self tableViewReloadData];
  922. [[OCNetworking sharedManager] readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
  923. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  924. [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
  925. } else if (errorCode != 0) {
  926. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  927. } else {
  928. NSLog(@"[LOG] It has been changed user during networking process, error.");
  929. }
  930. _loadingFolder = NO;
  931. }];
  932. }
  933. #pragma mark -
  934. #pragma --------------------------------------------------------------------------------------------
  935. #pragma mark ===== Search =====
  936. #pragma --------------------------------------------------------------------------------------------
  937. - (void)searchEnabled:(BOOL)enabled
  938. {
  939. if (enabled) {
  940. if (self.tableView.tableHeaderView != nil)
  941. return;
  942. self.definesPresentationContext = YES;
  943. self.searchController.searchResultsUpdater = self;
  944. self.searchController.dimsBackgroundDuringPresentation = NO;
  945. self.searchController.searchBar.translucent = NO;
  946. [self.searchController.searchBar sizeToFit];
  947. self.searchController.searchBar.delegate = self;
  948. self.searchController.searchBar.barTintColor = NCBrandColor.sharedInstance.brand;
  949. self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.brand;
  950. self.searchController.searchBar.backgroundImage = [UIImage new];
  951. // color searchbbar button text (cancel)
  952. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  953. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  954. [searchButton setTitleColor:NCBrandColor.sharedInstance.brandText forState:UIControlStateNormal];
  955. }
  956. // color textview searchbbar
  957. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  958. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  959. searchTextView.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  960. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  961. }
  962. self.tableView.tableHeaderView = self.searchController.searchBar;
  963. [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
  964. } else {
  965. self.tableView.tableHeaderView = nil;
  966. }
  967. }
  968. - (void)searchStartTimer
  969. {
  970. NSString *startDirectory = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  971. [[OCNetworking sharedManager] searchWithAccount:appDelegate.activeAccount fileName:_searchFileName serverUrl:startDirectory contentType:nil lteDateLastModified:nil gteDateLastModified:nil depth:@"infinity" completion:^(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode) {
  972. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  973. #if TARGET_OS_SIMULATOR
  974. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:account];
  975. if (capabilities.isFulltextsearchEnabled) {
  976. [[OCNetworking sharedManager] fullTextSearchWithAccount:appDelegate.activeAccount text:_searchFileName page:1 completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
  977. NSLog(@"x");
  978. }];
  979. }
  980. #endif
  981. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
  982. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  983. } else {
  984. if (errorCode != 0) {
  985. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  986. } else {
  987. NSLog(@"[LOG] It has been changed user during networking process, error.");
  988. }
  989. _searchFileName = @"";
  990. }
  991. }];
  992. _noFilesSearchTitle = @"";
  993. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  994. [self.tableView reloadEmptyDataSet];
  995. }
  996. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  997. {
  998. // Color text "Cancel"
  999. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:NCBrandColor.sharedInstance.brandText];
  1000. _isSearchMode = YES;
  1001. [self deleteRefreshControl];
  1002. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  1003. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1004. _searchFileName = fileName;
  1005. // First : filter
  1006. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView CONTAINS[cd] %@", appDelegate.activeAccount, _serverUrl, fileName] sorted:nil ascending:NO];
  1007. [_searchResultMetadatas removeAllObjects];
  1008. for (tableMetadata *record in records)
  1009. [_searchResultMetadatas addObject:record];
  1010. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  1011. // Version >= 12
  1012. if ([[NCManageDatabase sharedInstance] getServerVersionWithAccount:appDelegate.activeAccount] >= 12) {
  1013. [_timerWaitInput invalidate];
  1014. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1015. }
  1016. }
  1017. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1018. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1019. }
  1020. }
  1021. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1022. {
  1023. [self cancelSearchBar];
  1024. [self readFolder:_serverUrl];
  1025. }
  1026. - (void)cancelSearchBar
  1027. {
  1028. if (self.searchController.active) {
  1029. [self.searchController setActive:NO];
  1030. [self createRefreshControl];
  1031. _isSearchMode = NO;
  1032. _searchFileName = @"";
  1033. _dateReadDataSource = nil;
  1034. _searchResultMetadatas = [NSMutableArray new];
  1035. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1036. }
  1037. //[self setNeedsStatusBarAppearanceUpdate];
  1038. }
  1039. #pragma mark -
  1040. #pragma --------------------------------------------------------------------------------------------
  1041. #pragma mark ===== Delete File or Folder =====
  1042. #pragma --------------------------------------------------------------------------------------------
  1043. - (void)deleteFile
  1044. {
  1045. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1046. return;
  1047. NSArray *metadatas;
  1048. if ([_selectedocIdsMetadatas count] > 0) {
  1049. metadatas = [_selectedocIdsMetadatas allValues];
  1050. } else {
  1051. metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
  1052. }
  1053. // remove optimization
  1054. _dateReadDataSource = nil;
  1055. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:_metadataFolder.e2eEncrypted serverUrl:self.serverUrl folderocId:_metadataFolder.ocId completion:^(NSInteger errorCode, NSString *message) {
  1056. // Reload
  1057. if (_isSearchMode)
  1058. [self readFolder:self.serverUrl];
  1059. else
  1060. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1061. }];
  1062. // End Select Table View
  1063. [self tableViewSelect:NO];
  1064. }
  1065. #pragma --------------------------------------------------------------------------------------------
  1066. #pragma mark ===== Rename =====
  1067. #pragma --------------------------------------------------------------------------------------------
  1068. - (void)renameFile:(NSArray *)arguments
  1069. {
  1070. tableMetadata *metadata = [arguments objectAtIndex:0];
  1071. NSString *fileName = [arguments objectAtIndex:1];
  1072. // E2EE
  1073. if (_metadataFolder.e2eEncrypted) {
  1074. // verify if exists the new fileName
  1075. if ([[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, self.serverUrl, fileName]]) {
  1076. [appDelegate messageNotification:@"_error_e2ee_" description:@"_file_already_exists_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  1077. return;
  1078. }
  1079. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  1080. NSError *error = [[NCNetworkingEndToEnd sharedManager] sendEndToEndMetadataOnServerUrl:self.serverUrl fileNameRename:metadata.fileName fileNameNewRename:fileName account:appDelegate.activeAccount user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1081. if (error) {
  1082. dispatch_async(dispatch_get_main_queue(), ^{
  1083. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_send_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1084. });
  1085. } else {
  1086. [[NCManageDatabase sharedInstance] setMetadataFileNameViewWithServerUrl:metadata.serverUrl fileName:metadata.fileName newFileNameView:fileName account:appDelegate.activeAccount];
  1087. // Move file system
  1088. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileNameView];
  1089. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileName];
  1090. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1091. [[NSFileManager defaultManager] moveItemAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileName] error:nil];
  1092. }
  1093. // Unlock
  1094. tableE2eEncryptionLock *tableLock = [[NCManageDatabase sharedInstance] getE2ETokenLockWithServerUrl:self.serverUrl];
  1095. if (tableLock != nil) {
  1096. NSError *error = [[NCNetworkingEndToEnd sharedManager] unlockEndToEndFolderEncryptedOnServerUrl:self.serverUrl ocId:_metadataFolder.ocId token:tableLock.token user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1097. if (error) {
  1098. dispatch_async(dispatch_get_main_queue(), ^{
  1099. [appDelegate messageNotification:@"_e2e_error_unlock_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1100. });
  1101. }
  1102. }
  1103. dispatch_async(dispatch_get_main_queue(), ^{
  1104. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1105. });
  1106. });
  1107. } else {
  1108. // Plain
  1109. NSString *fileNameNew = [CCUtility removeForbiddenCharactersServer:fileName];
  1110. if ([fileName length] == 0 || [fileName isEqualToString:metadata.fileNameView]) {
  1111. return;
  1112. }
  1113. // Verify if exists the fileName TO
  1114. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:metadata.serverUrl fileName:fileNameNew completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1115. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1116. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1117. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }];
  1118. [alert addAction:ok];
  1119. [self presentViewController:alert animated:YES completion:nil];
  1120. } else if (errorCode != 0) {
  1121. if (errorCode == kOCErrorServerPathNotFound) {
  1122. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1123. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
  1124. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1125. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1126. // Rename metadata
  1127. (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:fileNameNew ocId:metadata.ocId];
  1128. if (metadata.directory) {
  1129. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  1130. NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:fileNameNew];
  1131. tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  1132. if (directoryTable == nil) {
  1133. [appDelegate messageNotification:@"_rename_" description:@"Internal error, ServerUrl not found" visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  1134. return;
  1135. }
  1136. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:@"" ocId:nil encrypted:directoryTable.e2eEncrypted account:appDelegate.activeAccount];
  1137. } else {
  1138. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:metadata.ocId date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:fileNameNew etag:nil];
  1139. // Move file system
  1140. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileName];
  1141. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileNameNew];
  1142. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1143. NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileName];
  1144. NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileNameNew];
  1145. [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
  1146. }
  1147. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1148. } else if (errorCode != 0) {
  1149. [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1150. } else {
  1151. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1152. }
  1153. }];
  1154. } else {
  1155. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1156. }
  1157. } else {
  1158. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1159. }
  1160. }];
  1161. }
  1162. }
  1163. #pragma --------------------------------------------------------------------------------------------
  1164. #pragma mark ===== Move =====
  1165. #pragma --------------------------------------------------------------------------------------------
  1166. - (void)moveFileOrFolderMetadata:(tableMetadata *)metadata serverUrlTo:(NSString *)serverUrlTo numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1167. {
  1168. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:serverUrlTo fileName:metadata.fileName completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1169. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1170. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1171. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1172. }];
  1173. [alert addAction:ok];
  1174. [self presentViewController:alert animated:YES completion:nil];
  1175. // End Select Table View
  1176. [self tableViewSelect:NO];
  1177. // reload Datasource
  1178. [self readFileReloadFolder];
  1179. } else if (errorCode != 0) {
  1180. if (errorCode == kOCErrorServerPathNotFound) {
  1181. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1182. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
  1183. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1184. [_hud hideHud];
  1185. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1186. if (metadata.directory) {
  1187. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] account:account];
  1188. }
  1189. [[NCManageDatabase sharedInstance] moveMetadataWithOcId:metadata.ocId serverUrlTo:serverUrlTo];
  1190. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:account];
  1191. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrlTo account:account];
  1192. // next
  1193. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  1194. if ([_selectedocIdsMetadatas count] > 0) {
  1195. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1196. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrlTo numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1197. } else {
  1198. // End Select Table View
  1199. [self tableViewSelect:NO];
  1200. // reload Datasource
  1201. if (_isSearchMode)
  1202. [self readFolder:metadata.serverUrl];
  1203. else
  1204. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1205. }
  1206. } else if (errorCode != 0) {
  1207. [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1208. // End Select Table View
  1209. [self tableViewSelect:NO];
  1210. // reload Datasource
  1211. if (_isSearchMode)
  1212. [self readFolder:metadata.serverUrl];
  1213. else
  1214. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:nil action:k_action_NULL];
  1215. } else {
  1216. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1217. }
  1218. }];
  1219. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1220. } else {
  1221. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1222. }
  1223. } else {
  1224. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1225. }
  1226. }];
  1227. }
  1228. // DELEGATE : Select
  1229. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  1230. {
  1231. if (serverUrl == nil) {
  1232. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1233. } else {
  1234. // E2EE DENIED
  1235. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) {
  1236. [appDelegate messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  1237. return;
  1238. }
  1239. if ([_selectedocIdsMetadatas count] > 0) {
  1240. _numSelectedocIdsMetadatas = [_selectedocIdsMetadatas count];
  1241. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1242. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrl numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1243. } else {
  1244. _numSelectedocIdsMetadatas = 1;
  1245. [self moveFileOrFolderMetadata:self.metadata serverUrlTo:serverUrl numFile:1 ofFile:_numSelectedocIdsMetadatas];
  1246. }
  1247. }
  1248. }
  1249. - (void)moveOpenWindow:(NSArray *)indexPaths
  1250. {
  1251. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1252. return;
  1253. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  1254. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  1255. viewController.delegate = self;
  1256. viewController.hideButtonCreateFolder = false;
  1257. viewController.selectFile = false;
  1258. viewController.includeDirectoryE2EEncryption = false;
  1259. viewController.includeImages = false;
  1260. viewController.type = @"";
  1261. viewController.titleButtonDone = NSLocalizedString(@"_move_", nil);
  1262. viewController.layoutViewSelect = k_layout_view_move;
  1263. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  1264. [self presentViewController:navigationController animated:YES completion:nil];
  1265. }
  1266. #pragma --------------------------------------------------------------------------------------------
  1267. #pragma mark ===== Create folder =====
  1268. #pragma --------------------------------------------------------------------------------------------
  1269. - (void)createFolder
  1270. {
  1271. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  1272. NSString *message;
  1273. UIAlertController *alertController;
  1274. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  1275. message = @"/";
  1276. } else {
  1277. message = [serverUrl lastPathComponent];
  1278. }
  1279. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  1280. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1281. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  1282. textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
  1283. }];
  1284. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1285. NSLog(@"[LOG] Cancel action");
  1286. }];
  1287. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1288. UITextField *fileName = alertController.textFields.firstObject;
  1289. [self createFolder:fileName.text serverUrl:serverUrl];
  1290. }];
  1291. okAction.enabled = NO;
  1292. [alertController addAction:cancelAction];
  1293. [alertController addAction:okAction];
  1294. [self presentViewController:alertController animated:YES completion:nil];
  1295. }
  1296. - (void)createFolder:(NSString *)fileNameFolder serverUrl:(NSString *)serverUrl
  1297. {
  1298. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1299. if (![fileNameFolder length]) return;
  1300. NSString *ocIdTemp = [[NSUUID UUID] UUIDString];
  1301. // Create Directory (temp) on metadata
  1302. tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:YES ocId:ocIdTemp serverUrl:serverUrl fileName:fileNameFolder etag:@"" size:0 status:k_metadataStatusNormal url:@""];
  1303. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1304. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  1305. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1306. // Creeate folder Networking
  1307. [[OCNetworking sharedManager] createFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileNameFolder completion:^(NSString *account, NSString *ocId, NSDate *date, NSString *message, NSInteger errorCode) {
  1308. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1309. // Delete Temp Dir
  1310. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1311. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrl, fileNameFolder];
  1312. if (_metadataFolder.e2eEncrypted) {
  1313. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1314. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:newDirectory ocId:ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1315. dispatch_async(dispatch_get_main_queue(), ^{
  1316. if (error) {
  1317. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1318. }
  1319. [self readFolder:self.serverUrl];
  1320. });
  1321. });
  1322. } else {
  1323. [self readFolder:self.serverUrl];
  1324. }
  1325. } else {
  1326. // Delete Temp Dir
  1327. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1328. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1329. if (errorCode != 0) {
  1330. [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1331. } else {
  1332. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1333. }
  1334. }
  1335. }];
  1336. }
  1337. #pragma --------------------------------------------------------------------------------------------
  1338. #pragma mark ===== Progress & Task Button =====
  1339. #pragma --------------------------------------------------------------------------------------------
  1340. - (void)triggerProgressTask:(NSNotification *)notification
  1341. {
  1342. if (sectionDataSource.ocIdIndexPath != nil) {
  1343. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
  1344. }
  1345. }
  1346. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1347. {
  1348. UITouch *touch = [[event allTouches] anyObject];
  1349. CGPoint location = [touch locationInView:self.tableView];
  1350. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1351. if ([self indexPathIsValid:indexPath]) {
  1352. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1353. if (metadataSection) {
  1354. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataSection.ocId]];
  1355. if (metadata)
  1356. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  1357. }
  1358. }
  1359. }
  1360. - (void)cancelAllTask:(id)sender
  1361. {
  1362. CGPoint location = [sender locationInView:self.tableView];
  1363. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1364. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1365. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1366. [NCUtility.sharedInstance startActivityIndicatorWithView:self.view bottom:0];
  1367. [[NCMainCommon sharedInstance] cancelAllTransfer];
  1368. [NCUtility.sharedInstance stopActivityIndicator];
  1369. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:nil ocId:nil action:k_action_NULL];
  1370. }]];
  1371. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  1372. alertController.popoverPresentationController.sourceView = self.tableView;
  1373. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1374. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1375. [alertController.view layoutIfNeeded];
  1376. [self presentViewController:alertController animated:YES completion:nil];
  1377. }
  1378. #pragma --------------------------------------------------------------------------------------------
  1379. #pragma mark ===== Tap =====
  1380. #pragma --------------------------------------------------------------------------------------------
  1381. - (void)tapActionComment:(UITapGestureRecognizer *)tapGesture
  1382. {
  1383. CGPoint location = [tapGesture locationInView:self.tableView];
  1384. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1385. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1386. if (metadata) {
  1387. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:1];
  1388. }
  1389. }
  1390. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  1391. {
  1392. CGPoint location = [tapGesture locationInView:self.tableView];
  1393. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1394. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1395. if (metadata) {
  1396. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  1397. }
  1398. }
  1399. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  1400. {
  1401. CGPoint location = [tapGesture locationInView:self.tableView];
  1402. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1403. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1404. if (metadata) {
  1405. }
  1406. }
  1407. #pragma --------------------------------------------------------------------------------------------
  1408. #pragma mark ===== Favorite =====
  1409. #pragma --------------------------------------------------------------------------------------------
  1410. - (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
  1411. {
  1412. NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
  1413. [[NCCommunication sharedInstance] setFavoriteWithUrlString:appDelegate.activeUrl fileName:fileNameServerUrl favorite:favorite account:appDelegate.activeAccount completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDecription) {
  1414. if (errorCode == 0 && [appDelegate.activeAccount isEqualToString:account]) {
  1415. [[NCManageDatabase sharedInstance] setMetadataFavoriteWithOcId:metadata.ocId favorite:favorite];
  1416. _dateReadDataSource = nil;
  1417. if (_isSearchMode)
  1418. [self readFolder:self.serverUrl];
  1419. else
  1420. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1421. if (metadata.directory && favorite) {
  1422. NSString *selector;
  1423. if ([CCUtility getFavoriteOffline])
  1424. selector = selectorReadFolderWithDownload;
  1425. else
  1426. selector = selectorReadFolder;
  1427. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName] selector:selector account:appDelegate.activeAccount];
  1428. }
  1429. if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
  1430. metadata.favorite = favorite;
  1431. metadata.session = k_download_session;
  1432. metadata.sessionError = @"";
  1433. metadata.sessionSelector = selectorDownloadSynchronize;
  1434. metadata.status = k_metadataStatusWaitDownload;
  1435. // Add Metadata for Download
  1436. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1437. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1438. [appDelegate startLoadAutoDownloadUpload];
  1439. }
  1440. } else if (errorCode != 0) {
  1441. [appDelegate messageNotification:@"_error_" description:errorDecription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1442. } else {
  1443. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1444. }
  1445. }];
  1446. }
  1447. #pragma --------------------------------------------------------------------------------------------
  1448. #pragma mark ==== Menu LOGO ====
  1449. #pragma --------------------------------------------------------------------------------------------
  1450. - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
  1451. {
  1452. if (appDelegate.reSelectMenu.isOpen || appDelegate.reMainMenu.isOpen)
  1453. return;
  1454. // Brand
  1455. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  1456. return;
  1457. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  1458. NSMutableArray *menuArray = [NSMutableArray new];
  1459. for (NSString *account in listAccount) {
  1460. CCMenuItem *item = [[CCMenuItem alloc] init];
  1461. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  1462. item.argument = account;
  1463. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
  1464. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
  1465. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  1466. if (avatar) {
  1467. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
  1468. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  1469. CGSize imageSize = avatarImageView.bounds.size;
  1470. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1471. CGContextRef context = UIGraphicsGetCurrentContext();
  1472. [avatarImageView.layer renderInContext:context];
  1473. avatar = UIGraphicsGetImageFromCurrentImageContext();
  1474. UIGraphicsEndImageContext();
  1475. } else {
  1476. avatar = [UIImage imageNamed:@"menuLogoUser"];
  1477. }
  1478. item.image = avatar;
  1479. item.target = self;
  1480. if ([account isEqualToString:appDelegate.activeAccount]) {
  1481. item.action = nil;
  1482. [menuArray insertObject:item atIndex:0];
  1483. } else {
  1484. item.action = @selector(changeDefaultAccount:);
  1485. [menuArray addObject:item];
  1486. }
  1487. }
  1488. // Add + new account
  1489. CCMenuItem *item = [[CCMenuItem alloc] init];
  1490. item.title = NSLocalizedString(@"_add_account_", nil);
  1491. item.argument = @"";
  1492. item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] width:50 height:50 color:NCBrandColor.sharedInstance.textView];
  1493. item.target = self;
  1494. item.action = @selector(addNewAccount:);
  1495. [menuArray addObject:item];
  1496. OptionalConfiguration options;
  1497. Color backgroundColor;
  1498. const CGFloat *componentsBackgroundColor = CGColorGetComponents(NCBrandColor.sharedInstance.backgroundForm.CGColor);
  1499. backgroundColor.R = componentsBackgroundColor[0];
  1500. backgroundColor.G = componentsBackgroundColor[1];
  1501. backgroundColor.B = componentsBackgroundColor[2];
  1502. options.arrowSize = 9;
  1503. options.marginXSpacing = 7;
  1504. options.marginYSpacing = 10;
  1505. options.intervalSpacing = 20;
  1506. options.menuCornerRadius = 6.5;
  1507. options.maskToBackground = NO;
  1508. options.shadowOfMenu = YES;
  1509. options.hasSeperatorLine = YES;
  1510. options.seperatorLineHasInsets = YES;
  1511. options.textColor = NCBrandColor.sharedInstance.textView;
  1512. options.menuBackgroundColor = backgroundColor;
  1513. options.separatorColor = NCBrandColor.sharedInstance.separator;
  1514. CGRect rect = self.view.frame;
  1515. CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
  1516. CGFloat safeAreaTop = 0;
  1517. CGFloat offsetY = 35;
  1518. if (@available(iOS 11, *)) {
  1519. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
  1520. }
  1521. rect.origin.y = locationY + safeAreaTop + offsetY;
  1522. rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
  1523. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  1524. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  1525. }
  1526. - (void)changeDefaultAccount:(CCMenuItem *)sender
  1527. {
  1528. // LOGOUT
  1529. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  1530. if (tableAccount) {
  1531. // LOGIN
  1532. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  1533. // go to home sweet home
  1534. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  1535. }
  1536. }
  1537. - (void)addNewAccount:(CCMenuItem *)sender
  1538. {
  1539. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  1540. }
  1541. #pragma --------------------------------------------------------------------------------------------
  1542. #pragma mark ==== ReMenu ====
  1543. #pragma --------------------------------------------------------------------------------------------
  1544. - (void)createReMenuBackgroundView:(REMenu *)menu
  1545. {
  1546. CGFloat safeAreaBottom = 0;
  1547. CGFloat safeAreaTop = 0;
  1548. CGFloat statusBar = 0;
  1549. if (@available(iOS 11, *)) {
  1550. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  1551. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  1552. }
  1553. if ([UIApplication sharedApplication].isStatusBarHidden) {
  1554. statusBar = 13;
  1555. }
  1556. CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
  1557. UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
  1558. CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
  1559. _reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
  1560. [UIView animateWithDuration:0.2 animations:^{
  1561. CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
  1562. CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
  1563. if (y>minimum) {
  1564. _reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
  1565. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  1566. }
  1567. }];
  1568. }
  1569. - (void)createReMainMenu
  1570. {
  1571. NSString *title;
  1572. NSString *groupBy = [CCUtility getGroupBySettings];
  1573. NSString *sorted = [CCUtility getOrderSettings];
  1574. BOOL ascending = [CCUtility getAscendingSettings];
  1575. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  1576. appDelegate.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectLight"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1577. if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
  1578. }];
  1579. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  1580. if ([sorted isEqualToString:@"fileName"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_a_z_", nil)]; }
  1581. else title = NSLocalizedString(@"_order_by_name_a_z_", nil);
  1582. appDelegate.sortFileNameAZItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameAZ"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1583. [CCUtility setOrderSettings:@"fileName"];
  1584. [CCUtility setAscendingSettings:true];
  1585. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1586. }];
  1587. if ([sorted isEqualToString:@"fileName"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_z_a_", nil)]; }
  1588. else title = NSLocalizedString(@"_order_by_name_z_a_", nil);
  1589. appDelegate.sortFileNameZAItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameZA"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1590. [CCUtility setOrderSettings:@"fileName"];
  1591. [CCUtility setAscendingSettings:false];
  1592. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1593. }];
  1594. if ([sorted isEqualToString:@"date"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_more_recent_", nil)]; }
  1595. else title = NSLocalizedString(@"_order_by_date_more_recent_", nil);
  1596. appDelegate.sortDateMoreRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateMoreRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1597. [CCUtility setOrderSettings:@"date"];
  1598. [CCUtility setAscendingSettings:false];
  1599. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1600. }];
  1601. if ([sorted isEqualToString:@"date"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_less_recent_", nil)]; }
  1602. else title = NSLocalizedString(@"_order_by_date_less_recent_", nil);
  1603. appDelegate.sortDateLessRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateLessRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1604. [CCUtility setOrderSettings:@"date"];
  1605. [CCUtility setAscendingSettings:true];
  1606. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1607. }];
  1608. if ([sorted isEqualToString:@"size"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_smallest_", nil)]; }
  1609. else title = NSLocalizedString(@"_order_by_size_smallest_", nil);
  1610. appDelegate.sortSmallestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortSmallest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1611. [CCUtility setOrderSettings:@"size"];
  1612. [CCUtility setAscendingSettings:true];
  1613. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1614. }];
  1615. if ([sorted isEqualToString:@"size"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_largest_", nil)]; }
  1616. else title = NSLocalizedString(@"_order_by_size_largest_", nil);
  1617. appDelegate.sortLargestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortLargest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1618. [CCUtility setOrderSettings:@"size"];
  1619. [CCUtility setAscendingSettings:false];
  1620. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1621. }];
  1622. // ITEM GROUP ALPHABETIC -----------------------------------------------------------------------------------------------------
  1623. if ([groupBy isEqualToString:@"alphabetic"]) { title = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  1624. else { title = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  1625. appDelegate.alphabeticItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1626. if ([groupBy isEqualToString:@"alphabetic"]) [CCUtility setGroupBySettings:@"none"];
  1627. else [CCUtility setGroupBySettings:@"alphabetic"];
  1628. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1629. }];
  1630. // ITEM GROUP TYPEFILE -------------------------------------------------------------------------------------------------------
  1631. if ([groupBy isEqualToString:@"typefile"]) { title = NSLocalizedString(@"_group_typefile_yes_", nil); }
  1632. else { title = NSLocalizedString(@"_group_typefile_no_", nil); }
  1633. appDelegate.typefileItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1634. if ([groupBy isEqualToString:@"typefile"]) [CCUtility setGroupBySettings:@"none"];
  1635. else [CCUtility setGroupBySettings:@"typefile"];
  1636. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1637. }];
  1638. // ITEM GROUP DATE -------------------------------------------------------------------------------------------------------
  1639. if ([groupBy isEqualToString:@"date"]) { title = NSLocalizedString(@"_group_date_yes_", nil); }
  1640. else { title = NSLocalizedString(@"_group_date_no_", nil); }
  1641. appDelegate.dateItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1642. if ([groupBy isEqualToString:@"date"]) [CCUtility setGroupBySettings:@"none"];
  1643. else [CCUtility setGroupBySettings:@"date"];
  1644. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1645. }];
  1646. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  1647. if ([CCUtility getDirectoryOnTop]) { title = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  1648. else { title = NSLocalizedString(@"_directory_on_top_no_", nil); }
  1649. appDelegate.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"foldersOnTop"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1650. if ([CCUtility getDirectoryOnTop]) [CCUtility setDirectoryOnTop:NO];
  1651. else [CCUtility setDirectoryOnTop:YES];
  1652. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1653. }];
  1654. // REMENU --------------------------------------------------------------------------------------------------------------
  1655. appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem,appDelegate.alphabeticItem, appDelegate.typefileItem, appDelegate.dateItem, appDelegate.directoryOnTopItem]];
  1656. appDelegate.reMainMenu.itemHeight = 40;
  1657. appDelegate.reMainMenu.imageOffset = CGSizeMake(5, -1);
  1658. appDelegate.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1659. appDelegate.reMainMenu.imageOffset = CGSizeMake(0, 0);
  1660. appDelegate.reMainMenu.waitUntilAnimationIsComplete = NO;
  1661. appDelegate.reMainMenu.separatorHeight = 0.5;
  1662. appDelegate.reMainMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1663. appDelegate.reMainMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1664. appDelegate.reMainMenu.textColor = NCBrandColor.sharedInstance.textView;
  1665. appDelegate.reMainMenu.textAlignment = NSTextAlignmentLeft;
  1666. appDelegate.reMainMenu.textShadowColor = nil;
  1667. appDelegate.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  1668. appDelegate.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  1669. appDelegate.reMainMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1670. appDelegate.reMainMenu.highlightedSeparatorColor = nil;
  1671. appDelegate.reMainMenu.highlightedTextColor = [UIColor blackColor];
  1672. appDelegate.reMainMenu.highlightedTextShadowColor = nil;
  1673. appDelegate.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1674. appDelegate.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  1675. appDelegate.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1676. appDelegate.reMainMenu.subtitleTextShadowColor = nil;
  1677. appDelegate.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1678. appDelegate.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1679. appDelegate.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1680. appDelegate.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1681. appDelegate.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  1682. appDelegate.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1683. appDelegate.reMainMenu.borderWidth = 0;
  1684. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1685. appDelegate.reMainMenu.animationDuration = 0.2;
  1686. appDelegate.reMainMenu.closeAnimationDuration = 0.2;
  1687. appDelegate.reMainMenu.bounce = NO;
  1688. __weak typeof(self) weakSelf = self;
  1689. [appDelegate.reMainMenu setClosePreparationBlock:^{
  1690. // Backgroun reMenu (Gesture)
  1691. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1692. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1693. }];
  1694. }
  1695. - (void)toggleReMainMenu
  1696. {
  1697. if (appDelegate.reMainMenu.isOpen) {
  1698. [appDelegate.reMainMenu close];
  1699. } else {
  1700. [self createReMainMenu];
  1701. [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
  1702. // Backgroun reMenu & (Gesture)
  1703. [self createReMenuBackgroundView:appDelegate.reMainMenu];
  1704. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  1705. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1706. }
  1707. }
  1708. - (void)createReSelectMenu
  1709. {
  1710. // ITEM SELECT ALL --------------------------------------------------------------------------------------------------
  1711. appDelegate.selectAllItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_all_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectFull"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1712. [self didSelectAll];
  1713. }];
  1714. // ITEM MOVE --------------------------------------------------------------------------------------------------------
  1715. appDelegate.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1716. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  1717. }];
  1718. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  1719. appDelegate.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_folders_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"downloadSelectedFiles"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1720. [self downloadSelectedFilesFolders];
  1721. }];
  1722. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  1723. appDelegate.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"saveSelectedFiles"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1724. [self saveSelectedFiles];
  1725. }];
  1726. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  1727. appDelegate.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1728. [self deleteFile];
  1729. }];
  1730. // E2EE
  1731. if (_metadataFolder.e2eEncrypted) {
  1732. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1733. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1734. } else {
  1735. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1736. }
  1737. } else {
  1738. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1739. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1740. } else {
  1741. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1742. }
  1743. }
  1744. appDelegate.reSelectMenu.itemHeight = 50;
  1745. appDelegate.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  1746. appDelegate.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1747. appDelegate.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  1748. appDelegate.reSelectMenu.waitUntilAnimationIsComplete = NO;
  1749. appDelegate.reSelectMenu.separatorHeight = 0.5;
  1750. appDelegate.reSelectMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1751. appDelegate.reSelectMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1752. appDelegate.reSelectMenu.textColor = NCBrandColor.sharedInstance.textView;
  1753. appDelegate.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  1754. appDelegate.reSelectMenu.textShadowColor = nil;
  1755. appDelegate.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  1756. appDelegate.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  1757. appDelegate.reSelectMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1758. appDelegate.reSelectMenu.highlightedSeparatorColor = nil;
  1759. appDelegate.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  1760. appDelegate.reSelectMenu.highlightedTextShadowColor = nil;
  1761. appDelegate.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1762. appDelegate.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  1763. appDelegate.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1764. appDelegate.reSelectMenu.subtitleTextShadowColor = nil;
  1765. appDelegate.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1766. appDelegate.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1767. appDelegate.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1768. appDelegate.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1769. appDelegate.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  1770. appDelegate.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1771. appDelegate.reMainMenu.borderWidth = 0;
  1772. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1773. appDelegate.reSelectMenu.closeAnimationDuration = 0.2;
  1774. appDelegate.reSelectMenu.animationDuration = 0.2;
  1775. appDelegate.reSelectMenu.bounce = NO;
  1776. __weak typeof(self) weakSelf = self;
  1777. [appDelegate.reSelectMenu setClosePreparationBlock:^{
  1778. // Backgroun reMenu (Gesture)
  1779. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1780. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1781. }];
  1782. }
  1783. - (void)toggleReSelectMenu
  1784. {
  1785. if (appDelegate.reSelectMenu.isOpen) {
  1786. [appDelegate.reSelectMenu close];
  1787. } else {
  1788. [self createReSelectMenu];
  1789. [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
  1790. // Backgroun reMenu & (Gesture)
  1791. [self createReMenuBackgroundView:appDelegate.reSelectMenu];
  1792. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  1793. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1794. }
  1795. }
  1796. #pragma --------------------------------------------------------------------------------------------
  1797. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  1798. #pragma --------------------------------------------------------------------------------------------
  1799. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  1800. {
  1801. if (recognizer.state == UIGestureRecognizerStateBegan) {
  1802. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  1803. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  1804. if ([self indexPathIsValid:indexPath])
  1805. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1806. else
  1807. self.metadata = nil;
  1808. [self becomeFirstResponder];
  1809. UIMenuController *menuController = [UIMenuController sharedMenuController];
  1810. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  1811. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  1812. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  1813. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  1814. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  1815. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1816. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, pasteFileItem, pasteFilesItem, nil]];
  1817. } else {
  1818. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  1819. }
  1820. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  1821. [menuController setMenuVisible:YES animated:YES];
  1822. }
  1823. }
  1824. - (BOOL)canBecomeFirstResponder
  1825. {
  1826. return YES;
  1827. }
  1828. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  1829. {
  1830. // For copy file, copy files, Open in ... :
  1831. //
  1832. // NO Directory
  1833. // NO Error Passcode
  1834. // NO In Session mode (download/upload)
  1835. // NO Template
  1836. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  1837. if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
  1838. else return NO;
  1839. }
  1840. if (@selector(copyFiles:) == action) {
  1841. if (_isSelectedMode) {
  1842. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1843. for (tableMetadata *metadata in selectedMetadatas) {
  1844. if (!metadata.directory && metadata.status == k_metadataStatusNormal)
  1845. return YES;
  1846. }
  1847. }
  1848. return NO;
  1849. }
  1850. if (@selector(pasteFile:) == action) {
  1851. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1852. NSArray *items = [pasteboard items];
  1853. if ([items count] == 1) {
  1854. // Value : (NSData) ocId
  1855. NSDictionary *dic = [items objectAtIndex:0];
  1856. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1857. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1858. if (ocId) {
  1859. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1860. if (metadata) {
  1861. return [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView];
  1862. } else {
  1863. return NO;
  1864. }
  1865. }
  1866. }
  1867. return NO;
  1868. }
  1869. if (@selector(pasteFiles:) == action) {
  1870. BOOL isValid = NO;
  1871. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1872. NSArray *items = [pasteboard items];
  1873. if ([items count] <= 1) return NO;
  1874. for (NSDictionary *dic in items) {
  1875. // Value : (NSData) ocId
  1876. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1877. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1878. if (ocId) {
  1879. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1880. if (metadata) {
  1881. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1882. isValid = YES;
  1883. } else {
  1884. isValid = NO;
  1885. break;
  1886. }
  1887. } else {
  1888. isValid = NO;
  1889. break;
  1890. }
  1891. } else {
  1892. isValid = NO;
  1893. break;
  1894. }
  1895. }
  1896. return isValid;
  1897. }
  1898. return NO;
  1899. }
  1900. /************************************ COPY ************************************/
  1901. - (void)copyFile:(id)sender
  1902. {
  1903. // Remove all item
  1904. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1905. pasteboard.items = [[NSArray alloc] init];
  1906. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  1907. [self copyFileToPasteboard:self.metadata];
  1908. } else {
  1909. self.metadata.session = k_download_session;
  1910. self.metadata.sessionError = @"";
  1911. self.metadata.sessionSelector = selectorLoadCopy;
  1912. self.metadata.status = k_metadataStatusWaitDownload;
  1913. // Add Metadata for Download
  1914. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  1915. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  1916. [appDelegate startLoadAutoDownloadUpload];
  1917. }
  1918. }
  1919. - (void)copyFiles:(id)sender
  1920. {
  1921. // Remove all item
  1922. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1923. pasteboard.items = [[NSArray alloc] init];
  1924. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1925. for (tableMetadata *metadata in selectedMetadatas) {
  1926. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1927. [self copyFileToPasteboard:metadata];
  1928. } else {
  1929. metadata.session = k_download_session;
  1930. metadata.sessionError = @"";
  1931. metadata.sessionSelector = selectorLoadCopy;
  1932. metadata.status = k_metadataStatusWaitDownload;
  1933. // Add Metadata for Download
  1934. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1935. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1936. [appDelegate startLoadAutoDownloadUpload];
  1937. }
  1938. }
  1939. [self tableViewSelect:NO];
  1940. }
  1941. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  1942. {
  1943. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1944. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  1945. // Value : (NSData) ocId
  1946. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.ocId], k_metadataKeyedUnarchiver,nil];
  1947. [items addObject:item];
  1948. [pasteboard setItems:items];
  1949. }
  1950. /************************************ OPEN IN ... ******************************/
  1951. - (void)openinFile:(id)sender
  1952. {
  1953. [[NCMainCommon sharedInstance] downloadOpenInMetadata:self.metadata];
  1954. }
  1955. /************************************ PASTE ************************************/
  1956. - (void)pasteFile:(id)sender
  1957. {
  1958. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1959. [self uploadFilePasteArray:[pasteboard items]];
  1960. }
  1961. - (void)pasteFiles:(id)sender
  1962. {
  1963. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1964. [self uploadFilePasteArray:[pasteboard items]];
  1965. }
  1966. - (void)uploadFilePasteArray:(NSArray *)items
  1967. {
  1968. for (NSDictionary *dic in items) {
  1969. // Value : (NSData) ocId
  1970. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1971. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1972. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1973. if (metadata) {
  1974. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1975. NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView serverUrl:self.serverUrl account:appDelegate.activeAccount];
  1976. NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:self.serverUrl fileNameView:fileName directory:false];
  1977. [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName]];
  1978. tableMetadata *metadataForUpload = [tableMetadata new];
  1979. metadataForUpload.account = appDelegate.activeAccount;
  1980. metadataForUpload.date = [NSDate new];
  1981. metadataForUpload.ocId = ocId;
  1982. metadataForUpload.fileName = fileName;
  1983. metadataForUpload.fileNameView = fileName;
  1984. metadataForUpload.serverUrl = self.serverUrl;
  1985. metadataForUpload.session = k_upload_session;
  1986. metadataForUpload.sessionSelector = selectorUploadFile;
  1987. metadataForUpload.size = metadata.size;
  1988. metadataForUpload.status = k_metadataStatusWaitUpload;
  1989. // Add Medtadata for upload
  1990. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  1991. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1992. }
  1993. }
  1994. }
  1995. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1996. [appDelegate startLoadAutoDownloadUpload];
  1997. }
  1998. #pragma --------------------------------------------------------------------------------------------
  1999. #pragma mark ===== Lock Passcode =====
  2000. #pragma --------------------------------------------------------------------------------------------
  2001. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2002. {
  2003. return _failedAttempts;
  2004. }
  2005. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2006. {
  2007. return _lockUntilDate;
  2008. }
  2009. - (void)passcodeViewCloseButtonPressed:(id)sender
  2010. {
  2011. [self dismissViewControllerAnimated:YES completion:nil];
  2012. }
  2013. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2014. {
  2015. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2016. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2017. _lockUntilDate = nil;
  2018. _failedAttempts = 0;
  2019. aResultHandler(YES);
  2020. } else aResultHandler(NO);
  2021. } else aResultHandler(YES);
  2022. }
  2023. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2024. {
  2025. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2026. switch (aViewController.type) {
  2027. case BKPasscodeViewControllerCheckPasscodeType: {
  2028. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2029. // possiamo procedere alla prossima directory
  2030. [self performSegueDirectoryWithControlPasscode:false metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2031. // avviamo la sessione Passcode Lock con now
  2032. appDelegate.sessionePasscodeLock = [NSDate date];
  2033. }
  2034. // disattivazione lock cartella
  2035. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2036. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2037. if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO account:appDelegate.activeAccount]) {
  2038. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2039. }
  2040. [self tableViewReloadData];
  2041. }
  2042. }
  2043. break;
  2044. default:
  2045. break;
  2046. }
  2047. }
  2048. - (void)comandoLockPassword
  2049. {
  2050. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2051. // se non è abilitato il Lock Passcode esci
  2052. if ([[CCUtility getBlockCode] length] == 0) {
  2053. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) preferredStyle:UIAlertControllerStyleAlert];
  2054. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  2055. [alertController addAction:okAction];
  2056. [self presentViewController:alertController animated:YES completion:nil];
  2057. return;
  2058. }
  2059. // se è richiesta la disattivazione si chiede la password
  2060. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2061. if (directory.lock) {
  2062. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2063. viewController.delegate = self;
  2064. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2065. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2066. viewController.inputViewTitlePassword = YES;
  2067. if ([CCUtility getSimplyBlockCode]) {
  2068. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2069. viewController.passcodeInputView.maximumLength = 6;
  2070. } else {
  2071. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2072. viewController.passcodeInputView.maximumLength = 64;
  2073. }
  2074. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  2075. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2076. viewController.touchIDManager = touchIDManager;
  2077. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2078. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2079. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  2080. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2081. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  2082. [self presentViewController:navigationController animated:YES completion:nil];
  2083. return;
  2084. }
  2085. // ---------------- ACTIVATE PASSWORD
  2086. if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES account:appDelegate.activeAccount]) {
  2087. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:self.metadata.ocId];
  2088. if ([self indexPathIsValid:indexPath])
  2089. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2090. } else {
  2091. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2092. }
  2093. }
  2094. #pragma mark -
  2095. #pragma --------------------------------------------------------------------------------------------
  2096. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  2097. #pragma --------------------------------------------------------------------------------------------
  2098. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  2099. {
  2100. if (metadata == nil || _metadataFolder == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || metadata.status != k_metadataStatusNormal || [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])
  2101. return NO;
  2102. // E2EE
  2103. if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
  2104. return NO;
  2105. return YES;
  2106. }
  2107. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  2108. {
  2109. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2110. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2111. return [self canOpenMenuAction:metadata];
  2112. }
  2113. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  2114. {
  2115. }
  2116. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  2117. {
  2118. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2119. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2120. if (direction == MGSwipeDirectionRightToLeft) {
  2121. [self actionDelete:indexPath];
  2122. }
  2123. if (direction == MGSwipeDirectionLeftToRight) {
  2124. if (self.metadata.favorite)
  2125. [self settingFavorite:self.metadata favorite:NO];
  2126. else
  2127. [self settingFavorite:self.metadata favorite:YES];
  2128. }
  2129. return YES;
  2130. }
  2131. - (void)actionDelete:(NSIndexPath *)indexPath
  2132. {
  2133. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2134. // Directory locked ?
  2135. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:metadata.fileName];
  2136. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2137. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2138. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) {
  2139. [appDelegate messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2140. return;
  2141. }
  2142. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  2143. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2144. [self performSelector:@selector(deleteFile) withObject:nil];
  2145. }]];
  2146. if (localFile) {
  2147. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2148. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2149. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] error:nil];
  2150. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2151. }]];
  2152. }
  2153. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2154. }]];
  2155. alertController.popoverPresentationController.sourceView = self.tableView;
  2156. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  2157. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2158. [alertController.view layoutIfNeeded];
  2159. [self presentViewController:alertController animated:YES completion:nil];
  2160. }
  2161. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  2162. {
  2163. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  2164. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  2165. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2166. NSString *titoloLock, *titleFavorite;
  2167. if (self.metadata.favorite) {
  2168. titleFavorite = NSLocalizedString(@"_remove_favorites_", nil);
  2169. } else {
  2170. titleFavorite = NSLocalizedString(@"_add_favorites_", nil);
  2171. }
  2172. if (self.metadata.directory) {
  2173. // calcolo lockServerUrl
  2174. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2175. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2176. if (directory.lock)
  2177. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  2178. else
  2179. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  2180. }
  2181. // ******************************************* AHKActionSheet *******************************************
  2182. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
  2183. actionSheet.animationDuration = 0.2;
  2184. actionSheet.buttonHeight = 50.0;
  2185. actionSheet.cancelButtonHeight = 50.0f;
  2186. actionSheet.separatorHeight = 5.0f;
  2187. actionSheet.automaticallyTintButtonImages = @(NO);
  2188. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.encrypted };
  2189. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2190. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2191. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2192. actionSheet.separatorColor = NCBrandColor.sharedInstance.separator;
  2193. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  2194. actionSheet.cancelButtonBackgroudColor = NCBrandColor.sharedInstance.backgroundForm;
  2195. // ******************************************* DIRECTORY *******************************************
  2196. if (self.metadata.directory) {
  2197. BOOL lockDirectory = NO;
  2198. BOOL isOffline = NO;
  2199. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2200. BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] account:appDelegate.activeAccount];
  2201. // Directory bloccata ?
  2202. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl]];
  2203. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) lockDirectory = YES;
  2204. if (directory.offline) isOffline = YES;
  2205. [actionSheet addButtonWithTitle:self.metadata.fileNameView
  2206. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:NCBrandColor.sharedInstance.brandElement]
  2207. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2208. height:50.0
  2209. type:AHKActionSheetButtonTypeDisabled
  2210. handler:nil
  2211. ];
  2212. [actionSheet addButtonWithTitle: titleFavorite
  2213. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2214. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2215. height: 50.0
  2216. type: AHKActionSheetButtonTypeDefault
  2217. handler: ^(AHKActionSheet *as) {
  2218. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2219. else [self settingFavorite:self.metadata favorite:YES];
  2220. }];
  2221. if (!lockDirectory && !isFolderEncrypted) {
  2222. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2223. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2224. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2225. height:50.0
  2226. type:AHKActionSheetButtonTypeDefault
  2227. handler:^(AHKActionSheet *as) {
  2228. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2229. }];
  2230. }
  2231. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !self.metadata.e2eEncrypted) {
  2232. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2233. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2234. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2235. height:50.0
  2236. type:AHKActionSheetButtonTypeDefault
  2237. handler:^(AHKActionSheet *as) {
  2238. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2239. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2240. textField.text = self.metadata.fileNameView;
  2241. textField.delegate = self;
  2242. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2243. }];
  2244. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2245. NSLog(@"[LOG] Cancel action");
  2246. }];
  2247. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2248. UITextField *fileName = alertController.textFields.firstObject;
  2249. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2250. }];
  2251. okAction.enabled = NO;
  2252. [alertController addAction:cancelAction];
  2253. [alertController addAction:okAction];
  2254. [self presentViewController:alertController animated:YES completion:nil];
  2255. }];
  2256. }
  2257. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !isFolderEncrypted) {
  2258. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2259. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2260. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2261. height:50.0
  2262. type:AHKActionSheetButtonTypeDefault
  2263. handler:^(AHKActionSheet *as) {
  2264. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2265. }];
  2266. }
  2267. if (!isFolderEncrypted) {
  2268. NSString *title;
  2269. if (isOffline) {
  2270. title = NSLocalizedString(@"_remove_available_offline_", nil);
  2271. } else {
  2272. title = NSLocalizedString(@"_set_available_offline_", nil);
  2273. }
  2274. [actionSheet addButtonWithTitle:title
  2275. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2276. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2277. height:50.0
  2278. type:AHKActionSheetButtonTypeDefault
  2279. handler:^(AHKActionSheet *as) {
  2280. if (isOffline) {
  2281. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:false account:appDelegate.activeAccount];
  2282. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2283. } else {
  2284. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:true account:appDelegate.activeAccount];
  2285. [[CCSynchronize sharedSynchronize] readFolder:dirServerUrl selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  2286. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2287. }
  2288. }];
  2289. }
  2290. [actionSheet addButtonWithTitle:titoloLock
  2291. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2292. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2293. height:50.0
  2294. type:AHKActionSheetButtonTypeDefault
  2295. handler:^(AHKActionSheet *as) {
  2296. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  2297. }];
  2298. if (!self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2299. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_set_folder_encrypted_", nil)
  2300. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2301. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2302. height:50.0
  2303. type:AHKActionSheetButtonTypeDefault
  2304. handler:^(AHKActionSheet *as) {
  2305. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  2306. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] ocId:self.metadata.ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  2307. dispatch_async(dispatch_get_main_queue(), ^{
  2308. if (error) {
  2309. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2310. } else {
  2311. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2312. [self readFolder:self.serverUrl];
  2313. }
  2314. });
  2315. });
  2316. }];
  2317. }
  2318. if (self.metadata.e2eEncrypted && !_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2319. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_remove_folder_encrypted_", nil)
  2320. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2321. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2322. height:50.0
  2323. type:AHKActionSheetButtonTypeDefault
  2324. handler:^(AHKActionSheet *as) {
  2325. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2326. NSError *error = [[NCNetworkingEndToEnd sharedManager] deletemarkEndToEndFolderEncryptedOnServerUrl:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] ocId:self.metadata.ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  2327. dispatch_async(dispatch_get_main_queue(), ^{
  2328. if (error) {
  2329. [appDelegate messageNotification:@"_e2e_error_delete_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2330. } else {
  2331. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2332. [self readFolder:self.serverUrl];
  2333. }
  2334. });
  2335. });
  2336. }];
  2337. }
  2338. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2339. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2340. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2341. height:50.0
  2342. type:AHKActionSheetButtonTypeDestructive
  2343. handler:^(AHKActionSheet *as) {
  2344. [self actionDelete:indexPath];
  2345. }];
  2346. [actionSheet show];
  2347. }
  2348. // ******************************************* FILE *******************************************
  2349. if (!self.metadata.directory) {
  2350. UIImage *iconHeader;
  2351. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  2352. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]])
  2353. iconHeader = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]];
  2354. else
  2355. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  2356. [actionSheet addButtonWithTitle: self.metadata.fileNameView
  2357. image: iconHeader
  2358. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2359. height: 50.0
  2360. type: AHKActionSheetButtonTypeDisabled
  2361. handler: nil
  2362. ];
  2363. [actionSheet addButtonWithTitle: titleFavorite
  2364. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2365. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2366. height: 50.0
  2367. type: AHKActionSheetButtonTypeDefault
  2368. handler: ^(AHKActionSheet *as) {
  2369. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2370. else [self settingFavorite:self.metadata favorite:YES];
  2371. }];
  2372. if (!_metadataFolder.e2eEncrypted) {
  2373. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2374. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2375. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2376. height: 50.0
  2377. type:AHKActionSheetButtonTypeDefault
  2378. handler:^(AHKActionSheet *as) {
  2379. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2380. }];
  2381. }
  2382. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  2383. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  2384. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2385. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2386. height: 50.0
  2387. type:AHKActionSheetButtonTypeDefault
  2388. handler:^(AHKActionSheet *as) {
  2389. [self performSelector:@selector(openinFile:) withObject:nil];
  2390. }];
  2391. }
  2392. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2393. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2394. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2395. height: 50.0
  2396. type:AHKActionSheetButtonTypeDefault
  2397. handler:^(AHKActionSheet *as) {
  2398. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2399. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2400. textField.text = self.metadata.fileNameView;
  2401. textField.delegate = self;
  2402. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2403. }];
  2404. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2405. NSLog(@"[LOG] Cancel action");
  2406. }];
  2407. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2408. UITextField *fileName = alertController.textFields.firstObject;
  2409. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2410. }];
  2411. okAction.enabled = NO;
  2412. [alertController addAction:cancelAction];
  2413. [alertController addAction:okAction];
  2414. [self presentViewController:alertController animated:YES completion:nil];
  2415. }];
  2416. if (!_metadataFolder.e2eEncrypted) {
  2417. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2418. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2419. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2420. height:50.0
  2421. type:AHKActionSheetButtonTypeDefault
  2422. handler:^(AHKActionSheet *as) {
  2423. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2424. }];
  2425. }
  2426. if ([NCUtility.sharedInstance isEditImage:self.metadata.fileNameView] != nil && !_metadataFolder.e2eEncrypted && self.metadata.status == k_metadataStatusNormal) {
  2427. [actionSheet addButtonWithTitle:NSLocalizedString(@"_modify_photo_", nil)
  2428. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"modifyPhoto"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2429. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2430. height:50.0
  2431. type:AHKActionSheetButtonTypeDefault
  2432. handler:^(AHKActionSheet *as) {
  2433. self.metadata.session = k_download_session;
  2434. self.metadata.sessionError = @"";
  2435. self.metadata.sessionSelector = selectorDownloadEditPhoto;
  2436. self.metadata.status = k_metadataStatusWaitDownload;
  2437. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2438. [appDelegate startLoadAutoDownloadUpload];
  2439. }];
  2440. }
  2441. if (!_metadataFolder.e2eEncrypted) {
  2442. NSString *title;
  2443. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", self.metadata.ocId]];
  2444. if (localFile == nil || localFile.offline == false) { title = NSLocalizedString(@"_set_available_offline_", nil); }
  2445. else { title = NSLocalizedString(@"_remove_available_offline_", nil); }
  2446. [actionSheet addButtonWithTitle:title
  2447. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2448. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2449. height:50.0
  2450. type:AHKActionSheetButtonTypeDefault
  2451. handler:^(AHKActionSheet *as) {
  2452. if (localFile == nil || ![CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2453. self.metadata.session = k_download_session;
  2454. self.metadata.sessionError = @"";
  2455. self.metadata.sessionSelector = selectorLoadOffline;
  2456. self.metadata.status = k_metadataStatusWaitDownload;
  2457. // Add Metadata for Download
  2458. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2459. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2460. [appDelegate startLoadAutoDownloadUpload];
  2461. } else if (localFile.offline == false) {
  2462. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:true];
  2463. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2464. } else {
  2465. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:false];
  2466. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2467. }
  2468. }];
  2469. }
  2470. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2471. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2472. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2473. height:50.0
  2474. type:AHKActionSheetButtonTypeDestructive
  2475. handler:^(AHKActionSheet *as) {
  2476. [self actionDelete:indexPath];
  2477. }];
  2478. [actionSheet show];
  2479. }
  2480. }
  2481. #pragma --------------------------------------------------------------------------------------------
  2482. #pragma mark - ==== Datasource ====
  2483. #pragma --------------------------------------------------------------------------------------------
  2484. - (void)clearDateReadDataSource:(NSNotification *)notification
  2485. {
  2486. _dateReadDataSource = Nil;
  2487. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2488. }
  2489. - (void)reloadDatasource:(NSString *)serverUrl ocId:(NSString *)ocId action:(NSInteger)action
  2490. {
  2491. // test
  2492. if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
  2493. return;
  2494. // Search Mode
  2495. if (_isSearchMode) {
  2496. // Create metadatas
  2497. NSMutableArray *metadatas = [NSMutableArray new];
  2498. for (tableMetadata *resultMetadata in _searchResultMetadatas) {
  2499. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", resultMetadata.ocId]];
  2500. if (metadata) {
  2501. [metadatas addObject:metadata];
  2502. }
  2503. }
  2504. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:@"fileName" ascending:NO activeAccount:appDelegate.activeAccount];
  2505. [self tableViewReloadData];
  2506. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  2507. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  2508. _noFilesSearchDescription = @"";
  2509. }
  2510. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  2511. _noFilesSearchTitle = @"";
  2512. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  2513. }
  2514. [self.tableView reloadEmptyDataSet];
  2515. return;
  2516. }
  2517. // Se non siamo nella dir appropriata esci
  2518. if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
  2519. return;
  2520. }
  2521. // Controllo data lettura Data Source
  2522. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  2523. if (tableDirectory == nil) {
  2524. return;
  2525. }
  2526. // Get MetadataFolder
  2527. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
  2528. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, k_serverUrl_root]];
  2529. else
  2530. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tableDirectory.ocId]];
  2531. // Remove optimization for encrypted directory
  2532. if (_metadataFolder.e2eEncrypted)
  2533. _dateReadDataSource = nil;
  2534. NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
  2535. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  2536. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  2537. _dateReadDataSource = [NSDate date];
  2538. // Data Source
  2539. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2540. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
  2541. dispatch_async(dispatch_get_main_queue(), ^{
  2542. sectionDataSource = sectionDataSourceTemp;
  2543. [self tableViewReloadData];
  2544. });
  2545. });
  2546. } else {
  2547. [self tableViewReloadData];
  2548. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  2549. }
  2550. // BLINK
  2551. if (self.blinkFileNamePath != nil) {
  2552. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2553. for (NSString *key in sectionDataSource.allRecordsDataSource) {
  2554. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:key];
  2555. NSString *metadataFileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  2556. if ([metadataFileNamePath isEqualToString:self.blinkFileNamePath]) {
  2557. for (NSString *key in sectionDataSource.ocIdIndexPath) {
  2558. if ([key isEqualToString:metadata.ocId]) {
  2559. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:key];
  2560. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  2561. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2562. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  2563. if (cell) {
  2564. self.blinkFileNamePath = nil;
  2565. [[NCUtility sharedInstance] blinkWithCell:cell];
  2566. }
  2567. });
  2568. }
  2569. }
  2570. }
  2571. }
  2572. });
  2573. }
  2574. }
  2575. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
  2576. {
  2577. // test
  2578. if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
  2579. return nil;
  2580. }
  2581. // get auto upload folder
  2582. _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  2583. _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
  2584. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  2585. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND status != %i", appDelegate.activeAccount, serverUrl, k_metadataStatusHide] sorted:nil ascending:NO];
  2586. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings] activeAccount:appDelegate.activeAccount];
  2587. if (withReloadData) {
  2588. sectionDataSource = sectionDataSourceTemp;
  2589. [self tableViewReloadData];
  2590. }
  2591. return sectionDataSourceTemp;
  2592. }
  2593. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  2594. {
  2595. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  2596. if (selectedRows.count > 0) {
  2597. for (NSIndexPath *selectionIndex in selectedRows) {
  2598. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  2599. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2600. [metadatas addObject:metadata];
  2601. }
  2602. }
  2603. return metadatas;
  2604. }
  2605. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  2606. {
  2607. NSInteger totSections =[sectionDataSource.sections count] ;
  2608. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  2609. return nil;
  2610. }
  2611. id valueSection = [sectionDataSource.sections objectAtIndex:section];
  2612. return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
  2613. }
  2614. #pragma --------------------------------------------------------------------------------------------
  2615. #pragma mark - ==== Table ====
  2616. #pragma --------------------------------------------------------------------------------------------
  2617. - (void)tableViewSelect:(BOOL)edit
  2618. {
  2619. // chiudiamo eventuali swipe aperti
  2620. if (edit)
  2621. [self.tableView setEditing:NO animated:NO];
  2622. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  2623. [self.tableView setEditing:edit animated:YES];
  2624. _isSelectedMode = edit;
  2625. if (edit)
  2626. [self setUINavigationBarSelected];
  2627. else
  2628. [self setUINavigationBarDefault];
  2629. [_selectedocIdsMetadatas removeAllObjects];
  2630. [self setTitle];
  2631. }
  2632. - (void)tableViewReloadData
  2633. {
  2634. // store selected cells before relod
  2635. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  2636. // reload table view
  2637. [self.tableView reloadData];
  2638. // selected cells stored
  2639. for (NSIndexPath *path in indexPaths)
  2640. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  2641. [self setTableViewFooter];
  2642. if (self.tableView.editing)
  2643. [self setTitle];
  2644. [self.tableView reloadEmptyDataSet];
  2645. }
  2646. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  2647. {
  2648. if (tableView.editing == 1) {
  2649. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2650. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  2651. return NO;
  2652. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  2653. return NO;
  2654. else
  2655. return YES;
  2656. } else {
  2657. [_selectedocIdsMetadatas removeAllObjects];
  2658. }
  2659. return YES;
  2660. }
  2661. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  2662. {
  2663. return 60;
  2664. }
  2665. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2666. {
  2667. return [[sectionDataSource.sectionArrayRow allKeys] count];
  2668. }
  2669. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2670. {
  2671. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  2672. }
  2673. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2674. {
  2675. NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
  2676. NSString *sectionTitle = [sections objectAtIndex:section];
  2677. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  2678. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  2679. if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  2680. return 20.f;
  2681. }
  2682. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2683. {
  2684. float shift;
  2685. UIVisualEffectView *visualEffectView;
  2686. NSString *titleSection;
  2687. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  2688. return nil;
  2689. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  2690. titleSection = [sectionDataSource.sections objectAtIndex:section];
  2691. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  2692. titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  2693. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  2694. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  2695. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  2696. else titleSection = NSLocalizedString(titleSection,nil);
  2697. // Format title
  2698. UIVisualEffect *blurEffect;
  2699. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  2700. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  2701. visualEffectView.backgroundColor = [NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.2];
  2702. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
  2703. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2704. shift = - 35;
  2705. else
  2706. shift = - 20;
  2707. } else shift = - 10;
  2708. // Title
  2709. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  2710. titleLabel.backgroundColor = [UIColor clearColor];
  2711. titleLabel.textColor = NCBrandColor.sharedInstance.textView;
  2712. titleLabel.font = [UIFont systemFontOfSize:12];
  2713. titleLabel.textAlignment = NSTextAlignmentLeft;
  2714. titleLabel.text = titleSection;
  2715. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2716. [visualEffectView.contentView addSubview:titleLabel];
  2717. // Elements
  2718. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  2719. elementLabel.backgroundColor = [UIColor clearColor];
  2720. elementLabel.textColor = NCBrandColor.sharedInstance.textView;
  2721. elementLabel.font = [UIFont systemFontOfSize:12];
  2722. elementLabel.textAlignment = NSTextAlignmentRight;
  2723. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2724. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  2725. NSUInteger rowsCount = [metadatas count];
  2726. if (rowsCount == 0) return nil;
  2727. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  2728. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  2729. [visualEffectView.contentView addSubview:elementLabel];
  2730. return visualEffectView;
  2731. }
  2732. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  2733. {
  2734. return [sectionDataSource.sections indexOfObject:title];
  2735. }
  2736. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  2737. {
  2738. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
  2739. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  2740. else
  2741. return nil;
  2742. }
  2743. /*
  2744. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  2745. {
  2746. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  2747. }
  2748. }
  2749. */
  2750. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2751. {
  2752. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2753. tableShare *shareCell;
  2754. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || (_metadataFolder != nil && [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])) {
  2755. return [CCCellMain new];
  2756. }
  2757. for (tableShare *share in appDelegate.shares) {
  2758. if ([share.serverUrl isEqualToString:metadata.serverUrl] && [share.fileName isEqualToString:metadata.fileName]) {
  2759. shareCell = share;
  2760. break;
  2761. }
  2762. }
  2763. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory tableShare:shareCell];
  2764. // NORMAL - > MAIN
  2765. if ([cell isKindOfClass:[CCCellMain class]]) {
  2766. // Comment tap
  2767. if (metadata.commentsUnread) {
  2768. UITapGestureRecognizer *tapComment = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionComment:)];
  2769. [tapComment setNumberOfTapsRequired:1];
  2770. ((CCCellMain *)cell).comment.userInteractionEnabled = YES;
  2771. [((CCCellMain *)cell).comment addGestureRecognizer:tapComment];
  2772. }
  2773. // Share add Tap
  2774. UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  2775. [tapShare setNumberOfTapsRequired:1];
  2776. ((CCCellMain *)cell).viewShared.userInteractionEnabled = YES;
  2777. [((CCCellMain *)cell).viewShared addGestureRecognizer:tapShare];
  2778. // More
  2779. if ([self canOpenMenuAction:metadata]) {
  2780. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  2781. [tapMore setNumberOfTapsRequired:1];
  2782. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  2783. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  2784. }
  2785. // MGSwipeButton
  2786. ((CCCellMain *)cell).delegate = self;
  2787. // LEFT
  2788. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellFavouriteImage backgroundColor:NCBrandColor.sharedInstance.yellowFavorite padding:25]];
  2789. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  2790. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  2791. //centerIconOverText
  2792. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  2793. [favoriteButton centerIconOverText];
  2794. // RIGHT
  2795. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellTrashImage backgroundColor:[UIColor redColor] padding:25]];
  2796. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  2797. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  2798. //centerIconOverText
  2799. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  2800. [deleteButton centerIconOverText];
  2801. }
  2802. // TRANSFER
  2803. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  2804. // gesture Transfer
  2805. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  2806. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  2807. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  2808. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  2809. }
  2810. return cell;
  2811. }
  2812. - (void)setTableViewFooter
  2813. {
  2814. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2815. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2816. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2817. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2818. UIFont *appFont = [UIFont systemFontOfSize:12];
  2819. footerLabel.font = appFont;
  2820. footerLabel.textColor = [UIColor grayColor];
  2821. footerLabel.backgroundColor = [UIColor clearColor];
  2822. footerLabel.textAlignment = NSTextAlignmentCenter;
  2823. NSString *folders;
  2824. NSString *files;
  2825. NSString *footerText;
  2826. if (sectionDataSource.directories > 1) {
  2827. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  2828. } else if (sectionDataSource.directories == 1){
  2829. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  2830. } else {
  2831. folders = @"";
  2832. }
  2833. if (sectionDataSource.files > 1) {
  2834. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2835. } else if (sectionDataSource.files == 1){
  2836. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2837. } else {
  2838. files = @"";
  2839. }
  2840. if ([folders isEqualToString:@""]) {
  2841. footerText = files;
  2842. } else if ([files isEqualToString:@""]) {
  2843. footerText = folders;
  2844. } else {
  2845. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  2846. }
  2847. footerLabel.text = footerText;
  2848. [footerView addSubview:footerLabel];
  2849. [self.tableView setTableFooterView:footerView];
  2850. }
  2851. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2852. {
  2853. CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
  2854. // settiamo il record file.
  2855. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2856. if (!self.metadata)
  2857. return;
  2858. // se non può essere selezionata deseleziona
  2859. if ([cell isEditing] == NO)
  2860. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  2861. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  2862. if (self.tableView.editing) {
  2863. [_selectedocIdsMetadatas setObject:self.metadata forKey:self.metadata.ocId];
  2864. [self setTitle];
  2865. return;
  2866. }
  2867. // se è in corso una sessione
  2868. if (self.metadata.status != k_metadataStatusNormal)
  2869. return;
  2870. // file
  2871. if (self.metadata.directory == NO) {
  2872. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  2873. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2874. [[NCNetworkingMain sharedInstance] downloadFileSuccessFailure:self.metadata.fileName ocId:self.metadata.ocId serverUrl:self.metadata.serverUrl selector:selectorLoadFileView errorMessage:@"" errorCode:0];
  2875. } else {
  2876. if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2877. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  2878. } else {
  2879. if (([self.metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_audio] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_image]) && _metadataFolder.e2eEncrypted == NO) {
  2880. [self shouldPerformSegue:self.metadata];
  2881. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isRichDocument:self.metadata]) {
  2882. if (appDelegate.reachability.isReachable) {
  2883. [self shouldPerformSegue:self.metadata];
  2884. } else {
  2885. [appDelegate messageNotification:@"_info_" description:@"_go_online_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  2886. }
  2887. } else {
  2888. self.metadata.session = k_download_session;
  2889. self.metadata.sessionError = @"";
  2890. self.metadata.sessionSelector = selectorLoadFileView;
  2891. self.metadata.status = k_metadataStatusWaitDownload;
  2892. // Add Metadata for Download
  2893. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2894. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2895. [appDelegate startLoadAutoDownloadUpload];
  2896. }
  2897. }
  2898. }
  2899. }
  2900. if (self.metadata.directory) {
  2901. [self performSegueDirectoryWithControlPasscode:true metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2902. }
  2903. }
  2904. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  2905. {
  2906. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2907. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  2908. [self setTitle];
  2909. }
  2910. - (void)didSelectAll
  2911. {
  2912. for (int i = 0; i < self.tableView.numberOfSections; i++) {
  2913. for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
  2914. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2915. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2916. [_selectedocIdsMetadatas setObject:metadata forKey:metadata.ocId];
  2917. [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  2918. }
  2919. }
  2920. [self setTitle];
  2921. }
  2922. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  2923. {
  2924. if (!indexPath)
  2925. return NO;
  2926. NSInteger section = indexPath.section;
  2927. NSInteger row = indexPath.row;
  2928. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  2929. if (section > lastSectionIndex || lastSectionIndex < 0)
  2930. return NO;
  2931. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  2932. if (rowCount < 0)
  2933. return NO;
  2934. return row <= rowCount;
  2935. }
  2936. #pragma --------------------------------------------------------------------------------------------
  2937. #pragma mark ===== Navigation ====
  2938. #pragma --------------------------------------------------------------------------------------------
  2939. - (void)shouldPerformSegue:(tableMetadata *)metadata
  2940. {
  2941. // if background return
  2942. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  2943. if (self.view.window == NO)
  2944. return;
  2945. // Collapsed ma siamo già in detail esci
  2946. if (self.splitViewController.isCollapsed)
  2947. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return;
  2948. // Metadata for push detail
  2949. self.metadataForPushDetail = metadata;
  2950. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  2951. }
  2952. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  2953. {
  2954. id viewController = segue.destinationViewController;
  2955. tableMetadata *metadata;
  2956. if ([viewController isKindOfClass:[UINavigationController class]]) {
  2957. UINavigationController *nav = viewController;
  2958. _detailViewController = (CCDetail *)nav.topViewController;
  2959. } else {
  2960. _detailViewController = segue.destinationViewController;
  2961. }
  2962. NSMutableArray *photoDataSource = [NSMutableArray new];
  2963. if ([sender isKindOfClass:[tableMetadata class]]) {
  2964. metadata = sender;
  2965. [photoDataSource addObject:sender];
  2966. } else {
  2967. metadata = self.metadataForPushDetail;
  2968. for (NSString *ocId in sectionDataSource.allOcId) {
  2969. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2970. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  2971. [photoDataSource addObject:metadata];
  2972. }
  2973. }
  2974. _detailViewController.metadataDetail = metadata;
  2975. _detailViewController.photoDataSource = photoDataSource;
  2976. _detailViewController.dateFilterQuery = nil;
  2977. [_detailViewController setTitle:metadata.fileNameView];
  2978. }
  2979. // can i go to next viewcontroller
  2980. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode metadata:(tableMetadata *)metadata blinkFileNamePath:(NSString *)blinkFileNamePath
  2981. {
  2982. NSString *nomeDir;
  2983. if (self.tableView.editing == NO) {
  2984. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  2985. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", metadata.account, lockServerUrl]];
  2986. // SE siamo in presenza di una directory bloccata E è attivo il block E la sessione password Lock è senza data ALLORA chiediamo la password per procedere
  2987. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil && controlPasscode) {
  2988. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2989. viewController.delegate = self;
  2990. viewController.fromType = CCBKPasscodeFromLockDirectory;
  2991. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2992. viewController.inputViewTitlePassword = YES;
  2993. if ([CCUtility getSimplyBlockCode]) {
  2994. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2995. viewController.passcodeInputView.maximumLength = 6;
  2996. } else {
  2997. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2998. viewController.passcodeInputView.maximumLength = 64;
  2999. }
  3000. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  3001. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  3002. viewController.touchIDManager = touchIDManager;
  3003. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  3004. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3005. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  3006. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3007. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  3008. [self presentViewController:navigationController animated:YES completion:nil];
  3009. return;
  3010. }
  3011. // E2EE Check enable
  3012. if (metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
  3013. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  3014. return;
  3015. }
  3016. nomeDir = metadata.fileName;
  3017. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:nomeDir];
  3018. CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
  3019. if (!viewController) {
  3020. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
  3021. viewController.serverUrl = serverUrlPush;
  3022. viewController.titleMain = metadata.fileName;
  3023. viewController.blinkFileNamePath = blinkFileNamePath;
  3024. // save self
  3025. [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
  3026. [self.navigationController pushViewController:viewController animated:YES];
  3027. } else {
  3028. if (viewController.isViewLoaded) {
  3029. viewController.titleMain = metadata.fileName;
  3030. viewController.blinkFileNamePath = blinkFileNamePath;
  3031. // Fix : Application tried to present modally an active controller
  3032. if ([self.navigationController isBeingPresented]) {
  3033. // being presented
  3034. } else if ([self.navigationController isMovingToParentViewController]) {
  3035. // being pushed
  3036. } else {
  3037. [self.navigationController pushViewController:viewController animated:YES];
  3038. }
  3039. }
  3040. }
  3041. }
  3042. }
  3043. @end