CCMain.m 198 KB

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