CCMain.m 207 KB

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