CCMain.m 199 KB

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