CCMain.m 197 KB

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