CCMain.m 198 KB

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