CCMain.m 197 KB

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