CCMain.m 201 KB

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