CCMain.m 210 KB

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