CCMain.m 198 KB

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