CCMain.m 201 KB

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