CCMain.m 206 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233
  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. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:_serverUrl fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
  854. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  855. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  856. // Read folder: No record, Change etag or BLINK
  857. if ([sectionDataSource.allRecordsDataSource count] == 0 || [metadata.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
  858. [self readFolder:metadata.serverUrl];
  859. }
  860. } else if (errorCode != 0) {
  861. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  862. } else {
  863. NSLog(@"[LOG] It has been changed user during networking process, error.");
  864. }
  865. }];
  866. */
  867. }
  868. #pragma --------------------------------------------------------------------------------------------
  869. #pragma mark ==== Read Folder ====
  870. #pragma --------------------------------------------------------------------------------------------
  871. - (void)insertMetadatasWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas
  872. {
  873. // stoprefresh
  874. [refreshControl endRefreshing];
  875. // save metadataFolder
  876. _metadataFolder = metadataFolder;
  877. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
  878. if (tableAccount == nil) {
  879. return;
  880. }
  881. if (self.searchController.isActive == NO) {
  882. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag ocId:metadataFolder.ocId encrypted:metadataFolder.e2eEncrypted richWorkspace:nil account:account];
  883. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide]];
  884. [[NCManageDatabase sharedInstance] setDateReadDirectoryWithServerUrl:serverUrl account:account];
  885. }
  886. 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];
  887. // insert in Database
  888. NSMutableArray *metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas];
  889. // insert in Database the /
  890. if (metadataFolder != nil) {
  891. _metadataFolder = [[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
  892. }
  893. // reinsert metadatas in Download
  894. if (metadatasInDownload) {
  895. (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload];
  896. }
  897. // File is changed ??
  898. if (!self.searchController.isActive && metadatasToInsertInDB) {
  899. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  900. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:serverUrl account:account withDownload:NO];
  901. });
  902. }
  903. // Search Mode
  904. if (self.searchController.isActive) {
  905. // Fix managed -> Unmanaged _searchResultMetadatas
  906. if (metadatasToInsertInDB)
  907. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
  908. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  909. }
  910. // this is the same directory
  911. if ([serverUrl isEqualToString:_serverUrl] && !self.searchController.isActive) {
  912. // reload
  913. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  914. [self tableViewReloadData];
  915. }
  916. // E2EE Is encrypted folder get metadata
  917. if (_metadataFolder.e2eEncrypted) {
  918. NSString *metadataFolderocId = metadataFolder.ocId;
  919. // Read Metadata
  920. if ([CCUtility isEndToEndEnabled:account]) {
  921. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  922. NSString *metadata;
  923. NSError *error = [[NCNetworkingEndToEnd sharedManager] getEndToEndMetadata:&metadata ocId:metadataFolderocId user:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] url:tableAccount.url];
  924. dispatch_async(dispatch_get_main_queue(), ^{
  925. if (error) {
  926. if (error.code != kOCErrorServerPathNotFound)
  927. [[NCContentPresenter shared] messageNotification:@"_e2e_error_get_metadata_" description:error.localizedDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  928. } else {
  929. if ([[NCEndToEndMetadata sharedInstance] decoderMetadata:metadata privateKey:[CCUtility getEndToEndPrivateKey:account] serverUrl:self.serverUrl account:account url:tableAccount.url] == false)
  930. [[NCContentPresenter shared] messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  931. else
  932. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  933. }
  934. });
  935. });
  936. } else {
  937. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  938. }
  939. }
  940. // rewrite title
  941. [self setTitle];
  942. }
  943. - (void)readFolder:(NSString *)serverUrl
  944. {
  945. // init control
  946. if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
  947. [refreshControl endRefreshing];
  948. return;
  949. }
  950. // Search Mode
  951. if (self.searchController.isActive) {
  952. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  953. _searchFileName = @""; // forced reload searchg
  954. [self updateSearchResultsForSearchController:self.searchController];
  955. return;
  956. }
  957. _loadingFolder = YES;
  958. [self tableViewReloadData];
  959. [[OCNetworking sharedManager] readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
  960. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  961. [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
  962. } else if (errorCode != 0) {
  963. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  964. } else {
  965. NSLog(@"[LOG] It has been changed user during networking process, error.");
  966. }
  967. _loadingFolder = NO;
  968. }];
  969. }
  970. #pragma mark -
  971. #pragma --------------------------------------------------------------------------------------------
  972. #pragma mark ===== Search =====
  973. #pragma --------------------------------------------------------------------------------------------
  974. - (void)searchEnabled:(BOOL)enabled
  975. {
  976. if (enabled) {
  977. if (self.tableView.tableHeaderView != nil)
  978. return;
  979. self.definesPresentationContext = YES;
  980. self.searchController.searchResultsUpdater = self;
  981. self.searchController.dimsBackgroundDuringPresentation = NO;
  982. self.searchController.searchBar.translucent = NO;
  983. [self.searchController.searchBar sizeToFit];
  984. self.searchController.searchBar.delegate = self;
  985. self.searchController.searchBar.barTintColor = NCBrandColor.sharedInstance.brand;
  986. self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.brand;
  987. self.searchController.searchBar.backgroundImage = [UIImage new];
  988. // color searchbbar button text (cancel)
  989. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  990. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  991. [searchButton setTitleColor:NCBrandColor.sharedInstance.brandText forState:UIControlStateNormal];
  992. }
  993. // color textview searchbbar
  994. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  995. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  996. searchTextView.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  997. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  998. }
  999. self.tableView.tableHeaderView = self.searchController.searchBar;
  1000. [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
  1001. } else {
  1002. self.tableView.tableHeaderView = nil;
  1003. }
  1004. }
  1005. - (void)searchStartTimer
  1006. {
  1007. if (self.searchController.isActive == false) {
  1008. return;
  1009. }
  1010. NSString *startDirectory = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  1011. [[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) {
  1012. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1013. #if TARGET_OS_SIMULATOR
  1014. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:account];
  1015. if (capabilities.isFulltextsearchEnabled) {
  1016. [[OCNetworking sharedManager] fullTextSearchWithAccount:appDelegate.activeAccount text:_searchFileName page:1 completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
  1017. NSLog(@"x");
  1018. }];
  1019. }
  1020. #endif
  1021. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
  1022. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  1023. } else {
  1024. if (errorCode != 0) {
  1025. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1026. } else {
  1027. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1028. }
  1029. _searchFileName = @"";
  1030. }
  1031. }];
  1032. _noFilesSearchTitle = @"";
  1033. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  1034. [self.tableView reloadEmptyDataSet];
  1035. }
  1036. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  1037. {
  1038. // Color text "Cancel"
  1039. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:NCBrandColor.sharedInstance.brandText];
  1040. if (searchController.isActive) {
  1041. [self deleteRefreshControl];
  1042. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  1043. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1044. _searchFileName = fileName;
  1045. // First : filter
  1046. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView CONTAINS[cd] %@", appDelegate.activeAccount, _serverUrl, fileName] sorted:nil ascending:NO];
  1047. [_searchResultMetadatas removeAllObjects];
  1048. for (tableMetadata *record in records)
  1049. [_searchResultMetadatas addObject:record];
  1050. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  1051. // Version >= 12
  1052. if ([[NCManageDatabase sharedInstance] getServerVersionWithAccount:appDelegate.activeAccount] >= 12) {
  1053. [_timerWaitInput invalidate];
  1054. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1055. }
  1056. }
  1057. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1058. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1059. }
  1060. } else {
  1061. [self createRefreshControl];
  1062. [self reloadDatasource:self.serverUrl ocId:nil action:k_action_NULL];
  1063. }
  1064. }
  1065. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1066. {
  1067. [self cancelSearchBar];
  1068. }
  1069. - (void)cancelSearchBar
  1070. {
  1071. if (self.searchController.active) {
  1072. [self.searchController setActive:NO];
  1073. _searchFileName = @"";
  1074. _dateReadDataSource = nil;
  1075. _searchResultMetadatas = [NSMutableArray new];
  1076. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1077. }
  1078. //[self setNeedsStatusBarAppearanceUpdate];
  1079. }
  1080. #pragma mark -
  1081. #pragma --------------------------------------------------------------------------------------------
  1082. #pragma mark ===== Delete File or Folder =====
  1083. #pragma --------------------------------------------------------------------------------------------
  1084. - (void)deleteFile
  1085. {
  1086. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1087. return;
  1088. NSArray *metadatas;
  1089. if ([_selectedocIdsMetadatas count] > 0) {
  1090. metadatas = [_selectedocIdsMetadatas allValues];
  1091. } else {
  1092. metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
  1093. }
  1094. // remove optimization
  1095. _dateReadDataSource = nil;
  1096. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:_metadataFolder.e2eEncrypted serverUrl:self.serverUrl folderocId:_metadataFolder.ocId completion:^(NSInteger errorCode, NSString *message) {
  1097. // Reload
  1098. if (self.searchController.isActive)
  1099. [self readFolder:self.serverUrl];
  1100. else
  1101. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1102. }];
  1103. // End Select Table View
  1104. [self tableViewSelect:NO];
  1105. }
  1106. #pragma --------------------------------------------------------------------------------------------
  1107. #pragma mark ===== Rename =====
  1108. #pragma --------------------------------------------------------------------------------------------
  1109. - (void)renameFile:(NSArray *)arguments
  1110. {
  1111. tableMetadata *metadata = [arguments objectAtIndex:0];
  1112. NSString *fileName = [arguments objectAtIndex:1];
  1113. // E2EE
  1114. if (_metadataFolder.e2eEncrypted) {
  1115. // verify if exists the new fileName
  1116. if ([[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, self.serverUrl, fileName]]) {
  1117. [[NCContentPresenter shared] messageNotification:@"_error_e2ee_" description:@"_file_already_exists_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  1118. return;
  1119. }
  1120. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  1121. 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];
  1122. if (error) {
  1123. [[NCContentPresenter shared] messageNotification:@"_error_e2ee_" description:@"_e2e_error_send_metadata_" delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  1124. } else {
  1125. [[NCManageDatabase sharedInstance] setMetadataFileNameViewWithServerUrl:metadata.serverUrl fileName:metadata.fileName newFileNameView:fileName account:appDelegate.activeAccount];
  1126. // Move file system
  1127. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileNameView];
  1128. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileName];
  1129. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1130. [[NSFileManager defaultManager] moveItemAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileName] error:nil];
  1131. }
  1132. // Unlock
  1133. tableE2eEncryptionLock *tableLock = [[NCManageDatabase sharedInstance] getE2ETokenLockWithServerUrl:self.serverUrl];
  1134. if (tableLock != nil) {
  1135. 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];
  1136. if (error) {
  1137. [[NCContentPresenter shared] messageNotification:@"_e2e_error_unlock_" description:error.localizedDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  1138. }
  1139. }
  1140. dispatch_async(dispatch_get_main_queue(), ^{
  1141. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1142. });
  1143. });
  1144. } else {
  1145. // verify permission
  1146. BOOL permission = [[NCUtility sharedInstance] permissionsContainsString:metadata.permissions permissions:k_permission_can_rename];
  1147. if (![metadata.permissions isEqualToString:@""] && permission == false) {
  1148. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_no_permission_modify_file_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  1149. return;
  1150. }
  1151. // Plain
  1152. NSString *fileNameNew = [CCUtility removeForbiddenCharactersServer:fileName];
  1153. if ([fileName length] == 0 || [fileName isEqualToString:metadata.fileNameView]) {
  1154. return;
  1155. }
  1156. // Verify if exists the fileName TO
  1157. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:metadata.serverUrl fileName:fileNameNew completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1158. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1159. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1160. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }];
  1161. [alert addAction:ok];
  1162. [self presentViewController:alert animated:YES completion:nil];
  1163. } else if (errorCode != 0) {
  1164. if (errorCode == kOCErrorServerPathNotFound) {
  1165. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1166. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
  1167. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1168. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1169. // Rename metadata
  1170. (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:fileNameNew ocId:metadata.ocId];
  1171. if (metadata.directory) {
  1172. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  1173. NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:fileNameNew];
  1174. tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  1175. if (directoryTable == nil) {
  1176. [[NCContentPresenter shared] messageNotification:@"_rename_" description:@"Internal error, ServerUrl not found" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  1177. return;
  1178. }
  1179. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:@"" ocId:nil encrypted:directoryTable.e2eEncrypted richWorkspace:nil account:appDelegate.activeAccount];
  1180. } else {
  1181. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:metadata.ocId date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:fileNameNew etag:nil];
  1182. // Move file system
  1183. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileName];
  1184. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileNameNew];
  1185. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1186. NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileName];
  1187. NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileNameNew];
  1188. [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
  1189. }
  1190. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1191. } else if (errorCode != 0) {
  1192. [[NCContentPresenter shared] messageNotification:@"_rename_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1193. } else {
  1194. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1195. }
  1196. }];
  1197. } else {
  1198. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1199. }
  1200. } else {
  1201. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1202. }
  1203. }];
  1204. }
  1205. }
  1206. #pragma --------------------------------------------------------------------------------------------
  1207. #pragma mark ===== Move =====
  1208. #pragma --------------------------------------------------------------------------------------------
  1209. - (void)moveFileOrFolderMetadata:(tableMetadata *)metadata serverUrlTo:(NSString *)serverUrlTo numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1210. {
  1211. // verify permission
  1212. BOOL permission = [[NCUtility sharedInstance] permissionsContainsString:metadata.permissions permissions:k_permission_can_move];
  1213. if (![metadata.permissions isEqualToString:@""] && permission == false) {
  1214. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_no_permission_modify_file_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  1215. return;
  1216. }
  1217. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:serverUrlTo fileName:metadata.fileName completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1218. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1219. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1220. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1221. }];
  1222. [alert addAction:ok];
  1223. [self presentViewController:alert animated:YES completion:nil];
  1224. // End Select Table View
  1225. [self tableViewSelect:NO];
  1226. // reload Datasource
  1227. [self readFileReloadFolder];
  1228. } else if (errorCode != 0) {
  1229. if (errorCode == kOCErrorServerPathNotFound) {
  1230. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1231. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
  1232. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1233. [_hud hideHud];
  1234. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1235. if (metadata.directory) {
  1236. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] account:account];
  1237. }
  1238. [[NCManageDatabase sharedInstance] moveMetadataWithOcId:metadata.ocId serverUrlTo:serverUrlTo];
  1239. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:account];
  1240. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrlTo account:account];
  1241. // next
  1242. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  1243. if ([_selectedocIdsMetadatas count] > 0) {
  1244. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1245. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrlTo numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1246. } else {
  1247. // End Select Table View
  1248. [self tableViewSelect:NO];
  1249. // reload Datasource
  1250. if (self.searchController.isActive)
  1251. [self readFolder:metadata.serverUrl];
  1252. else
  1253. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1254. }
  1255. } else if (errorCode != 0) {
  1256. [[NCContentPresenter shared] messageNotification:@"_move_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1257. // End Select Table View
  1258. [self tableViewSelect:NO];
  1259. // reload Datasource
  1260. if (self.searchController.isActive)
  1261. [self readFolder:metadata.serverUrl];
  1262. else
  1263. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:nil action:k_action_NULL];
  1264. } else {
  1265. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1266. }
  1267. }];
  1268. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1269. } else {
  1270. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1271. }
  1272. } else {
  1273. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1274. }
  1275. }];
  1276. }
  1277. // DELEGATE : Select
  1278. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  1279. {
  1280. if (serverUrl == nil) {
  1281. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1282. } else {
  1283. // E2EE DENIED
  1284. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) {
  1285. [[NCContentPresenter shared] messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  1286. return;
  1287. }
  1288. if ([_selectedocIdsMetadatas count] > 0) {
  1289. _numSelectedocIdsMetadatas = [_selectedocIdsMetadatas count];
  1290. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1291. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrl numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1292. } else {
  1293. _numSelectedocIdsMetadatas = 1;
  1294. [self moveFileOrFolderMetadata:self.metadata serverUrlTo:serverUrl numFile:1 ofFile:_numSelectedocIdsMetadatas];
  1295. }
  1296. }
  1297. }
  1298. - (void)moveOpenWindow:(NSArray *)indexPaths
  1299. {
  1300. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1301. return;
  1302. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  1303. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  1304. viewController.delegate = self;
  1305. viewController.hideButtonCreateFolder = false;
  1306. viewController.selectFile = false;
  1307. viewController.includeDirectoryE2EEncryption = false;
  1308. viewController.includeImages = false;
  1309. viewController.type = @"";
  1310. viewController.titleButtonDone = NSLocalizedString(@"_move_", nil);
  1311. viewController.layoutViewSelect = k_layout_view_move;
  1312. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  1313. [self presentViewController:navigationController animated:YES completion:nil];
  1314. }
  1315. #pragma --------------------------------------------------------------------------------------------
  1316. #pragma mark ===== Create folder =====
  1317. #pragma --------------------------------------------------------------------------------------------
  1318. - (void)createFolder
  1319. {
  1320. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  1321. NSString *message;
  1322. UIAlertController *alertController;
  1323. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  1324. message = @"/";
  1325. } else {
  1326. message = [serverUrl lastPathComponent];
  1327. }
  1328. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  1329. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1330. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  1331. textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
  1332. }];
  1333. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1334. NSLog(@"[LOG] Cancel action");
  1335. }];
  1336. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1337. UITextField *fileName = alertController.textFields.firstObject;
  1338. [self createFolder:fileName.text serverUrl:serverUrl];
  1339. }];
  1340. okAction.enabled = NO;
  1341. [alertController addAction:cancelAction];
  1342. [alertController addAction:okAction];
  1343. [self presentViewController:alertController animated:YES completion:nil];
  1344. }
  1345. - (void)createFolder:(NSString *)fileNameFolder serverUrl:(NSString *)serverUrl
  1346. {
  1347. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1348. fileNameFolder = [[NCUtility sharedInstance] createFileName:fileNameFolder serverUrl:self.serverUrl account:appDelegate.activeAccount];
  1349. if (![fileNameFolder length]) return;
  1350. NSString *ocIdTemp = [[NSUUID UUID] UUIDString];
  1351. // Create Directory (temp) on metadata
  1352. 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:@""];
  1353. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1354. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  1355. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1356. // Creeate folder Networking
  1357. [[OCNetworking sharedManager] createFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileNameFolder completion:^(NSString *account, NSString *ocId, NSDate *date, NSString *message, NSInteger errorCode) {
  1358. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1359. // Delete Temp Dir
  1360. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1361. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrl, fileNameFolder];
  1362. if (_metadataFolder.e2eEncrypted) {
  1363. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1364. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:newDirectory ocId:ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1365. dispatch_async(dispatch_get_main_queue(), ^{
  1366. if (error) {
  1367. [[NCContentPresenter shared] messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  1368. }
  1369. [self readFolder:self.serverUrl];
  1370. });
  1371. });
  1372. } else {
  1373. [self readFolder:self.serverUrl];
  1374. }
  1375. } else {
  1376. // Delete Temp Dir
  1377. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1378. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1379. if (errorCode != 0) {
  1380. [[NCContentPresenter shared] messageNotification:@"_create_folder_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1381. } else {
  1382. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1383. }
  1384. }
  1385. }];
  1386. }
  1387. #pragma --------------------------------------------------------------------------------------------
  1388. #pragma mark ===== Progress & Task Button =====
  1389. #pragma --------------------------------------------------------------------------------------------
  1390. - (void)triggerProgressTask:(NSNotification *)notification
  1391. {
  1392. if (sectionDataSource.ocIdIndexPath != nil) {
  1393. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
  1394. }
  1395. }
  1396. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1397. {
  1398. UITouch *touch = [[event allTouches] anyObject];
  1399. CGPoint location = [touch locationInView:self.tableView];
  1400. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1401. if ([self indexPathIsValid:indexPath]) {
  1402. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1403. if (metadataSection) {
  1404. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataSection.ocId]];
  1405. if (metadata)
  1406. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  1407. }
  1408. }
  1409. }
  1410. - (void)cancelAllTask:(id)sender
  1411. {
  1412. CGPoint location = [sender locationInView:self.tableView];
  1413. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1414. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1415. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1416. [NCUtility.sharedInstance startActivityIndicatorWithView:self.view bottom:0];
  1417. [[NCMainCommon sharedInstance] cancelAllTransfer];
  1418. [NCUtility.sharedInstance stopActivityIndicator];
  1419. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:nil ocId:nil action:k_action_NULL];
  1420. }]];
  1421. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  1422. alertController.popoverPresentationController.sourceView = self.tableView;
  1423. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1424. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1425. [alertController.view layoutIfNeeded];
  1426. [self presentViewController:alertController animated:YES completion:nil];
  1427. }
  1428. #pragma --------------------------------------------------------------------------------------------
  1429. #pragma mark ===== Tap =====
  1430. #pragma --------------------------------------------------------------------------------------------
  1431. - (void)tapActionComment:(UITapGestureRecognizer *)tapGesture
  1432. {
  1433. CGPoint location = [tapGesture locationInView:self.tableView];
  1434. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1435. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1436. if (metadata) {
  1437. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:1];
  1438. }
  1439. }
  1440. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  1441. {
  1442. CGPoint location = [tapGesture locationInView:self.tableView];
  1443. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1444. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1445. if (metadata) {
  1446. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  1447. }
  1448. }
  1449. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  1450. {
  1451. CGPoint location = [tapGesture locationInView:self.tableView];
  1452. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1453. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1454. if (metadata) {
  1455. }
  1456. }
  1457. #pragma --------------------------------------------------------------------------------------------
  1458. #pragma mark ===== Rich WorkspaceTap Action =====
  1459. #pragma --------------------------------------------------------------------------------------------
  1460. - (void)viewRichWorkspaceTapAction:(UITapGestureRecognizer *)tapGesture
  1461. {
  1462. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, self.serverUrl, @"readme.md"]];
  1463. if (metadata && [[NCUtility sharedInstance] isDirectEditing:metadata]) {
  1464. if (appDelegate.reachability.isReachable) {
  1465. [self shouldPerformSegue:metadata selector:@""];
  1466. } else {
  1467. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  1468. }
  1469. } else if (metadata == nil) {
  1470. NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:@"Readme.md" serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
  1471. [[NCCommunication sharedInstance] NCTextCreateFileWithUrlString:appDelegate.activeUrl fileNamePath:fileNamePath editor:@"text" templateId:@"" account:appDelegate.activeAccount completionHandler:^(NSString *account, NSString *url, NSInteger errorCode, NSString *errorMessage) {
  1472. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1473. tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:false ocId:[CCUtility createRandomString:12] serverUrl:self.serverUrl fileName:@"Readme.md" etag:@"" size:0 status:k_metadataStatusNormal url:url contentType:@"text/markdown"];
  1474. [self shouldPerformSegue:metadata selector:@""];
  1475. } else if (errorCode != 0) {
  1476. [NCContentPresenter.shared messageNotification:@"_error_" description:errorMessage delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1477. } else {
  1478. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1479. }
  1480. }];
  1481. }
  1482. }
  1483. #pragma --------------------------------------------------------------------------------------------
  1484. #pragma mark ===== Favorite =====
  1485. #pragma --------------------------------------------------------------------------------------------
  1486. - (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
  1487. {
  1488. NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
  1489. [[NCCommunication sharedInstance] setFavoriteWithUrlString:appDelegate.activeUrl fileName:fileNameServerUrl favorite:favorite account:appDelegate.activeAccount completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDecription) {
  1490. if (errorCode == 0 && [appDelegate.activeAccount isEqualToString:account]) {
  1491. [[NCManageDatabase sharedInstance] setMetadataFavoriteWithOcId:metadata.ocId favorite:favorite];
  1492. _dateReadDataSource = nil;
  1493. if (self.searchController.isActive)
  1494. [self readFolder:self.serverUrl];
  1495. else
  1496. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1497. if (metadata.directory && favorite) {
  1498. NSString *selector;
  1499. if ([CCUtility getFavoriteOffline])
  1500. selector = selectorReadFolderWithDownload;
  1501. else
  1502. selector = selectorReadFolder;
  1503. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName] selector:selector account:appDelegate.activeAccount];
  1504. }
  1505. if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
  1506. metadata.favorite = favorite;
  1507. metadata.session = k_download_session;
  1508. metadata.sessionError = @"";
  1509. metadata.sessionSelector = selectorDownloadSynchronize;
  1510. metadata.status = k_metadataStatusWaitDownload;
  1511. // Add Metadata for Download
  1512. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1513. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1514. [appDelegate startLoadAutoDownloadUpload];
  1515. }
  1516. } else if (errorCode != 0) {
  1517. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDecription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  1518. } else {
  1519. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1520. }
  1521. }];
  1522. }
  1523. #pragma --------------------------------------------------------------------------------------------
  1524. #pragma mark ==== Menu LOGO ====
  1525. #pragma --------------------------------------------------------------------------------------------
  1526. - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
  1527. {
  1528. if (appDelegate.reSelectMenu.isOpen || appDelegate.reMainMenu.isOpen)
  1529. return;
  1530. // Brand
  1531. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  1532. return;
  1533. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  1534. NSMutableArray *menuArray = [NSMutableArray new];
  1535. for (NSString *account in listAccount) {
  1536. CCMenuItem *item = [[CCMenuItem alloc] init];
  1537. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  1538. item.argument = account;
  1539. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
  1540. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
  1541. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  1542. if (avatar) {
  1543. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
  1544. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  1545. CGSize imageSize = avatarImageView.bounds.size;
  1546. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1547. CGContextRef context = UIGraphicsGetCurrentContext();
  1548. [avatarImageView.layer renderInContext:context];
  1549. avatar = UIGraphicsGetImageFromCurrentImageContext();
  1550. UIGraphicsEndImageContext();
  1551. } else {
  1552. avatar = [UIImage imageNamed:@"menuLogoUser"];
  1553. }
  1554. item.image = avatar;
  1555. item.target = self;
  1556. if ([account isEqualToString:appDelegate.activeAccount]) {
  1557. item.action = nil;
  1558. [menuArray insertObject:item atIndex:0];
  1559. } else {
  1560. item.action = @selector(changeDefaultAccount:);
  1561. [menuArray addObject:item];
  1562. }
  1563. }
  1564. // Add + new account
  1565. CCMenuItem *item = [[CCMenuItem alloc] init];
  1566. item.title = NSLocalizedString(@"_add_account_", nil);
  1567. item.argument = @"";
  1568. item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] width:50 height:50 color:NCBrandColor.sharedInstance.textView];
  1569. item.target = self;
  1570. item.action = @selector(addNewAccount:);
  1571. [menuArray addObject:item];
  1572. OptionalConfiguration options;
  1573. Color backgroundColor;
  1574. const CGFloat *componentsBackgroundColor = CGColorGetComponents(NCBrandColor.sharedInstance.backgroundForm.CGColor);
  1575. backgroundColor.R = componentsBackgroundColor[0];
  1576. backgroundColor.G = componentsBackgroundColor[1];
  1577. backgroundColor.B = componentsBackgroundColor[2];
  1578. options.arrowSize = 9;
  1579. options.marginXSpacing = 7;
  1580. options.marginYSpacing = 10;
  1581. options.intervalSpacing = 20;
  1582. options.menuCornerRadius = 6.5;
  1583. options.maskToBackground = NO;
  1584. options.shadowOfMenu = YES;
  1585. options.hasSeperatorLine = YES;
  1586. options.seperatorLineHasInsets = YES;
  1587. options.textColor = NCBrandColor.sharedInstance.textView;
  1588. options.menuBackgroundColor = backgroundColor;
  1589. options.separatorColor = NCBrandColor.sharedInstance.separator;
  1590. CGRect rect = self.view.frame;
  1591. CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
  1592. CGFloat safeAreaTop = 0;
  1593. CGFloat offsetY = 35;
  1594. if (@available(iOS 11, *)) {
  1595. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
  1596. }
  1597. rect.origin.y = locationY + safeAreaTop + offsetY;
  1598. rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
  1599. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  1600. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  1601. }
  1602. - (void)changeDefaultAccount:(CCMenuItem *)sender
  1603. {
  1604. // LOGOUT
  1605. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  1606. if (tableAccount) {
  1607. // LOGIN
  1608. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  1609. // go to home sweet home
  1610. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  1611. }
  1612. }
  1613. - (void)addNewAccount:(CCMenuItem *)sender
  1614. {
  1615. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  1616. }
  1617. #pragma --------------------------------------------------------------------------------------------
  1618. #pragma mark ==== ReMenu ====
  1619. #pragma --------------------------------------------------------------------------------------------
  1620. - (void)createReMenuBackgroundView:(REMenu *)menu
  1621. {
  1622. CGFloat safeAreaBottom = 0;
  1623. CGFloat safeAreaTop = 0;
  1624. CGFloat statusBar = 0;
  1625. if (@available(iOS 11, *)) {
  1626. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  1627. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  1628. }
  1629. if ([UIApplication sharedApplication].isStatusBarHidden) {
  1630. statusBar = 13;
  1631. }
  1632. CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
  1633. UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
  1634. CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
  1635. _reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
  1636. [UIView animateWithDuration:0.2 animations:^{
  1637. CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
  1638. CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
  1639. if (y>minimum) {
  1640. _reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
  1641. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  1642. }
  1643. }];
  1644. }
  1645. - (void)createReMainMenu
  1646. {
  1647. NSString *title;
  1648. //NSString *groupBy = [CCUtility getGroupBySettings];
  1649. NSString *sorted = [CCUtility getOrderSettings];
  1650. BOOL ascending = [CCUtility getAscendingSettings];
  1651. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  1652. 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) {
  1653. if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
  1654. }];
  1655. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  1656. if ([sorted isEqualToString:@"fileName"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_a_z_", nil)]; }
  1657. else title = NSLocalizedString(@"_order_by_name_a_z_", nil);
  1658. appDelegate.sortFileNameAZItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameAZ"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1659. [CCUtility setOrderSettings:@"fileName"];
  1660. [CCUtility setAscendingSettings:true];
  1661. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1662. }];
  1663. if ([sorted isEqualToString:@"fileName"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_z_a_", nil)]; }
  1664. else title = NSLocalizedString(@"_order_by_name_z_a_", nil);
  1665. appDelegate.sortFileNameZAItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameZA"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1666. [CCUtility setOrderSettings:@"fileName"];
  1667. [CCUtility setAscendingSettings:false];
  1668. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1669. }];
  1670. if ([sorted isEqualToString:@"date"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_more_recent_", nil)]; }
  1671. else title = NSLocalizedString(@"_order_by_date_more_recent_", nil);
  1672. appDelegate.sortDateMoreRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateMoreRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1673. [CCUtility setOrderSettings:@"date"];
  1674. [CCUtility setAscendingSettings:false];
  1675. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1676. }];
  1677. if ([sorted isEqualToString:@"date"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_less_recent_", nil)]; }
  1678. else title = NSLocalizedString(@"_order_by_date_less_recent_", nil);
  1679. appDelegate.sortDateLessRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateLessRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1680. [CCUtility setOrderSettings:@"date"];
  1681. [CCUtility setAscendingSettings:true];
  1682. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1683. }];
  1684. if ([sorted isEqualToString:@"size"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_smallest_", nil)]; }
  1685. else title = NSLocalizedString(@"_order_by_size_smallest_", nil);
  1686. appDelegate.sortSmallestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortSmallest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1687. [CCUtility setOrderSettings:@"size"];
  1688. [CCUtility setAscendingSettings:true];
  1689. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1690. }];
  1691. if ([sorted isEqualToString:@"size"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_largest_", nil)]; }
  1692. else title = NSLocalizedString(@"_order_by_size_largest_", nil);
  1693. appDelegate.sortLargestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortLargest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1694. [CCUtility setOrderSettings:@"size"];
  1695. [CCUtility setAscendingSettings:false];
  1696. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1697. }];
  1698. /*
  1699. // ITEM GROUP ALPHABETIC -----------------------------------------------------------------------------------------------------
  1700. if ([groupBy isEqualToString:@"alphabetic"]) { title = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  1701. else { title = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  1702. appDelegate.alphabeticItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1703. if ([groupBy isEqualToString:@"alphabetic"]) [CCUtility setGroupBySettings:@"none"];
  1704. else [CCUtility setGroupBySettings:@"alphabetic"];
  1705. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1706. }];
  1707. // ITEM GROUP TYPEFILE -------------------------------------------------------------------------------------------------------
  1708. if ([groupBy isEqualToString:@"typefile"]) { title = NSLocalizedString(@"_group_typefile_yes_", nil); }
  1709. else { title = NSLocalizedString(@"_group_typefile_no_", nil); }
  1710. appDelegate.typefileItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1711. if ([groupBy isEqualToString:@"typefile"]) [CCUtility setGroupBySettings:@"none"];
  1712. else [CCUtility setGroupBySettings:@"typefile"];
  1713. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1714. }];
  1715. // ITEM GROUP DATE -------------------------------------------------------------------------------------------------------
  1716. if ([groupBy isEqualToString:@"date"]) { title = NSLocalizedString(@"_group_date_yes_", nil); }
  1717. else { title = NSLocalizedString(@"_group_date_no_", nil); }
  1718. appDelegate.dateItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1719. if ([groupBy isEqualToString:@"date"]) [CCUtility setGroupBySettings:@"none"];
  1720. else [CCUtility setGroupBySettings:@"date"];
  1721. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1722. }];
  1723. */
  1724. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  1725. if ([CCUtility getDirectoryOnTop]) { title = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  1726. else { title = NSLocalizedString(@"_directory_on_top_no_", nil); }
  1727. appDelegate.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"foldersOnTop"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1728. if ([CCUtility getDirectoryOnTop]) [CCUtility setDirectoryOnTop:NO];
  1729. else [CCUtility setDirectoryOnTop:YES];
  1730. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1731. }];
  1732. // REMENU --------------------------------------------------------------------------------------------------------------
  1733. //appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem,appDelegate.alphabeticItem, appDelegate.typefileItem, appDelegate.dateItem, appDelegate.directoryOnTopItem]];
  1734. appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem, appDelegate.directoryOnTopItem]];
  1735. appDelegate.reMainMenu.itemHeight = 40;
  1736. appDelegate.reMainMenu.imageOffset = CGSizeMake(5, -1);
  1737. appDelegate.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1738. appDelegate.reMainMenu.imageOffset = CGSizeMake(0, 0);
  1739. appDelegate.reMainMenu.waitUntilAnimationIsComplete = NO;
  1740. appDelegate.reMainMenu.separatorHeight = 0.5;
  1741. appDelegate.reMainMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1742. appDelegate.reMainMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1743. appDelegate.reMainMenu.textColor = NCBrandColor.sharedInstance.textView;
  1744. appDelegate.reMainMenu.textAlignment = NSTextAlignmentLeft;
  1745. appDelegate.reMainMenu.textShadowColor = nil;
  1746. appDelegate.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  1747. appDelegate.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  1748. appDelegate.reMainMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1749. appDelegate.reMainMenu.highlightedSeparatorColor = nil;
  1750. appDelegate.reMainMenu.highlightedTextColor = [UIColor blackColor];
  1751. appDelegate.reMainMenu.highlightedTextShadowColor = nil;
  1752. appDelegate.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1753. appDelegate.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  1754. appDelegate.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1755. appDelegate.reMainMenu.subtitleTextShadowColor = nil;
  1756. appDelegate.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1757. appDelegate.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1758. appDelegate.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1759. appDelegate.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1760. appDelegate.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  1761. appDelegate.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1762. appDelegate.reMainMenu.borderWidth = 0;
  1763. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1764. appDelegate.reMainMenu.animationDuration = 0.2;
  1765. appDelegate.reMainMenu.closeAnimationDuration = 0.2;
  1766. appDelegate.reMainMenu.bounce = NO;
  1767. __weak typeof(self) weakSelf = self;
  1768. [appDelegate.reMainMenu setClosePreparationBlock:^{
  1769. // Backgroun reMenu (Gesture)
  1770. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1771. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1772. }];
  1773. }
  1774. - (void)toggleReMainMenu
  1775. {
  1776. if (appDelegate.reMainMenu.isOpen) {
  1777. [appDelegate.reMainMenu close];
  1778. } else {
  1779. [self createReMainMenu];
  1780. [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
  1781. // Backgroun reMenu & (Gesture)
  1782. [self createReMenuBackgroundView:appDelegate.reMainMenu];
  1783. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  1784. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1785. }
  1786. }
  1787. - (void)createReSelectMenu
  1788. {
  1789. // ITEM SELECT ALL --------------------------------------------------------------------------------------------------
  1790. 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) {
  1791. [self didSelectAll];
  1792. }];
  1793. // ITEM MOVE --------------------------------------------------------------------------------------------------------
  1794. 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) {
  1795. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  1796. }];
  1797. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  1798. 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) {
  1799. [self downloadSelectedFilesFolders];
  1800. }];
  1801. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  1802. 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) {
  1803. [self saveSelectedFiles];
  1804. }];
  1805. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  1806. 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) {
  1807. [self deleteFile];
  1808. }];
  1809. // E2EE
  1810. if (_metadataFolder.e2eEncrypted) {
  1811. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1812. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1813. } else {
  1814. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1815. }
  1816. } else {
  1817. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1818. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1819. } else {
  1820. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1821. }
  1822. }
  1823. appDelegate.reSelectMenu.itemHeight = 50;
  1824. appDelegate.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  1825. appDelegate.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1826. appDelegate.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  1827. appDelegate.reSelectMenu.waitUntilAnimationIsComplete = NO;
  1828. appDelegate.reSelectMenu.separatorHeight = 0.5;
  1829. appDelegate.reSelectMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1830. appDelegate.reSelectMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1831. appDelegate.reSelectMenu.textColor = NCBrandColor.sharedInstance.textView;
  1832. appDelegate.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  1833. appDelegate.reSelectMenu.textShadowColor = nil;
  1834. appDelegate.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  1835. appDelegate.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  1836. appDelegate.reSelectMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1837. appDelegate.reSelectMenu.highlightedSeparatorColor = nil;
  1838. appDelegate.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  1839. appDelegate.reSelectMenu.highlightedTextShadowColor = nil;
  1840. appDelegate.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1841. appDelegate.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  1842. appDelegate.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1843. appDelegate.reSelectMenu.subtitleTextShadowColor = nil;
  1844. appDelegate.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1845. appDelegate.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1846. appDelegate.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1847. appDelegate.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1848. appDelegate.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  1849. appDelegate.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1850. appDelegate.reMainMenu.borderWidth = 0;
  1851. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1852. appDelegate.reSelectMenu.closeAnimationDuration = 0.2;
  1853. appDelegate.reSelectMenu.animationDuration = 0.2;
  1854. appDelegate.reSelectMenu.bounce = NO;
  1855. __weak typeof(self) weakSelf = self;
  1856. [appDelegate.reSelectMenu setClosePreparationBlock:^{
  1857. // Backgroun reMenu (Gesture)
  1858. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1859. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1860. }];
  1861. }
  1862. - (void)toggleReSelectMenu
  1863. {
  1864. if (appDelegate.reSelectMenu.isOpen) {
  1865. [appDelegate.reSelectMenu close];
  1866. } else {
  1867. [self createReSelectMenu];
  1868. [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
  1869. // Backgroun reMenu & (Gesture)
  1870. [self createReMenuBackgroundView:appDelegate.reSelectMenu];
  1871. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  1872. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1873. }
  1874. }
  1875. #pragma --------------------------------------------------------------------------------------------
  1876. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  1877. #pragma --------------------------------------------------------------------------------------------
  1878. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  1879. {
  1880. if (recognizer.state == UIGestureRecognizerStateBegan) {
  1881. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  1882. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  1883. NSMutableArray *items = [NSMutableArray new];
  1884. if ([self indexPathIsValid:indexPath])
  1885. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1886. else
  1887. self.metadata = nil;
  1888. [self becomeFirstResponder];
  1889. UIMenuController *menuController = [UIMenuController sharedMenuController];
  1890. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)]];
  1891. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)]];
  1892. if ([NCBrandOptions sharedInstance].disable_openin_file == false) {
  1893. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)]];
  1894. }
  1895. if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document]) {
  1896. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_internal_view_", nil) action:@selector(openInternalViewer:)]];
  1897. }
  1898. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)]];
  1899. [items addObject:[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)]];
  1900. [menuController setMenuItems:items];
  1901. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  1902. [menuController setMenuVisible:YES animated:YES];
  1903. }
  1904. }
  1905. - (BOOL)canBecomeFirstResponder
  1906. {
  1907. return YES;
  1908. }
  1909. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  1910. {
  1911. // For copy file, copy files, Open in ... :
  1912. //
  1913. // NO Directory
  1914. // NO Error Passcode
  1915. // NO In Session mode (download/upload)
  1916. // NO Template
  1917. if (@selector(copyFile:) == action || @selector(openinFile:) == action || @selector(openInternalViewer:) == action) {
  1918. if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
  1919. else return NO;
  1920. }
  1921. if (@selector(copyFiles:) == action) {
  1922. if (_isSelectedMode) {
  1923. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1924. for (tableMetadata *metadata in selectedMetadatas) {
  1925. if (!metadata.directory && metadata.status == k_metadataStatusNormal)
  1926. return YES;
  1927. }
  1928. }
  1929. return NO;
  1930. }
  1931. if (@selector(pasteFile:) == action) {
  1932. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1933. NSArray *items = [pasteboard items];
  1934. if ([items count] == 1) {
  1935. // Value : (NSData) ocId
  1936. NSDictionary *dic = [items objectAtIndex:0];
  1937. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1938. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1939. if (ocId) {
  1940. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1941. if (metadata) {
  1942. return [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView];
  1943. } else {
  1944. return NO;
  1945. }
  1946. }
  1947. }
  1948. return NO;
  1949. }
  1950. if (@selector(pasteFiles:) == action) {
  1951. BOOL isValid = NO;
  1952. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1953. NSArray *items = [pasteboard items];
  1954. if ([items count] <= 1) return NO;
  1955. for (NSDictionary *dic in items) {
  1956. // Value : (NSData) ocId
  1957. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1958. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1959. if (ocId) {
  1960. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1961. if (metadata) {
  1962. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1963. isValid = YES;
  1964. } else {
  1965. isValid = NO;
  1966. break;
  1967. }
  1968. } else {
  1969. isValid = NO;
  1970. break;
  1971. }
  1972. } else {
  1973. isValid = NO;
  1974. break;
  1975. }
  1976. }
  1977. return isValid;
  1978. }
  1979. return NO;
  1980. }
  1981. /************************************ COPY ************************************/
  1982. - (void)copyFile:(id)sender
  1983. {
  1984. // Remove all item
  1985. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1986. pasteboard.items = [[NSArray alloc] init];
  1987. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  1988. [self copyFileToPasteboard:self.metadata];
  1989. } else {
  1990. self.metadata.session = k_download_session;
  1991. self.metadata.sessionError = @"";
  1992. self.metadata.sessionSelector = selectorLoadCopy;
  1993. self.metadata.status = k_metadataStatusWaitDownload;
  1994. // Add Metadata for Download
  1995. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  1996. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  1997. [appDelegate startLoadAutoDownloadUpload];
  1998. }
  1999. }
  2000. - (void)copyFiles:(id)sender
  2001. {
  2002. // Remove all item
  2003. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2004. pasteboard.items = [[NSArray alloc] init];
  2005. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2006. for (tableMetadata *metadata in selectedMetadatas) {
  2007. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  2008. [self copyFileToPasteboard:metadata];
  2009. } else {
  2010. metadata.session = k_download_session;
  2011. metadata.sessionError = @"";
  2012. metadata.sessionSelector = selectorLoadCopy;
  2013. metadata.status = k_metadataStatusWaitDownload;
  2014. // Add Metadata for Download
  2015. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  2016. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  2017. [appDelegate startLoadAutoDownloadUpload];
  2018. }
  2019. }
  2020. [self tableViewSelect:NO];
  2021. }
  2022. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  2023. {
  2024. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2025. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2026. // Value : (NSData) ocId
  2027. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.ocId], k_metadataKeyedUnarchiver,nil];
  2028. [items addObject:item];
  2029. [pasteboard setItems:items];
  2030. }
  2031. /************************************ OPEN IN ... ******************************/
  2032. - (void)openinFile:(id)sender
  2033. {
  2034. [[NCMainCommon sharedInstance] downloadOpenWithMetadata:self.metadata selector:selectorOpenIn];
  2035. }
  2036. /************************************ OPEN INTERNAL VIEWER ... ******************************/
  2037. - (void)openInternalViewer:(id)sender
  2038. {
  2039. [[NCMainCommon sharedInstance] downloadOpenWithMetadata:self.metadata selector:selectorLoadFileInternalView];
  2040. }
  2041. /************************************ PASTE ************************************/
  2042. - (void)pasteFile:(id)sender
  2043. {
  2044. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2045. [self uploadFilePasteArray:[pasteboard items]];
  2046. }
  2047. - (void)pasteFiles:(id)sender
  2048. {
  2049. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2050. [self uploadFilePasteArray:[pasteboard items]];
  2051. }
  2052. - (void)uploadFilePasteArray:(NSArray *)items
  2053. {
  2054. for (NSDictionary *dic in items) {
  2055. // Value : (NSData) ocId
  2056. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  2057. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  2058. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  2059. if (metadata) {
  2060. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  2061. NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView serverUrl:self.serverUrl account:appDelegate.activeAccount];
  2062. NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:self.serverUrl fileNameView:fileName directory:false];
  2063. [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName]];
  2064. tableMetadata *metadataForUpload = [tableMetadata new];
  2065. metadataForUpload.account = appDelegate.activeAccount;
  2066. metadataForUpload.date = [NSDate new];
  2067. metadataForUpload.ocId = ocId;
  2068. metadataForUpload.fileName = fileName;
  2069. metadataForUpload.fileNameView = fileName;
  2070. metadataForUpload.serverUrl = self.serverUrl;
  2071. metadataForUpload.session = k_upload_session;
  2072. metadataForUpload.sessionSelector = selectorUploadFile;
  2073. metadataForUpload.size = metadata.size;
  2074. metadataForUpload.status = k_metadataStatusWaitUpload;
  2075. // Add Medtadata for upload
  2076. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  2077. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2078. }
  2079. }
  2080. }
  2081. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2082. [appDelegate startLoadAutoDownloadUpload];
  2083. }
  2084. #pragma --------------------------------------------------------------------------------------------
  2085. #pragma mark ===== Lock Passcode =====
  2086. #pragma --------------------------------------------------------------------------------------------
  2087. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2088. {
  2089. return _failedAttempts;
  2090. }
  2091. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2092. {
  2093. return _lockUntilDate;
  2094. }
  2095. - (void)passcodeViewCloseButtonPressed:(id)sender
  2096. {
  2097. [self dismissViewControllerAnimated:YES completion:nil];
  2098. }
  2099. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2100. {
  2101. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2102. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2103. _lockUntilDate = nil;
  2104. _failedAttempts = 0;
  2105. aResultHandler(YES);
  2106. } else aResultHandler(NO);
  2107. } else aResultHandler(YES);
  2108. }
  2109. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2110. {
  2111. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2112. switch (aViewController.type) {
  2113. case BKPasscodeViewControllerCheckPasscodeType: {
  2114. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2115. // possiamo procedere alla prossima directory
  2116. [self performSegueDirectoryWithControlPasscode:false metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2117. // avviamo la sessione Passcode Lock con now
  2118. appDelegate.sessionePasscodeLock = [NSDate date];
  2119. }
  2120. // disattivazione lock cartella
  2121. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2122. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2123. if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO account:appDelegate.activeAccount]) {
  2124. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_error_operation_canc_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  2125. }
  2126. [self tableViewReloadData];
  2127. }
  2128. }
  2129. break;
  2130. default:
  2131. break;
  2132. }
  2133. }
  2134. - (void)comandoLockPassword
  2135. {
  2136. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2137. // se non è abilitato il Lock Passcode esci
  2138. if ([[CCUtility getBlockCode] length] == 0) {
  2139. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) preferredStyle:UIAlertControllerStyleAlert];
  2140. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  2141. [alertController addAction:okAction];
  2142. [self presentViewController:alertController animated:YES completion:nil];
  2143. return;
  2144. }
  2145. // se è richiesta la disattivazione si chiede la password
  2146. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2147. if (directory.lock) {
  2148. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2149. viewController.delegate = self;
  2150. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2151. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2152. viewController.inputViewTitlePassword = YES;
  2153. if ([CCUtility getSimplyBlockCode]) {
  2154. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2155. viewController.passcodeInputView.maximumLength = 6;
  2156. } else {
  2157. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2158. viewController.passcodeInputView.maximumLength = 64;
  2159. }
  2160. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  2161. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2162. viewController.touchIDManager = touchIDManager;
  2163. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2164. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2165. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  2166. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2167. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  2168. [self presentViewController:navigationController animated:YES completion:nil];
  2169. return;
  2170. }
  2171. // ---------------- ACTIVATE PASSWORD
  2172. if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES account:appDelegate.activeAccount]) {
  2173. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:self.metadata.ocId];
  2174. if ([self indexPathIsValid:indexPath])
  2175. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2176. } else {
  2177. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_error_operation_canc_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  2178. }
  2179. }
  2180. #pragma mark -
  2181. #pragma --------------------------------------------------------------------------------------------
  2182. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  2183. #pragma --------------------------------------------------------------------------------------------
  2184. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  2185. {
  2186. if (metadata == nil || _metadataFolder == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || metadata.status != k_metadataStatusNormal || [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])
  2187. return NO;
  2188. // E2EE
  2189. if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
  2190. return NO;
  2191. return YES;
  2192. }
  2193. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  2194. {
  2195. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2196. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2197. return [self canOpenMenuAction:metadata];
  2198. }
  2199. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  2200. {
  2201. }
  2202. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  2203. {
  2204. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2205. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2206. if (direction == MGSwipeDirectionRightToLeft) {
  2207. [self actionDelete:indexPath];
  2208. }
  2209. if (direction == MGSwipeDirectionLeftToRight) {
  2210. if (self.metadata.favorite)
  2211. [self settingFavorite:self.metadata favorite:NO];
  2212. else
  2213. [self settingFavorite:self.metadata favorite:YES];
  2214. }
  2215. return YES;
  2216. }
  2217. - (void)actionDelete:(NSIndexPath *)indexPath
  2218. {
  2219. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2220. // Directory locked ?
  2221. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:metadata.fileName];
  2222. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2223. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2224. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) {
  2225. [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_folder_blocked_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError];
  2226. return;
  2227. }
  2228. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  2229. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2230. [self performSelector:@selector(deleteFile) withObject:nil];
  2231. }]];
  2232. if (localFile) {
  2233. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2234. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2235. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] error:nil];
  2236. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2237. }]];
  2238. }
  2239. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2240. }]];
  2241. alertController.popoverPresentationController.sourceView = self.tableView;
  2242. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  2243. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2244. [alertController.view layoutIfNeeded];
  2245. [self presentViewController:alertController animated:YES completion:nil];
  2246. }
  2247. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  2248. {
  2249. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  2250. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  2251. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2252. NSString *titoloLock, *titleFavorite;
  2253. if (self.metadata.favorite) {
  2254. titleFavorite = NSLocalizedString(@"_remove_favorites_", nil);
  2255. } else {
  2256. titleFavorite = NSLocalizedString(@"_add_favorites_", nil);
  2257. }
  2258. if (self.metadata.directory) {
  2259. // calcolo lockServerUrl
  2260. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2261. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2262. if (directory.lock)
  2263. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  2264. else
  2265. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  2266. }
  2267. // ******************************************* AHKActionSheet *******************************************
  2268. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
  2269. actionSheet.animationDuration = 0.2;
  2270. actionSheet.buttonHeight = 50.0;
  2271. actionSheet.cancelButtonHeight = 50.0f;
  2272. actionSheet.separatorHeight = 5.0f;
  2273. actionSheet.automaticallyTintButtonImages = @(NO);
  2274. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.encrypted };
  2275. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2276. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2277. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2278. actionSheet.separatorColor = NCBrandColor.sharedInstance.separator;
  2279. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  2280. actionSheet.cancelButtonBackgroudColor = NCBrandColor.sharedInstance.backgroundForm;
  2281. // ******************************************* DIRECTORY *******************************************
  2282. if (self.metadata.directory) {
  2283. BOOL lockDirectory = NO;
  2284. BOOL isOffline = NO;
  2285. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2286. BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] account:appDelegate.activeAccount];
  2287. // Directory bloccata ?
  2288. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl]];
  2289. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) lockDirectory = YES;
  2290. if (directory.offline) isOffline = YES;
  2291. [actionSheet addButtonWithTitle:self.metadata.fileNameView
  2292. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:NCBrandColor.sharedInstance.brandElement]
  2293. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2294. height:50.0
  2295. type:AHKActionSheetButtonTypeDisabled
  2296. handler:nil
  2297. ];
  2298. [actionSheet addButtonWithTitle: titleFavorite
  2299. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2300. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2301. height: 50.0
  2302. type: AHKActionSheetButtonTypeDefault
  2303. handler: ^(AHKActionSheet *as) {
  2304. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2305. else [self settingFavorite:self.metadata favorite:YES];
  2306. }];
  2307. if (!lockDirectory && !isFolderEncrypted) {
  2308. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2309. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2310. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2311. height:50.0
  2312. type:AHKActionSheetButtonTypeDefault
  2313. handler:^(AHKActionSheet *as) {
  2314. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2315. }];
  2316. }
  2317. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !self.metadata.e2eEncrypted) {
  2318. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2319. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2320. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2321. height:50.0
  2322. type:AHKActionSheetButtonTypeDefault
  2323. handler:^(AHKActionSheet *as) {
  2324. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2325. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2326. textField.text = self.metadata.fileNameView;
  2327. textField.delegate = self;
  2328. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2329. }];
  2330. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2331. NSLog(@"[LOG] Cancel action");
  2332. }];
  2333. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2334. UITextField *fileName = alertController.textFields.firstObject;
  2335. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2336. }];
  2337. okAction.enabled = NO;
  2338. [alertController addAction:cancelAction];
  2339. [alertController addAction:okAction];
  2340. [self presentViewController:alertController animated:YES completion:nil];
  2341. }];
  2342. }
  2343. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !isFolderEncrypted) {
  2344. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2345. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2346. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2347. height:50.0
  2348. type:AHKActionSheetButtonTypeDefault
  2349. handler:^(AHKActionSheet *as) {
  2350. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2351. }];
  2352. }
  2353. if (!isFolderEncrypted) {
  2354. NSString *title;
  2355. if (isOffline) {
  2356. title = NSLocalizedString(@"_remove_available_offline_", nil);
  2357. } else {
  2358. title = NSLocalizedString(@"_set_available_offline_", nil);
  2359. }
  2360. [actionSheet addButtonWithTitle:title
  2361. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2362. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2363. height:50.0
  2364. type:AHKActionSheetButtonTypeDefault
  2365. handler:^(AHKActionSheet *as) {
  2366. if (isOffline) {
  2367. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:false account:appDelegate.activeAccount];
  2368. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2369. } else {
  2370. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:true account:appDelegate.activeAccount];
  2371. [[CCSynchronize sharedSynchronize] readFolder:dirServerUrl selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  2372. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2373. }
  2374. }];
  2375. }
  2376. [actionSheet addButtonWithTitle:titoloLock
  2377. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2378. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2379. height:50.0
  2380. type:AHKActionSheetButtonTypeDefault
  2381. handler:^(AHKActionSheet *as) {
  2382. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  2383. }];
  2384. if (!self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2385. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_set_folder_encrypted_", nil)
  2386. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2387. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2388. height:50.0
  2389. type:AHKActionSheetButtonTypeDefault
  2390. handler:^(AHKActionSheet *as) {
  2391. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  2392. 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];
  2393. dispatch_async(dispatch_get_main_queue(), ^{
  2394. if (error) {
  2395. [[NCContentPresenter shared] messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  2396. } else {
  2397. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2398. [self readFolder:self.serverUrl];
  2399. }
  2400. });
  2401. });
  2402. }];
  2403. }
  2404. if (self.metadata.e2eEncrypted && !_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2405. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_remove_folder_encrypted_", nil)
  2406. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2407. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2408. height:50.0
  2409. type:AHKActionSheetButtonTypeDefault
  2410. handler:^(AHKActionSheet *as) {
  2411. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2412. 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];
  2413. dispatch_async(dispatch_get_main_queue(), ^{
  2414. if (error) {
  2415. [[NCContentPresenter shared] messageNotification:@"_e2e_error_delete_mark_folder_" description:error.localizedDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code];
  2416. } else {
  2417. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2418. [self readFolder:self.serverUrl];
  2419. }
  2420. });
  2421. });
  2422. }];
  2423. }
  2424. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2425. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2426. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2427. height:50.0
  2428. type:AHKActionSheetButtonTypeDestructive
  2429. handler:^(AHKActionSheet *as) {
  2430. [self actionDelete:indexPath];
  2431. }];
  2432. [actionSheet show];
  2433. }
  2434. // ******************************************* FILE *******************************************
  2435. if (!self.metadata.directory) {
  2436. UIImage *iconHeader;
  2437. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  2438. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]])
  2439. iconHeader = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]];
  2440. else
  2441. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  2442. [actionSheet addButtonWithTitle: self.metadata.fileNameView
  2443. image: iconHeader
  2444. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2445. height: 50.0
  2446. type: AHKActionSheetButtonTypeDisabled
  2447. handler: nil
  2448. ];
  2449. [actionSheet addButtonWithTitle: titleFavorite
  2450. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2451. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2452. height: 50.0
  2453. type: AHKActionSheetButtonTypeDefault
  2454. handler: ^(AHKActionSheet *as) {
  2455. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2456. else [self settingFavorite:self.metadata favorite:YES];
  2457. }];
  2458. if (!_metadataFolder.e2eEncrypted) {
  2459. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2460. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2461. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2462. height: 50.0
  2463. type:AHKActionSheetButtonTypeDefault
  2464. handler:^(AHKActionSheet *as) {
  2465. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2466. }];
  2467. }
  2468. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  2469. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  2470. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2471. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2472. height: 50.0
  2473. type:AHKActionSheetButtonTypeDefault
  2474. handler:^(AHKActionSheet *as) {
  2475. [self performSelector:@selector(openinFile:) withObject:nil];
  2476. }];
  2477. }
  2478. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2479. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2480. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2481. height: 50.0
  2482. type:AHKActionSheetButtonTypeDefault
  2483. handler:^(AHKActionSheet *as) {
  2484. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2485. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2486. textField.text = self.metadata.fileNameView;
  2487. textField.delegate = self;
  2488. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2489. }];
  2490. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2491. NSLog(@"[LOG] Cancel action");
  2492. }];
  2493. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2494. UITextField *fileName = alertController.textFields.firstObject;
  2495. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2496. }];
  2497. okAction.enabled = NO;
  2498. [alertController addAction:cancelAction];
  2499. [alertController addAction:okAction];
  2500. [self presentViewController:alertController animated:YES completion:nil];
  2501. }];
  2502. if (!_metadataFolder.e2eEncrypted) {
  2503. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2504. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2505. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2506. height:50.0
  2507. type:AHKActionSheetButtonTypeDefault
  2508. handler:^(AHKActionSheet *as) {
  2509. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2510. }];
  2511. }
  2512. if ([NCUtility.sharedInstance isEditImage:self.metadata.fileNameView] != nil && !_metadataFolder.e2eEncrypted && self.metadata.status == k_metadataStatusNormal) {
  2513. [actionSheet addButtonWithTitle:NSLocalizedString(@"_modify_photo_", nil)
  2514. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"modifyPhoto"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2515. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2516. height:50.0
  2517. type:AHKActionSheetButtonTypeDefault
  2518. handler:^(AHKActionSheet *as) {
  2519. self.metadata.session = k_download_session;
  2520. self.metadata.sessionError = @"";
  2521. self.metadata.sessionSelector = selectorDownloadEditPhoto;
  2522. self.metadata.status = k_metadataStatusWaitDownload;
  2523. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2524. [appDelegate startLoadAutoDownloadUpload];
  2525. }];
  2526. }
  2527. if (!_metadataFolder.e2eEncrypted) {
  2528. NSString *title;
  2529. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", self.metadata.ocId]];
  2530. if (localFile == nil || localFile.offline == false) { title = NSLocalizedString(@"_set_available_offline_", nil); }
  2531. else { title = NSLocalizedString(@"_remove_available_offline_", nil); }
  2532. [actionSheet addButtonWithTitle:title
  2533. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2534. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2535. height:50.0
  2536. type:AHKActionSheetButtonTypeDefault
  2537. handler:^(AHKActionSheet *as) {
  2538. if (localFile == nil || ![CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2539. self.metadata.session = k_download_session;
  2540. self.metadata.sessionError = @"";
  2541. self.metadata.sessionSelector = selectorLoadOffline;
  2542. self.metadata.status = k_metadataStatusWaitDownload;
  2543. // Add Metadata for Download
  2544. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2545. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2546. [appDelegate startLoadAutoDownloadUpload];
  2547. } else if (localFile.offline == false) {
  2548. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:true];
  2549. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2550. } else {
  2551. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:false];
  2552. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2553. }
  2554. }];
  2555. }
  2556. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2557. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2558. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2559. height:50.0
  2560. type:AHKActionSheetButtonTypeDestructive
  2561. handler:^(AHKActionSheet *as) {
  2562. [self actionDelete:indexPath];
  2563. }];
  2564. [actionSheet show];
  2565. }
  2566. }
  2567. #pragma --------------------------------------------------------------------------------------------
  2568. #pragma mark - ==== Datasource ====
  2569. #pragma --------------------------------------------------------------------------------------------
  2570. - (void)clearDateReadDataSource:(NSNotification *)notification
  2571. {
  2572. _dateReadDataSource = Nil;
  2573. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2574. }
  2575. - (void)reloadDatasource:(NSString *)serverUrl ocId:(NSString *)ocId action:(NSInteger)action
  2576. {
  2577. // test
  2578. if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
  2579. return;
  2580. // Search Mode
  2581. if (self.searchController.isActive) {
  2582. // Create metadatas
  2583. NSMutableArray *metadatas = [NSMutableArray new];
  2584. for (tableMetadata *resultMetadata in _searchResultMetadatas) {
  2585. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", resultMetadata.ocId]];
  2586. if (metadata) {
  2587. [metadatas addObject:metadata];
  2588. }
  2589. }
  2590. // [CCUtility getGroupBySettings]
  2591. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:nil filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:@"fileName" ascending:NO activeAccount:appDelegate.activeAccount];
  2592. [self tableViewReloadData];
  2593. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  2594. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  2595. _noFilesSearchDescription = @"";
  2596. }
  2597. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  2598. _noFilesSearchTitle = @"";
  2599. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  2600. }
  2601. [self.tableView reloadEmptyDataSet];
  2602. return;
  2603. }
  2604. // Se non siamo nella dir appropriata esci
  2605. if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
  2606. return;
  2607. }
  2608. // Controllo data lettura Data Source
  2609. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  2610. if (tableDirectory == nil) {
  2611. return;
  2612. }
  2613. // Get MetadataFolder
  2614. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
  2615. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, k_serverUrl_root]];
  2616. else
  2617. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tableDirectory.ocId]];
  2618. // Remove optimization for encrypted directory
  2619. if (_metadataFolder.e2eEncrypted)
  2620. _dateReadDataSource = nil;
  2621. NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
  2622. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  2623. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  2624. _dateReadDataSource = [NSDate date];
  2625. // Data Source
  2626. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2627. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
  2628. dispatch_async(dispatch_get_main_queue(), ^{
  2629. sectionDataSource = sectionDataSourceTemp;
  2630. [self tableViewReloadData];
  2631. });
  2632. });
  2633. } else {
  2634. [self tableViewReloadData];
  2635. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  2636. }
  2637. // BLINK
  2638. if (self.blinkFileNamePath != nil) {
  2639. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2640. for (NSString *key in sectionDataSource.allRecordsDataSource) {
  2641. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:key];
  2642. NSString *metadataFileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  2643. if ([metadataFileNamePath isEqualToString:self.blinkFileNamePath]) {
  2644. for (NSString *key in sectionDataSource.ocIdIndexPath) {
  2645. if ([key isEqualToString:metadata.ocId]) {
  2646. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:key];
  2647. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  2648. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2649. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  2650. if (cell) {
  2651. self.blinkFileNamePath = nil;
  2652. [[NCUtility sharedInstance] blinkWithCell:cell];
  2653. }
  2654. });
  2655. }
  2656. }
  2657. }
  2658. }
  2659. });
  2660. }
  2661. }
  2662. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
  2663. {
  2664. // test
  2665. if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
  2666. return nil;
  2667. }
  2668. // get auto upload folder
  2669. _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  2670. _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
  2671. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  2672. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND status != %i", appDelegate.activeAccount, serverUrl, k_metadataStatusHide] sorted:nil ascending:NO];
  2673. // [CCUtility getGroupBySettings]
  2674. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings] activeAccount:appDelegate.activeAccount];
  2675. if (withReloadData) {
  2676. sectionDataSource = sectionDataSourceTemp;
  2677. [self tableViewReloadData];
  2678. }
  2679. return sectionDataSourceTemp;
  2680. }
  2681. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  2682. {
  2683. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  2684. if (selectedRows.count > 0) {
  2685. for (NSIndexPath *selectionIndex in selectedRows) {
  2686. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  2687. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2688. [metadatas addObject:metadata];
  2689. }
  2690. }
  2691. return metadatas;
  2692. }
  2693. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  2694. {
  2695. NSInteger totSections =[sectionDataSource.sections count] ;
  2696. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  2697. return nil;
  2698. }
  2699. id valueSection = [sectionDataSource.sections objectAtIndex:section];
  2700. return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
  2701. }
  2702. #pragma --------------------------------------------------------------------------------------------
  2703. #pragma mark - ==== Table ====
  2704. #pragma --------------------------------------------------------------------------------------------
  2705. - (void)tableViewSelect:(BOOL)edit
  2706. {
  2707. // chiudiamo eventuali swipe aperti
  2708. if (edit)
  2709. [self.tableView setEditing:NO animated:NO];
  2710. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  2711. [self.tableView setEditing:edit animated:YES];
  2712. _isSelectedMode = edit;
  2713. if (edit)
  2714. [self setUINavigationBarSelected];
  2715. else
  2716. [self setUINavigationBarDefault];
  2717. [_selectedocIdsMetadatas removeAllObjects];
  2718. [self setTitle];
  2719. }
  2720. - (void)tableViewReloadData
  2721. {
  2722. // store selected cells before relod
  2723. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  2724. // reload table view
  2725. [self.tableView reloadData];
  2726. // selected cells stored
  2727. for (NSIndexPath *path in indexPaths)
  2728. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  2729. [self setTableViewHeader];
  2730. [self setTableViewFooter];
  2731. if (self.tableView.editing)
  2732. [self setTitle];
  2733. [self.tableView reloadEmptyDataSet];
  2734. }
  2735. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  2736. {
  2737. if (tableView.editing == 1) {
  2738. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2739. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  2740. return NO;
  2741. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  2742. return NO;
  2743. else
  2744. return YES;
  2745. } else {
  2746. [_selectedocIdsMetadatas removeAllObjects];
  2747. }
  2748. return YES;
  2749. }
  2750. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  2751. {
  2752. return 60;
  2753. }
  2754. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2755. {
  2756. return [[sectionDataSource.sectionArrayRow allKeys] count];
  2757. }
  2758. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2759. {
  2760. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  2761. }
  2762. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2763. {
  2764. NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
  2765. NSString *sectionTitle = [sections objectAtIndex:section];
  2766. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  2767. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  2768. if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  2769. return 20.f;
  2770. }
  2771. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2772. {
  2773. float shift;
  2774. UIVisualEffectView *visualEffectView;
  2775. NSString *titleSection;
  2776. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  2777. return nil;
  2778. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  2779. titleSection = [sectionDataSource.sections objectAtIndex:section];
  2780. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  2781. titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  2782. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  2783. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  2784. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  2785. else titleSection = NSLocalizedString(titleSection,nil);
  2786. // Format title
  2787. UIVisualEffect *blurEffect;
  2788. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  2789. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  2790. visualEffectView.backgroundColor = [NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.2];
  2791. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
  2792. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2793. shift = - 35;
  2794. else
  2795. shift = - 20;
  2796. } else shift = - 10;
  2797. // Title
  2798. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  2799. titleLabel.backgroundColor = [UIColor clearColor];
  2800. titleLabel.textColor = NCBrandColor.sharedInstance.textView;
  2801. titleLabel.font = [UIFont systemFontOfSize:12];
  2802. titleLabel.textAlignment = NSTextAlignmentLeft;
  2803. titleLabel.text = titleSection;
  2804. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2805. [visualEffectView.contentView addSubview:titleLabel];
  2806. // Elements
  2807. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  2808. elementLabel.backgroundColor = [UIColor clearColor];
  2809. elementLabel.textColor = NCBrandColor.sharedInstance.textView;
  2810. elementLabel.font = [UIFont systemFontOfSize:12];
  2811. elementLabel.textAlignment = NSTextAlignmentRight;
  2812. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2813. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  2814. NSUInteger rowsCount = [metadatas count];
  2815. if (rowsCount == 0) return nil;
  2816. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  2817. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  2818. [visualEffectView.contentView addSubview:elementLabel];
  2819. return visualEffectView;
  2820. }
  2821. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  2822. {
  2823. return [sectionDataSource.sections indexOfObject:title];
  2824. }
  2825. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  2826. {
  2827. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
  2828. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  2829. else
  2830. return nil;
  2831. }
  2832. /*
  2833. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  2834. {
  2835. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  2836. }
  2837. }
  2838. */
  2839. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2840. {
  2841. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2842. tableShare *shareCell;
  2843. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || (_metadataFolder != nil && [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])) {
  2844. return [CCCellMain new];
  2845. }
  2846. for (tableShare *share in appDelegate.shares) {
  2847. if ([share.serverUrl isEqualToString:metadata.serverUrl] && [share.fileName isEqualToString:metadata.fileName]) {
  2848. shareCell = share;
  2849. break;
  2850. }
  2851. }
  2852. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory tableShare:shareCell];
  2853. // NORMAL - > MAIN
  2854. if ([cell isKindOfClass:[CCCellMain class]]) {
  2855. // Comment tap
  2856. if (metadata.commentsUnread) {
  2857. UITapGestureRecognizer *tapComment = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionComment:)];
  2858. [tapComment setNumberOfTapsRequired:1];
  2859. ((CCCellMain *)cell).comment.userInteractionEnabled = YES;
  2860. [((CCCellMain *)cell).comment addGestureRecognizer:tapComment];
  2861. }
  2862. // Share add Tap
  2863. UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  2864. [tapShare setNumberOfTapsRequired:1];
  2865. ((CCCellMain *)cell).viewShared.userInteractionEnabled = YES;
  2866. [((CCCellMain *)cell).viewShared addGestureRecognizer:tapShare];
  2867. // More
  2868. if ([self canOpenMenuAction:metadata]) {
  2869. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  2870. [tapMore setNumberOfTapsRequired:1];
  2871. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  2872. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  2873. }
  2874. // MGSwipeButton
  2875. ((CCCellMain *)cell).delegate = self;
  2876. // LEFT
  2877. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellFavouriteImage backgroundColor:NCBrandColor.sharedInstance.yellowFavorite padding:25]];
  2878. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  2879. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  2880. //centerIconOverText
  2881. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  2882. [favoriteButton centerIconOverText];
  2883. // RIGHT
  2884. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellTrashImage backgroundColor:[UIColor redColor] padding:25]];
  2885. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  2886. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  2887. //centerIconOverText
  2888. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  2889. [deleteButton centerIconOverText];
  2890. }
  2891. // TRANSFER
  2892. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  2893. // gesture Transfer
  2894. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  2895. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  2896. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  2897. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  2898. }
  2899. return cell;
  2900. }
  2901. - (void)setTableViewHeader
  2902. {
  2903. // Nextcloud 18
  2904. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  2905. if (capabilities.versionMajor < k_nextcloud_version_18_0) {
  2906. [self.tableView setTableHeaderView:nil];
  2907. } else {
  2908. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
  2909. if (directory.richWorkspace.length == 0) {
  2910. [self.tableView setTableHeaderView:nil];
  2911. } else {
  2912. [self.viewRichWorkspace setRichWorkspaceText:directory.richWorkspace];
  2913. [self.viewRichWorkspace setFrame:CGRectMake(0, 0, self.tableView.frame.size.width, CCUtility.getRichWorkspaceHeight)];
  2914. [self.tableView setTableHeaderView:self.viewRichWorkspace];
  2915. }
  2916. }
  2917. [self.tableView reloadData];
  2918. }
  2919. - (void)setTableViewFooter
  2920. {
  2921. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2922. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2923. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2924. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2925. UIFont *appFont = [UIFont systemFontOfSize:12];
  2926. footerLabel.font = appFont;
  2927. footerLabel.textColor = [UIColor grayColor];
  2928. footerLabel.backgroundColor = [UIColor clearColor];
  2929. footerLabel.textAlignment = NSTextAlignmentCenter;
  2930. NSString *folders;
  2931. NSString *files;
  2932. NSString *footerText;
  2933. if (sectionDataSource.directories > 1) {
  2934. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  2935. } else if (sectionDataSource.directories == 1){
  2936. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  2937. } else {
  2938. folders = @"";
  2939. }
  2940. if (sectionDataSource.files > 1) {
  2941. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2942. } else if (sectionDataSource.files == 1){
  2943. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2944. } else {
  2945. files = @"";
  2946. }
  2947. if ([folders isEqualToString:@""]) {
  2948. footerText = files;
  2949. } else if ([files isEqualToString:@""]) {
  2950. footerText = folders;
  2951. } else {
  2952. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  2953. }
  2954. footerLabel.text = footerText;
  2955. [footerView addSubview:footerLabel];
  2956. [self.tableView setTableFooterView:footerView];
  2957. }
  2958. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2959. {
  2960. CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
  2961. // settiamo il record file.
  2962. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2963. if (!self.metadata)
  2964. return;
  2965. // se non può essere selezionata deseleziona
  2966. if ([cell isEditing] == NO)
  2967. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  2968. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  2969. if (self.tableView.editing) {
  2970. [_selectedocIdsMetadatas setObject:self.metadata forKey:self.metadata.ocId];
  2971. [self setTitle];
  2972. return;
  2973. }
  2974. // se è in corso una sessione
  2975. if (self.metadata.status != k_metadataStatusNormal)
  2976. return;
  2977. // file
  2978. if (self.metadata.directory == NO) {
  2979. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  2980. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2981. [[NCNetworkingMain sharedInstance] downloadFileSuccessFailure:self.metadata.fileName ocId:self.metadata.ocId serverUrl:self.metadata.serverUrl selector:selectorLoadFileView errorMessage:@"" errorCode:0];
  2982. } else {
  2983. if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2984. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2985. } else {
  2986. 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) {
  2987. [self shouldPerformSegue:self.metadata selector:@""];
  2988. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isDirectEditing:self.metadata] != nil) {
  2989. if (appDelegate.reachability.isReachable) {
  2990. [self shouldPerformSegue:self.metadata selector:@""];
  2991. } else {
  2992. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  2993. }
  2994. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isRichDocument:self.metadata]) {
  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 {
  3001. self.metadata.session = k_download_session;
  3002. self.metadata.sessionError = @"";
  3003. self.metadata.sessionSelector = selectorLoadFileView;
  3004. self.metadata.status = k_metadataStatusWaitDownload;
  3005. // Add Metadata for Download
  3006. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  3007. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  3008. [appDelegate startLoadAutoDownloadUpload];
  3009. }
  3010. }
  3011. }
  3012. }
  3013. if (self.metadata.directory) {
  3014. [self performSegueDirectoryWithControlPasscode:true metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  3015. }
  3016. }
  3017. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  3018. {
  3019. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3020. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  3021. [self setTitle];
  3022. }
  3023. - (void)didSelectAll
  3024. {
  3025. for (int i = 0; i < self.tableView.numberOfSections; i++) {
  3026. for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
  3027. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3028. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3029. [_selectedocIdsMetadatas setObject:metadata forKey:metadata.ocId];
  3030. [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  3031. }
  3032. }
  3033. [self setTitle];
  3034. }
  3035. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  3036. {
  3037. if (!indexPath)
  3038. return NO;
  3039. NSInteger section = indexPath.section;
  3040. NSInteger row = indexPath.row;
  3041. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  3042. if (section > lastSectionIndex || lastSectionIndex < 0)
  3043. return NO;
  3044. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  3045. if (rowCount < 0)
  3046. return NO;
  3047. return row <= rowCount;
  3048. }
  3049. #pragma --------------------------------------------------------------------------------------------
  3050. #pragma mark ===== Navigation ====
  3051. #pragma --------------------------------------------------------------------------------------------
  3052. - (void)shouldPerformSegue:(tableMetadata *)metadata selector:(NSString *)selector
  3053. {
  3054. // if background return
  3055. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  3056. if (self.view.window == NO)
  3057. return;
  3058. // Collapsed ma siamo già in detail esci
  3059. if (self.splitViewController.isCollapsed)
  3060. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return;
  3061. // Metadata for push detail
  3062. self.metadataForPushDetail = metadata;
  3063. self.selectorForPushDetail = selector;
  3064. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  3065. }
  3066. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  3067. {
  3068. id viewController = segue.destinationViewController;
  3069. tableMetadata *metadata;
  3070. if ([viewController isKindOfClass:[UINavigationController class]]) {
  3071. UINavigationController *nav = viewController;
  3072. _detailViewController = (CCDetail *)nav.topViewController;
  3073. } else {
  3074. _detailViewController = segue.destinationViewController;
  3075. }
  3076. NSMutableArray *photoDataSource = [NSMutableArray new];
  3077. if ([sender isKindOfClass:[tableMetadata class]]) {
  3078. metadata = sender;
  3079. [photoDataSource addObject:sender];
  3080. } else {
  3081. metadata = self.metadataForPushDetail;
  3082. for (NSString *ocId in sectionDataSource.allOcId) {
  3083. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  3084. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  3085. [photoDataSource addObject:metadata];
  3086. }
  3087. }
  3088. _detailViewController.metadataDetail = metadata;
  3089. _detailViewController.selectorDetail = self.selectorForPushDetail;
  3090. _detailViewController.photoDataSource = photoDataSource;
  3091. _detailViewController.dateFilterQuery = nil;
  3092. [_detailViewController setTitle:metadata.fileNameView];
  3093. }
  3094. // can i go to next viewcontroller
  3095. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode metadata:(tableMetadata *)metadata blinkFileNamePath:(NSString *)blinkFileNamePath
  3096. {
  3097. NSString *nomeDir;
  3098. if (self.tableView.editing == NO) {
  3099. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  3100. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", metadata.account, lockServerUrl]];
  3101. // 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
  3102. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil && controlPasscode) {
  3103. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3104. viewController.delegate = self;
  3105. viewController.fromType = CCBKPasscodeFromLockDirectory;
  3106. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3107. viewController.inputViewTitlePassword = YES;
  3108. if ([CCUtility getSimplyBlockCode]) {
  3109. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  3110. viewController.passcodeInputView.maximumLength = 6;
  3111. } else {
  3112. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3113. viewController.passcodeInputView.maximumLength = 64;
  3114. }
  3115. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  3116. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  3117. viewController.touchIDManager = touchIDManager;
  3118. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  3119. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3120. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  3121. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3122. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  3123. [self presentViewController:navigationController animated:YES completion:nil];
  3124. return;
  3125. }
  3126. // E2EE Check enable
  3127. if (metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
  3128. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  3129. return;
  3130. }
  3131. nomeDir = metadata.fileName;
  3132. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:nomeDir];
  3133. CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
  3134. if (!viewController) {
  3135. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
  3136. viewController.serverUrl = serverUrlPush;
  3137. viewController.titleMain = metadata.fileName;
  3138. viewController.blinkFileNamePath = blinkFileNamePath;
  3139. // save self
  3140. [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
  3141. [self.navigationController pushViewController:viewController animated:YES];
  3142. } else {
  3143. if (viewController.isViewLoaded) {
  3144. viewController.titleMain = metadata.fileName;
  3145. viewController.blinkFileNamePath = blinkFileNamePath;
  3146. // Fix : Application tried to present modally an active controller
  3147. if ([self.navigationController isBeingPresented]) {
  3148. // being presented
  3149. } else if ([self.navigationController isMovingToParentViewController]) {
  3150. // being pushed
  3151. } else {
  3152. [self.navigationController pushViewController:viewController animated:YES];
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. @end