CCMain.m 209 KB

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