CCMain.m 205 KB

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