CCMain.m 199 KB

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