123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569 |
- //
- // CCMain.m
- // Nextcloud iOS
- //
- // Created by Marino Faggiana on 04/09/14.
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- #import <JDStatusBarNotification/JDStatusBarNotification.h>
- #import "CCMain.h"
- #import "AppDelegate.h"
- #import "CCMedia.h"
- #import "CCSynchronize.h"
- #import "OCActivity.h"
- #import "OCNotifications.h"
- #import "OCNotificationsAction.h"
- #import "OCFrameworkConstants.h"
- #import "OCCapabilities.h"
- #import "NCAutoUpload.h"
- #import "NCBridgeSwift.h"
- #import "NCNetworkingEndToEnd.h"
- #import "PKDownloadButton.h"
- @interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, CCLoginDelegate, CCLoginDelegateWeb, NCSelectDelegate>
- {
- AppDelegate *appDelegate;
-
- BOOL _isRoot;
- BOOL _isViewDidLoad;
-
- NSMutableDictionary *_selectedFileIDsMetadatas;
- NSUInteger _numSelectedFileIDsMetadatas;
- NSMutableArray *_queueSelector;
-
- UIImageView *_imageTitleHome;
-
- NSUInteger _failedAttempts;
- NSDate *_lockUntilDate;
- UIRefreshControl *refreshControl;
- UIDocumentInteractionController *docController;
- CCHud *_hud;
-
- // Datasource
- CCSectionDataSourceMetadata *sectionDataSource;
- NSDate *_dateReadDataSource;
-
- // Search
- BOOL _isSearchMode;
- NSString *_searchFileName;
- NSMutableArray *_searchResultMetadatas;
- NSString *_noFilesSearchTitle;
- NSString *_noFilesSearchDescription;
- NSTimer *_timerWaitInput;
- // Automatic Upload Folder
- NSString *_autoUploadFileName;
- NSString *_autoUploadDirectory;
-
- // Folder
- BOOL _loadingFolder;
- tableMetadata *_metadataFolder;
-
- // Image Title Segue
- UIImage *imageTitleSegue;
- }
- @end
- @implementation CCMain
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
-
- // Active Main
- appDelegate.activeMain = self;
- }
-
- return self;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== View =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // init object
- self.metadata = [tableMetadata new];
- _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
- _selectedFileIDsMetadatas = [NSMutableDictionary new];
- _queueSelector = [NSMutableArray new];
- _isViewDidLoad = YES;
- _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
- _searchResultMetadatas = [NSMutableArray new];
- _searchFileName = @"";
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = @"";
-
- // delegate
- self.tableView.delegate = self;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.separatorColor = [NCBrandColor sharedInstance].seperator;
- self.tableView.emptyDataSetDelegate = self;
- self.tableView.emptyDataSetSource = self;
- self.searchController.delegate = self;
- self.searchController.searchBar.delegate = self;
-
- // Register cell
- [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
- [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
-
- // long press recognizer TableView
- UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
- [self.tableView addGestureRecognizer:longPressRecognizer];
-
- // Pull-to-Refresh
- [self createRefreshControl];
-
- // Register for 3D Touch Previewing if available
- if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
- {
- [self registerForPreviewingWithDelegate:self sourceView:self.view];
- }
- // reMenu Background
- _reMenuBackgroundView = [UIView new];
- _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
-
- // if this is not Main (the Main uses inizializeMain)
- if (_isRoot == NO && appDelegate.activeAccount.length > 0) {
- // Read (File) Folder
- [self readFileReloadFolder];
- }
-
- // Title
- [self setTitle];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // test
- if (appDelegate.activeAccount.length == 0)
- return;
-
- // Color
- [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
- [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- // Plus Button
- [appDelegate plusButtonVisibile:true];
- if (_isSelectedMode)
- [self setUINavigationBarSelected];
- else
- [self setUINavigationBarDefault];
-
- // If not editing mode remove _selectedFileIDs
- if (!self.tableView.editing)
- [_selectedFileIDsMetadatas removeAllObjects];
-
- // Search Bar
- if ([CCUtility isFolderEncrypted:self.serverUrl account:appDelegate.activeAccount]) {
- [self searchEnabled:NO];
- } else {
- [self searchEnabled:YES];
- }
-
- // Query data source
- if (!_isSearchMode) {
- [self queryDatasourceWithReloadData:YES serverUrl:self.serverUrl];
- }
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- // Active Main
- appDelegate.activeMain = self;
-
- // Test viewDidLoad
- if (_isViewDidLoad) {
-
- _isViewDidLoad = NO;
-
- } else {
-
- if (appDelegate.activeAccount.length > 0 && [_selectedFileIDsMetadatas count] == 0) {
-
- // Read (file) Folder
- [self readFileReloadFolder];
- }
- }
- // Title
- [self setTitle];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- [self closeAllMenu];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
- {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [self closeAllMenu];
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
-
- 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))) {
-
- // Portrait
-
- } else {
-
- // Landscape
- }
-
- [self.tableView reloadData];
- }];
- }
- - (BOOL)prefersStatusBarHidden
- {
- return NO;
- }
- // detect scroll for remove keyboard in search mode
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- if (_isSearchMode && scrollView == self.tableView) {
-
- [self.searchController.searchBar endEditing:YES];
- }
- }
- - (void)changeTheming
- {
- if (self.isViewLoaded && self.view.window)
- [appDelegate changeTheming:self];
-
- // Refresh control
- refreshControl.tintColor = [NCBrandColor sharedInstance].brandText;
- refreshControl.backgroundColor = [NCBrandColor sharedInstance].brand;
- // color searchbar
- self.searchController.searchBar.barTintColor = [NCBrandColor sharedInstance].brand;
- self.searchController.searchBar.backgroundColor = [NCBrandColor sharedInstance].brand;
- // color searchbbar button text (cancel)
- UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
- if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
- [searchButton setTitleColor:[NCBrandColor sharedInstance].brandText forState:UIControlStateNormal];
- }
-
- // Title
- [self setTitle];
-
- // Reload Table View
- [self tableViewReloadData];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Initizlize Mail =====
- #pragma --------------------------------------------------------------------------------------------
- //
- // Callers :
- //
- // loginSuccess (delagate)
- // ChangeDefaultAccount (delegate)
- // Split : inizialize
- // Settings Advanced : removeAllFiles
- //
- - (void)initializeMain:(NSNotification *)notification
- {
- _dateReadDataSource = nil;
-
- // test
- if (appDelegate.activeAccount.length == 0)
- return;
-
- if ([appDelegate.listMainVC count] == 0 || _isRoot) {
-
- // This is Root home main add list
- appDelegate.homeMain = self;
- _isRoot = YES;
- _serverUrl = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
- [appDelegate.listMainVC setObject:self forKey:_serverUrl];
-
- // go Home
- [self.navigationController popToRootViewControllerAnimated:NO];
-
- // setting Networking
- [[CCNetworking sharedNetworking] settingAccount];
-
- // Remove search mode
- [self cancelSearchBar];
-
- // populate shared Link & User
- NSArray *results = [[NCManageDatabase sharedInstance] getShares];
- if (results) {
- appDelegate.sharesLink = results[0];
- appDelegate.sharesUserAndGroup = results[1];
- }
-
- // Setting Theming
- [appDelegate settingThemingColorBrand];
-
- // Detail
- // If AVPlayer in play -> Stop
- if (appDelegate.player != nil && appDelegate.player.rate != 0) {
- [appDelegate.player pause];
- }
- for (UIView *view in [appDelegate.activeDetail.view subviews]) {
- if ([view isKindOfClass:[UIImageView class]] == NO) { // View Image Nextcloud
- [view removeFromSuperview];
- }
- }
- appDelegate.activeDetail.title = nil;
-
- // remove all Notification Messages
- [appDelegate.listOfNotifications removeAllObjects];
-
- // Not Photos Video in library ? then align and Init Auto Upload
- NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
- if ([recordsPhotoLibrary count] == 0) {
- [[NCAutoUpload sharedInstance] alignPhotoLibrary];
- }
- [[NCAutoUpload sharedInstance] initStateAutoUpload];
-
- NSLog(@"[LOG] Request Service Server Nextcloud");
- [[NCService sharedInstance] startRequestServicesServer];
-
- // Clear datasorce
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl fileID:nil action:k_action_NULL];
-
- // Read this folder
- [self readFileReloadFolder];
-
- } else {
-
- // reload datasource
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl fileID:nil action:k_action_NULL];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== DZNEmptyDataSetSource ====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
- {
- if (_loadingFolder)
- return NO;
- else
- return YES;
- }
- - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [NCBrandColor sharedInstance].backgroundView;
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
- {
- if (_isSearchMode)
- return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"searchBig"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
- else
- return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"filesNoFiles"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
- }
- - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
- {
- if (_loadingFolder && refreshControl.isRefreshing == NO) {
-
- UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
- activityView.color = [NCBrandColor sharedInstance].brandElement;
- [activityView startAnimating];
-
- return activityView;
- }
-
- return nil;
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text;
-
- if (_isSearchMode) {
-
- text = _noFilesSearchTitle;
-
- } else {
-
- text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
- }
-
- NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text;
-
- if (_isSearchMode) {
-
- text = _noFilesSearchDescription;
-
- } else {
-
- text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
- }
-
- NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
- paragraph.lineBreakMode = NSLineBreakByWordWrapping;
- paragraph.alignment = NSTextAlignmentCenter;
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Text Field =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)minCharTextFieldDidChange:(UITextField *)sender
- {
- UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
-
- if (alertController)
- {
- UITextField *fileName = alertController.textFields.firstObject;
- UIAlertAction *okAction = alertController.actions.lastObject;
- okAction.enabled = fileName.text.length > 0;
- }
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField{
- [textField selectAll:textField];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Graphic Window =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createRefreshControl
- {
- refreshControl = [UIRefreshControl new];
-
- if (@available(iOS 10, *)) {
- _tableView.refreshControl = refreshControl;
- } else {
- [_tableView addSubview:refreshControl];
- }
-
- refreshControl.tintColor = [NCBrandColor sharedInstance].brandText;
- refreshControl.backgroundColor = [NCBrandColor sharedInstance].brand;
-
- [refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
- }
- - (void)deleteRefreshControl
- {
- [refreshControl endRefreshing];
-
- for (UIView *subview in [_tableView subviews]) {
- if (subview == refreshControl)
- [subview removeFromSuperview];
- }
-
- if (@available(iOS 10, *)) {
- self.tableView.refreshControl = nil;
- }
-
- refreshControl = nil;
- }
- - (void)refreshControlTarget
- {
- [self readFolder:_serverUrl];
-
- // Actuate `Peek` feedback (weak boom)
- AudioServicesPlaySystemSound(1519);
-
- [_imageTitleHome setUserInteractionEnabled:NO];
- }
- - (void)setTitle
- {
- // Color text self.navigationItem.title
- [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
- if (_isSelectedMode) {
-
- NSUInteger totali = [sectionDataSource.allRecordsDataSource count];
- NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
-
- self.navigationItem.titleView = nil;
- self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
- } else {
-
- // we are in home : LOGO BRAND
- if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
-
- self.navigationItem.title = nil;
- UIImage *image = [self getImageLogoHome];
- _imageTitleHome = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; // IMAGE = 120 x 60
- _imageTitleHome.contentMode = UIViewContentModeScaleAspectFill;
-
- if ([[[UIDevice currentDevice] systemVersion] floatValue] < 10.0) {
- _imageTitleHome.translatesAutoresizingMaskIntoConstraints = YES; //iOS 9
- } else {
- _imageTitleHome.translatesAutoresizingMaskIntoConstraints = NO; //iOS >= 9
- }
- _imageTitleHome.image = image;
-
- // backbutton
- self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
-
- [_imageTitleHome setUserInteractionEnabled:YES];
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuLogo:)];
- [singleTap setNumberOfTapsRequired:1];
- [_imageTitleHome addGestureRecognizer:singleTap];
-
- self.navigationItem.titleView = _imageTitleHome;
-
- } else {
-
- NSString *shareLink, *shareUserAndGroup;
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataFolder.directoryID];
- if (serverUrl) {
- shareLink = [appDelegate.sharesLink objectForKey:[serverUrl stringByAppendingString:_metadataFolder.fileName]];
- shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:_metadataFolder.fileName]];
- }
-
- self.navigationItem.title = _titleMain;
-
- if (self.imageTitle) {
- [CCGraphics addImageToTitle:_titleMain colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:self.imageTitle multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
- } else {
- self.navigationItem.titleView = nil;
- }
- }
- }
- }
- - (UIImage *)getImageLogoHome
- {
- UIImage *imageThemingLogo = [UIImage imageNamed:@"themingLogo"];
- NSInteger multiplier = 2;
- NSString *fileNameThemingLogo = [NSString stringWithFormat:@"%@/%@-themingLogo.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl]];
- UIImage *image = [UIImage imageWithContentsOfFile:fileNameThemingLogo];
- if (image != nil) {
- imageThemingLogo = image;
- multiplier = 1;
- }
-
- if ([NCBrandOptions sharedInstance].use_themingLogo) {
-
- if ([appDelegate.reachability isReachable] == NO) {
-
- return [CCGraphics changeThemingColorImage:imageThemingLogo multiplier:multiplier color:[NCBrandColor sharedInstance].icon];
-
- } else {
-
- tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];
-
- if ([capabilities.themingColor isEqualToString:@"#FFFFFF"])
- return [CCGraphics changeThemingColorImage:imageThemingLogo multiplier:multiplier color:[UIColor blackColor]];
- else
- return [CCGraphics changeThemingColorImage:imageThemingLogo multiplier:multiplier color:[UIColor whiteColor]];
- }
-
- } else {
-
- if ([appDelegate.reachability isReachable] == NO)
- return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"themingLogo"] multiplier:multiplier color:[NCBrandColor sharedInstance].icon];
- else
- return [UIImage imageNamed:@"themingLogo"];
- }
- }
- - (void)setUINavigationBarDefault
- {
- [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
-
- UIBarButtonItem *buttonMore, *buttonNotification;
-
- // =
- buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
- buttonMore.enabled = true;
-
- // <
- self.navigationController.navigationBar.hidden = NO;
-
- // Notification
- if ([appDelegate.listOfNotifications count] > 0) {
-
- buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"notification"] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
- buttonNotification.tintColor = [NCBrandColor sharedInstance].brandText;
- buttonNotification.enabled = true;
- }
-
- if (buttonNotification)
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
- else
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
- self.navigationItem.leftBarButtonItem = nil;
- }
- - (void)setUINavigationBarSelected
- {
- [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
-
- UIImage *icon = [UIImage imageNamed:@"navigationControllerMenu"];
- UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
-
- self.navigationItem.leftBarButtonItem = leftButton;
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
- }
- - (void)cancelSelect
- {
- [self tableViewSelect:NO];
- [appDelegate.reSelectMenu close];
- }
- - (void)closeAllMenu
- {
- // close Menu
- [appDelegate.reSelectMenu close];
- [appDelegate.reMainMenu close];
-
- // Close Menu Logo
- [CCMenuAccount dismissMenu];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Document Picker =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
- {
- NSLog(@"[LOG] Cancelled");
- }
- - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
- {
- NSLog(@"[LOG] Cancelled");
- }
- - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
- {
- documentPicker.delegate = self;
- [self presentViewController:documentPicker animated:YES completion:nil];
- }
- - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
- {
- if (controller.documentPickerMode == UIDocumentPickerModeImport) {
-
- NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
- __block NSError *error;
-
- [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
-
- NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
- NSString *fileName = [[NCUtility sharedInstance] createFileName:[url lastPathComponent] directoryID:directoryID];
- NSString *fileID = [directoryID stringByAppendingString:fileName];
- NSData *data = [NSData dataWithContentsOfURL:newURL];
-
- if (data && error == nil) {
-
- if ([data writeToFile:[CCUtility getDirectoryProviderStorageFileID:fileID fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
-
- tableMetadata *metadataForUpload = [tableMetadata new];
-
- metadataForUpload.account = appDelegate.activeAccount;
- metadataForUpload.date = [NSDate new];
- metadataForUpload.directoryID = directoryID;
- metadataForUpload.fileID = fileID;
- metadataForUpload.fileName = fileName;
- metadataForUpload.fileNameView = fileName;
- metadataForUpload.session = k_upload_session;
- metadataForUpload.sessionSelector = selectorUploadFile;
- metadataForUpload.size = data.length;
- metadataForUpload.status = k_metadataStatusWaitUpload;
-
- // Check il file already exists
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileName]];
- if (metadata) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- // NO OVERWITE
- }];
- UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- // Remove record metadata
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID] clearDateReadDirectoryID:metadata.directoryID];
-
- // Add Medtadata for upload
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }];
-
- [alertController addAction:cancelAction];
- [alertController addAction:overwriteAction];
-
- UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
- alertWindow.rootViewController = [[UIViewController alloc]init];
- alertWindow.windowLevel = UIWindowLevelAlert + 1;
- [alertWindow makeKeyAndVisible];
- [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
-
- } else {
-
- // Add Medtadata for upload
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
-
- } else {
-
- [appDelegate messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- }
-
- } else {
-
- [appDelegate messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- }
- }];
- }
- }
- - (void)openImportDocumentPicker
- {
- UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
-
- documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
- documentProviderMenu.popoverPresentationController.sourceView = self.tabBarController.tabBar;
- documentProviderMenu.popoverPresentationController.sourceRect = self.tabBarController.tabBar.bounds;
- documentProviderMenu.delegate = self;
-
- [self presentViewController:documentProviderMenu animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Assets Picker =====
- #pragma --------------------------------------------------------------------------------------------
- -(void)dismissFormUploadAssets
- {
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- - (void)openAssetsPickerController
- {
- NCPhotosPickerViewController *viewController = [[NCPhotosPickerViewController alloc] init:self];
-
- [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nonnull assets) {
- if (assets.count > 0) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
- NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
-
- NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets cryptated:NO session:k_upload_session delegate:self];
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [self presentViewController:navigationController animated:YES completion:nil];
- });
- }
- }];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Save selected File =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)saveToPhotoAlbum:(tableMetadata *)metadata
- {
- NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
- PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
-
- UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
-
- if (image)
- UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
- else
- [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- }
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
-
- if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
-
- UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
- } else {
- [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- }
- }
-
- if (status != PHAuthorizationStatusAuthorized) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-
- [alertController addAction:okAction];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- }
- - (void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
- {
- if (error)
- [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- else
- [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
- }
- - (void)saveSelectedFiles
- {
- if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
- return;
- NSLog(@"[LOG] Start download selected files ...");
-
- [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
-
- NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-
- for (tableMetadata *metadata in metadatas) {
-
- if (metadata.directory == NO && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- if (serverUrl) {
-
- metadata.session = k_download_session;
- metadata.sessionError = @"";
- metadata.sessionSelector = selectorSave;
- metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
- }
- }
- }
-
- [_hud hideHud];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- });
-
- [self tableViewSelect:NO];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== View Notification ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)viewNotification
- {
- if ([appDelegate.listOfNotifications count] > 0) {
-
- CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
-
- [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [self presentViewController:notificationVC animated:YES completion:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Delegate Login ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)loginSuccess:(NSInteger)loginType
- {
- [_imageTitleHome setUserInteractionEnabled:NO];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-
- // go to home sweet home
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-
- [_imageTitleHome setUserInteractionEnabled:YES];
- });
-
- [appDelegate subscribingNextcloudServerPushNotification];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Peek & Pop =====
- #pragma --------------------------------------------------------------------------------------------
- - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
- {
- CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (metadata.hasPreview == 1) {
- CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
-
- if (cell) {
- previewingContext.sourceRect = cell.frame;
- CCPeekPop *vc = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
-
- vc.delegate = self;
- vc.metadata = metadata;
-
- return vc;
- }
- }
-
- return nil;
- }
- - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
- {
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
-
- [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadSelectedFilesFolders
- {
- if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
- return;
- NSLog(@"[LOG] Start download selected ...");
-
- [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (serverUrl == nil) continue;
-
- if (metadata.directory) {
-
- [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName] selector:selectorReadFolderWithDownload];
-
- } else {
-
- [[CCSynchronize sharedSynchronize] readFile:metadata.fileID fileName:metadata.fileName serverUrl:serverUrl selector:selectorReadFileWithDownload];
- }
- }
-
- [_hud hideHud];
- });
-
- [self tableViewSelect:NO];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Upload new Photos/Videos =====
- #pragma --------------------------------------------------------------------------------------------
- //
- // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
- //
- - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
- // if request create the folder for Auto Upload & the subfolders
- if ([autoUploadPath isEqualToString:serverUrl])
- if (![[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
- return;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self uploadFileAsset:assets serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
- });
- });
- }
- - (void)uploadFileAsset:(NSArray *)assets serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
- {
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
- if (!directoryID) return;
-
- for (PHAsset *asset in assets) {
-
- tableMetadata *metadata;
- NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType keyFileNameOriginal:k_keyFileNameOriginal];
-
- NSDate *assetDate = asset.creationDate;
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-
- // Create serverUrl if use sub folder
- if (useSubFolder) {
-
- [formatter setDateFormat:@"yyyy"];
- NSString *yearString = [formatter stringFromDate:assetDate];
-
- [formatter setDateFormat:@"MM"];
- NSString *monthString = [formatter stringFromDate:assetDate];
-
- serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
- }
-
- // Check if is in upload
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID == %@ AND fileName == %@ AND session != ''", directoryID, fileName];
- NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
- if ([isRecordInSessions count] > 0)
- continue;
-
- // Prepare record metadata
- tableMetadata *metadataForUpload = [tableMetadata new];
- metadataForUpload.account = appDelegate.activeAccount;
- metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
- metadataForUpload.date = [NSDate new];
- metadataForUpload.directoryID = directoryID;
- metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
- metadataForUpload.fileName = fileName;
- metadataForUpload.fileNameView = fileName;
- metadataForUpload.session = session;
- metadataForUpload.sessionSelector = selectorUploadFile;
- metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
- metadataForUpload.status = k_metadataStatusWaitUpload;
-
- NSString *fileNameExtension = [fileName pathExtension];
- NSString *fileNameWithoutExtension = [fileName stringByDeletingPathExtension];
-
- if ([[fileNameExtension lowercaseString] isEqualToString:@"heic"] && [CCUtility getFormatCompatibility]) {
- NSString *fileNameCompatibility = [fileNameWithoutExtension stringByAppendingString:@".jpg"];
- metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileNameCompatibility]];
- } else {
- metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileName]];
- }
-
- // Check il file already exists
- if (metadata) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileNameWithoutExtension message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- // NO OVERWITE
- }];
- UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- // Remove record metadata
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID] clearDateReadDirectoryID:metadata.directoryID];
- // Add Medtadata for upload
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
- }];
-
- [alertController addAction:cancelAction];
- [alertController addAction:overwriteAction];
-
- UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
- alertWindow.rootViewController = [[UIViewController alloc]init];
- alertWindow.windowLevel = UIWindowLevelAlert + 1;
- [alertWindow makeKeyAndVisible];
- [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
-
- } else {
-
- // Add Medtadata for upload
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
- }
- }
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Read File ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readFileSuccessFailure:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- if (errorCode == 0) {
-
- // Read Folder
- if ([metadataNet.selector isEqualToString:selectorReadFileReloadFolder]) {
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", metadataNet.account, metadataNet.serverUrl]];
-
- // Change etag, read folder
- if ([metadata.etag isEqualToString:directory.etag] == NO) {
- [self readFolder:metadataNet.serverUrl];
- }
- }
-
- } else {
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- }
- }
- - (void)readFileReloadFolder
- {
- if (!_serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode)
- return;
-
- // Load Datasource
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- });
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
- metadataNet.action = actionReadFile;
- metadataNet.priority = NSOperationQueuePriorityHigh;
- metadataNet.selector = selectorReadFileReloadFolder;
- metadataNet.serverUrl = _serverUrl;
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Read Folder ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readFolderSuccessFailure:(CCMetadataNet *)metadataNet metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // stoprefresh
- [refreshControl endRefreshing];
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:metadataNet.account])
- return;
-
- // ERROR
- if (errorCode != 0) {
-
- _loadingFolder = NO;
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized) {
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
-
- } else {
- [self tableViewReloadData];
-
- [_imageTitleHome setUserInteractionEnabled:YES];
-
- [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
- }
-
- return;
- }
-
- // save metadataFolder
- _metadataFolder = metadataFolder;
-
- if (_isSearchMode == NO) {
-
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:metadataNet.serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted];
-
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND (status == %d OR status == %d)", metadataNet.directoryID, k_metadataStatusNormal, k_metadataStatusHide] clearDateReadDirectoryID:metadataNet.directoryID];
-
- [[NCManageDatabase sharedInstance] setDateReadDirectoryWithDirectoryID:metadataNet.directoryID];
- }
-
- NSArray *metadatasInDownload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", metadataNet.directoryID, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError] sorted:nil ascending:NO];
-
- // insert in Database
- NSMutableArray *metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas serverUrl:metadataNet.serverUrl];
- // reinsert metadatas in Download
- if (metadatasInDownload) {
- (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload serverUrl:metadataNet.serverUrl];
- }
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- // File is changed ??
- if (!_isSearchMode && metadatasToInsertInDB)
- [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:metadataNet.serverUrl account:appDelegate.activeAccount withDownload:NO];
- });
-
- // Search Mode
- if (_isSearchMode) {
-
- // Fix managed -> Unmanaged _searchResultMetadatas
- if (metadatasToInsertInDB)
- _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
- }
-
- // this is the same directory
- if ([metadataNet.serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
-
- // reload
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
-
- // Enable change user
- [_imageTitleHome setUserInteractionEnabled:YES];
-
- _loadingFolder = NO;
- [self tableViewReloadData];
- }
-
- // E2EE Is encrypted folder get metadata
- if (_metadataFolder.e2eEncrypted) {
-
- // Read Metadata
- if ([CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
- NSString *metadata;
- NSError *error = [[NCNetworkingEndToEnd sharedManager] getEndToEndMetadata:&metadata fileID:metadataFolder.fileID user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (error) {
- if (error.code != 404)
- [appDelegate messageNotification:@"_e2e_error_get_metadata_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- } else {
- if ([[NCEndToEndMetadata sharedInstance] decoderMetadata:metadata privateKey:[CCUtility getEndToEndPrivateKey:appDelegate.activeAccount] serverUrl:self.serverUrl account:appDelegate.activeAccount url:appDelegate.activeUrl] == false)
- [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- else
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- });
- });
- } else {
- [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
- }
- }
-
- // rewrite title
- [self setTitle];
- }
- - (void)readFolder:(NSString *)serverUrl
- {
- // init control
- if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
-
- [refreshControl endRefreshing];
- return;
- }
-
- // Search Mode
- if (_isSearchMode) {
-
- [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
-
- _searchFileName = @""; // forced reload searchg
-
- [self updateSearchResultsForSearchController:self.searchController];
-
- return;
- }
-
- _loadingFolder = YES;
- [self tableViewReloadData];
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
- metadataNet.action = actionReadFolder;
- metadataNet.date = [NSDate date];
- metadataNet.depth = @"1";
- metadataNet.directoryID = directory.directoryID;
- metadataNet.priority = NSOperationQueuePriorityHigh;
- metadataNet.selector = selectorReadFolder;
- metadataNet.serverUrl = serverUrl;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Search =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)searchEnabled:(BOOL)enabled
- {
- if (enabled) {
-
- if (self.tableView.tableHeaderView != nil)
- return;
-
- self.definesPresentationContext = YES;
- self.searchController.searchResultsUpdater = self;
- self.searchController.dimsBackgroundDuringPresentation = NO;
- self.searchController.searchBar.translucent = NO;
- [self.searchController.searchBar sizeToFit];
- self.searchController.searchBar.delegate = self;
- self.searchController.searchBar.barTintColor = [NCBrandColor sharedInstance].brand;
- self.searchController.searchBar.backgroundColor = [NCBrandColor sharedInstance].brand;
- self.searchController.searchBar.backgroundImage = [UIImage new];
- // color searchbbar button text (cancel)
- UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
- if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
- [searchButton setTitleColor:[NCBrandColor sharedInstance].brandText forState:UIControlStateNormal];
- }
-
- self.tableView.tableHeaderView = self.searchController.searchBar;
- [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
-
- } else {
-
- self.tableView.tableHeaderView = nil;
- }
- }
- - (void)searchStartTimer
- {
- NSString *startDirectory = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionSearch;
- metadataNet.contentType = nil;
- metadataNet.date = nil;
- metadataNet.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:startDirectory];
- metadataNet.fileName = _searchFileName;
- metadataNet.etag = @"";
- metadataNet.depth = @"infinity";
- metadataNet.priority = NSOperationQueuePriorityHigh;
- metadataNet.selector = selectorSearchFiles;
- metadataNet.serverUrl = startDirectory;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
-
- [self.tableView reloadEmptyDataSet];
- }
- - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
- {
- // Color text "Cancel"
- [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:[NCBrandColor sharedInstance].brandText];
- _isSearchMode = YES;
- [self deleteRefreshControl];
-
- NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
-
- if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
-
- _searchFileName = fileName;
-
- // First : filter
-
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
- if (!directoryID) return;
-
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView CONTAINS[cd] %@", directoryID, fileName];
- NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
-
- [_searchResultMetadatas removeAllObjects];
- for (tableMetadata *record in records)
- [_searchResultMetadatas addObject:record];
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.account = appDelegate.activeAccount;
- metadataNet.directoryID = directoryID;
- metadataNet.selector = selectorSearchFiles;
- metadataNet.serverUrl = _serverUrl;
- [self readFolderSuccessFailure:metadataNet metadataFolder:nil metadatas:_searchResultMetadatas message:nil errorCode:0];
-
- // Version >= 12
- if ([[NCManageDatabase sharedInstance] getServerVersion] >= 12) {
-
- [_timerWaitInput invalidate];
- _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
- }
- }
-
- if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- }
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
- {
- [self cancelSearchBar];
-
- [self readFolder:_serverUrl];
- }
- - (void)searchSuccessFailure:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- if (errorCode == 0) {
-
- _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
- [self readFolderSuccessFailure:metadataNet metadataFolder:nil metadatas:metadatas message:nil errorCode:0];
-
- } else {
-
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- else
- [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- _searchFileName = @"";
- }
- }
- - (void)cancelSearchBar
- {
- if (self.searchController.active) {
-
- [self.searchController setActive:NO];
- [self createRefreshControl];
-
- _isSearchMode = NO;
- _searchFileName = @"";
- _dateReadDataSource = nil;
- _searchResultMetadatas = [NSMutableArray new];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
-
- //[self setNeedsStatusBarAppearanceUpdate];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Delete File or Folder =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)deleteFile
- {
- if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
- return;
-
- NSArray *metadatas;
- if ([_selectedFileIDsMetadatas count] > 0) {
- metadatas = [_selectedFileIDsMetadatas allValues];
- } else {
- metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
- }
-
- // remove optimization
- _dateReadDataSource = nil;
-
- [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:_metadataFolder.e2eEncrypted serverUrl:self.serverUrl folderFileID:_metadataFolder.fileID completion:^(NSInteger errorCode, NSString *message) {
-
- // Reload
- if (_isSearchMode)
- [self readFolder:self.serverUrl];
- else
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }];
-
- // End Select Table View
- [self tableViewSelect:NO];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Rename / Move =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)renameSuccess:(CCMetadataNet *)metadataNet
- {
- // Rename metadata
- (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:metadataNet.fileNameTo fileID:metadataNet.fileID];
-
- if (metadataNet.directory) {
-
- NSString *serverUrl = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadataNet.fileName];
- NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadataNet.fileNameTo];
- tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
- if (directoryTable == nil) {
- [self renameMoveFileOrFolderFailure:metadataNet message:@"Internal error, ServerUrl not found" errorCode:0];
- return;
- }
-
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:nil fileID:nil encrypted:directoryTable.e2eEncrypted];
- } else {
-
- [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadataNet.fileID date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:metadataNet.fileNameTo etag:nil];
-
- // Move file system
- NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadataNet.fileID], metadataNet.fileName];
- NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadataNet.fileID], metadataNet.fileNameTo];
-
- [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
-
- NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadataNet.fileID fileNameView:metadataNet.fileName];
- NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadataNet.fileID fileNameView:metadataNet.fileNameTo];
-
- [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
- }
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:metadataNet.fileID action:k_action_MOD];
- }
- - (void)renameFile:(NSArray *)arguments
- {
- tableMetadata* metadata = [arguments objectAtIndex:0];
- NSString *fileName = [arguments objectAtIndex:1];
-
- // E2EE
- if (_metadataFolder.e2eEncrypted) {
-
- // verify if exists the new fileName
- if ([[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, self.serverUrl, fileName]]) {
- [appDelegate messageNotification:@"_error_e2ee_" description:@"_file_already_exists_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- return;
- }
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-
- 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];
- if (error) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_send_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- });
- } else {
- [[NCManageDatabase sharedInstance] setMetadataFileNameViewWithDirectoryID:metadata.directoryID fileName:metadata.fileName newFileNameView:fileName];
-
- // Move file system
- NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], metadata.fileNameView];
- NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], fileName];
- [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
- [[NSFileManager defaultManager] moveItemAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:fileName] error:nil];
- }
-
- // Unlock
- tableE2eEncryptionLock *tableLock = [[NCManageDatabase sharedInstance] getE2ETokenLockWithServerUrl:self.serverUrl];
- if (tableLock != nil) {
- 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];
- if (error) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [appDelegate messageNotification:@"_e2e_error_unlock_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- });
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- });
- });
-
- } else {
-
- // Plain
-
- NSString *fileNameNew = [CCUtility removeForbiddenCharactersServer:fileName];
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- if ([fileName length] == 0 || [fileName isEqualToString:metadata.fileNameView]) {
- return;
- }
-
- // Verify if exists the fileName TO
- OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
-
- [ocNetworking readFile:fileNameNew serverUrl:serverUrl account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
-
- UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- }];
- [alert addAction:ok];
- [self presentViewController:alert animated:YES completion:nil];
-
- } failure:^(NSString *message, NSInteger errorCode) {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.directory = metadata.directory;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNameTo = fileNameNew;
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.selector = selectorRename;
- metadataNet.serverUrl = serverUrl;
- metadataNet.serverUrlTo = serverUrl;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
- }];
- }
- }
- - (void)renameMoveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- if ([message length] > 0) {
-
- if ([metadataNet.selector isEqualToString:selectorRename]) {
- [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
-
- if ([metadataNet.selector isEqualToString:selectorMove]) {
- [appDelegate messageNotification:@"_move_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- }
-
- if ([metadataNet.selector isEqualToString:selectorMove]) {
-
- [_hud hideHud];
-
- if (message && errorCode != kOCErrorServerUnauthorized)
- [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- // End Select Table View
- [self tableViewSelect:NO];
-
- // reload Datasource
- if (_isSearchMode)
- [self readFolder:metadataNet.serverUrl];
- else
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- }
- - (void)moveSuccess:(CCMetadataNet *)metadataNet
- {
- [_queueSelector removeObject:metadataNet.selector];
-
- if ([_queueSelector count] == 0) {
-
- [_hud hideHud];
-
- NSString *fileName = metadataNet.fileName;
- NSString *directoryID = metadataNet.directoryID;
- NSString *directoryIDTo = metadataNet.directoryIDTo;
- NSString *serverUrlTo = [[NCManageDatabase sharedInstance] getServerUrl:directoryIDTo];
- if (!serverUrlTo) return;
-
- // FILE -> Metadata
- if (metadataNet.directory == NO)
- [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
-
- // DIRECTORY -> Directory - CCMetadata
- if (metadataNet.directory == YES) {
-
- // delete all dir / subdir
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:fileName]];
-
- // move metadata
- [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
-
- // Add new directory
- NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
- (void) [[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:false favorite:false fileID:nil permissions:nil serverUrl:newDirectory];
- }
-
- // next
- [_selectedFileIDsMetadatas removeObjectForKey:metadataNet.fileID];
-
- if ([_selectedFileIDsMetadatas count] > 0) {
-
- NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
-
- [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrlTo, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
-
- } else {
-
- // End Select Table View
- [self tableViewSelect:NO];
-
- // reload Datasource
- if (_isSearchMode)
- [self readFolder:metadataNet.serverUrl];
- else
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- }
- }
- - (void)moveFileOrFolderMetadata:(NSArray *)arguments
- {
- tableMetadata *metadata = [arguments objectAtIndex:0];
- NSString *serverUrlTo = [arguments objectAtIndex:1];
- NSInteger numFile = [[arguments objectAtIndex:2] integerValue];
- NSInteger ofFile = [[arguments objectAtIndex:3] integerValue];
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (!serverUrl) return;
-
- NSString *directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
- if (!directoryIDTo) return;
-
- OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
- [ocNetworking readFile:metadata.fileName serverUrl:serverUrlTo account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
-
- UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- }];
- [alert addAction:ok];
- [self presentViewController:alert animated:YES completion:nil];
-
- // End Select Table View
- [self tableViewSelect:NO];
-
- // reload Datasource
- [self readFileReloadFolder];
-
- } failure:^(NSString *message, NSInteger errorCode) {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.directory = metadata.directory;
- metadataNet.fileID = metadata.fileID;
- metadataNet.directoryID = metadata.directoryID;
- metadataNet.directoryIDTo = directoryIDTo;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.fileNameTo = metadata.fileName;
- metadataNet.etag = metadata.etag;
- metadataNet.selector = selectorMove;
- metadataNet.serverUrl = serverUrl;
- metadataNet.serverUrlTo = serverUrlTo;
-
- [_queueSelector addObject:metadataNet.selector];
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
- }];
- }
- // DELEGATE : Select
- - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
- {
- if (serverUrl == nil) {
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- } else {
- [_queueSelector removeAllObjects];
-
- // E2EE DENIED
- if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) {
-
- [appDelegate messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
- return;
- }
-
- if ([_selectedFileIDsMetadatas count] > 0) {
-
- _numSelectedFileIDsMetadatas = [_selectedFileIDsMetadatas count];
- NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
-
- [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrl, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
-
- } else {
-
- _numSelectedFileIDsMetadatas = 1;
- [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[self.metadata, serverUrl, [NSNumber numberWithInteger:1], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
- }
- }
- }
- - (void)moveOpenWindow:(NSArray *)indexPaths
- {
- if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
- return;
-
- UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
- NCSelect *viewController = (NCSelect *)navigationController.topViewController;
-
- viewController.delegate = self;
- viewController.hideButtonCreateFolder = false;
- viewController.selectFile = false;
- viewController.includeDirectoryE2EEncryption = false;
- viewController.includeImages = false;
- viewController.type = @"";
- viewController.titleButtonDone = NSLocalizedString(@"_move_", nil);
- viewController.layoutViewSelect = k_layout_view_move;
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Create folder =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createFolder
- {
- NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
- NSString *message;
- UIAlertController *alertController;
-
- if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
- message = @"/";
- } else {
- message = [serverUrl lastPathComponent];
- }
-
- alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
-
- textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"[LOG] Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
- [self createFolder:fileName.text serverUrl:serverUrl];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (void)createFolder:(NSString *)fileNameFolder serverUrl:(NSString *)serverUrl
- {
- fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
- if (![fileNameFolder length]) return;
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
- if (!directoryID) return;
- NSString *fileIDTemp = [[NSUUID UUID] UUIDString];
-
- // Create Directory (temp) on metadata
- tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:YES fileID:fileIDTemp directoryID:directoryID fileName:fileNameFolder etag:@"" size:0 status:k_metadataStatusNormal url:@""];
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
-
- [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
-
- // Creeate folder Networking
- OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
-
- [ocNetworking createFolder:fileNameFolder serverUrl:serverUrl account:appDelegate.activeAccount success:^(NSString *fileID, NSDate *date) {
- // Delete Temp Dir
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp] clearDateReadDirectoryID:nil];
- NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrl, fileNameFolder];
-
- if (_metadataFolder.e2eEncrypted) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:newDirectory fileID:fileID user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (error) {
- [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- }
- [self readFolder:self.serverUrl];
- });
- });
-
- } else {
-
- [self readFolder:self.serverUrl];
- }
-
- } failure:^(NSString *message, NSInteger errorCode) {
-
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- else
- [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- // Delete Temp Dir
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp] clearDateReadDirectoryID:nil];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
-
- // We are in directory fail ?
- CCMain *vc = [appDelegate.listMainVC objectForKey:[CCUtility stringAppendServerUrl:_serverUrl addFileName:fileNameFolder]];
- if (vc)
- [vc.navigationController popViewControllerAnimated:YES];
- }];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Progress & Task Button =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)triggerProgressTask:(NSNotification *)notification
- {
- [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
- }
- - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- UITouch *touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- if ([self indexPathIsValid:indexPath]) {
-
- tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (metadataSection) {
-
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadataSection.fileID]];
- if (metadata)
- [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
- }
- }
- }
- - (void)cancelAllTask:(id)sender
- {
- CGPoint location = [sender locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- [[NCMainCommon sharedInstance] cancelAllTransfer];
- }]];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
-
- alertController.popoverPresentationController.sourceView = self.tableView;
- alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [alertController.view layoutIfNeeded];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Shared =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
- {
- [_hud hideHud];
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- NSArray *result = [[NCManageDatabase sharedInstance] updateShare:items activeUrl:appDelegate.activeUrl];
- if (result) {
- appDelegate.sharesLink = result[0];
- appDelegate.sharesUserAndGroup = result[1];
- }
-
- // Notify Shares View
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
-
- if (openWindow) {
-
- if (_shareOC) {
-
- [_shareOC reloadData];
-
- } else {
-
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadataNet.fileID]];
-
- // Apriamo la view
- _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
-
- _shareOC.delegate = self;
- _shareOC.metadata = metadata;
- _shareOC.serverUrl = metadataNet.serverUrl;
-
- _shareOC.shareLink = [appDelegate.sharesLink objectForKey:metadata.fileID];
- _shareOC.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:metadata.fileID];
-
- [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:_shareOC animated:YES completion:nil];
- }
- }
- [self tableViewReloadData];
- }
- - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [_hud hideHud];
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- else
- [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- if (_shareOC)
- [_shareOC reloadData];
-
- [self tableViewReloadData];
- }
- - (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.sharePermission = permission;
- metadataNet.password = password;
- metadataNet.selector = selectorShare;
- metadataNet.serverUrl = serverUrl;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
- [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)unShareSuccess:(CCMetadataNet *)metadataNet
- {
- [_hud hideHud];
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- // rimuoviamo la condivisione da db
- NSArray *result = [[NCManageDatabase sharedInstance] unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:appDelegate.sharesLink sharesUserAndGroup:appDelegate.sharesUserAndGroup];
-
- if (result) {
- appDelegate.sharesLink = result[0];
- appDelegate.sharesUserAndGroup = result[1];
- }
-
- if (_shareOC)
- [_shareOC reloadData];
-
- [self tableViewReloadData];
- }
- - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionUnShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.selector = selectorUnshare;
- metadataNet.serverUrl = serverUrl;
- metadataNet.share = share;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionUpdateShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.expirationTime = expirationTime;
- metadataNet.password = password;
- metadataNet.selector = selectorUpdateShare;
- metadataNet.serverUrl = serverUrl;
- metadataNet.share = share;
- metadataNet.sharePermission = permission;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
- [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
- {
- [_hud hideHud];
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- if (_shareOC)
- [_shareOC reloadUserAndGroup:items];
- }
- - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [_hud hideHud];
-
- // Check Active Account
- if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
- return;
-
- // Unauthorized
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- else
- [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- - (void)getUserAndGroup:(NSString *)find
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionGetUserAndGroup;
- metadataNet.optionAny = find;
- metadataNet.selector = selectorGetUserAndGroup;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleIndeterminateHud];
- }
- - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(tableMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
- metadataNet.action = actionShareWith;
- metadataNet.fileID = metadata.fileID;
- metadataNet.directoryID = directoryID;
- metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.serverUrl = serverUrl;
- metadataNet.selector = selectorShare;
- metadataNet.share = user;
- metadataNet.shareeType = shareeType;
- metadataNet.sharePermission = permission;
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)openWindowShare:(tableMetadata *)metadata
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (!serverUrl) return;
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
-
- metadataNet.action = actionReadShareServer;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNameView = metadata.fileNameView;
- metadataNet.selector = selectorOpenWindowShare;
- metadataNet.serverUrl = serverUrl;
-
- [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleIndeterminateHud];
- }
- - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
- {
- CGPoint location = [tapGesture locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (metadata)
- [self openWindowShare:metadata];
- }
- - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
- {
- CGPoint location = [tapGesture locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (metadata) {
-
- CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
-
- vc.metadata = metadata;
-
- [vc setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:vc animated:YES completion:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Favorite =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
- {
- NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
-
- OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
- [ocNetworking settingFavorite:fileNameServerUrl favorite:favorite completion:^(NSString *message, NSInteger errorCode) {
- if (errorCode == 0) {
-
- [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadata.fileID favorite:favorite];
- _dateReadDataSource = nil;
- if (_isSearchMode)
- [self readFolder:self.serverUrl];
- else
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
-
- if (metadata.directory && favorite) {
- NSString *dir = [CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName];
- [appDelegate.activeFavorites addFavoriteFolder:dir];
- }
-
- if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
-
- metadata.favorite = favorite;
- metadata.session = k_download_session;
- metadata.sessionError = @"";
- metadata.sessionSelector = selectorDownloadSynchronize;
- metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
- }
-
- } else {
- if (errorCode == kOCErrorServerUnauthorized)
- [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
- }
- }];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Open in... =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)DownloadOpenIn:(tableMetadata *)metadata
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (!serverUrl) return;
- metadata.session = k_download_session;
- metadata.sessionError = @"";
- metadata.sessionSelector = selectorOpenIn;
- metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
- }
- - (void)openIn:(tableMetadata *)metadata
- {
- NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
-
- docController = [UIDocumentInteractionController interactionControllerWithURL:url];
- docController.delegate = self;
-
- NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
- CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
-
- if (cell) {
- [docController presentOptionsMenuFromRect:cell.frame inView:self.tableView animated:YES];
- } else {
- [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Menu LOGO ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
- {
- if (appDelegate.reSelectMenu.isOpen || appDelegate.reMainMenu.isOpen)
- return;
-
- // Brand
- if ([NCBrandOptions sharedInstance].disable_multiaccount)
- return;
-
- NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
-
- NSMutableArray *menuArray = [NSMutableArray new];
-
- for (NSString *account in listAccount) {
-
- CCMenuItem *item = [[CCMenuItem alloc] init];
-
- item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
- item.argument = account;
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
- NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-avatar.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url]];
-
- UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
- if (avatar) {
-
- avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
-
- CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
-
- CGSize imageSize = avatarImageView.bounds.size;
- UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
- CGContextRef context = UIGraphicsGetCurrentContext();
- [avatarImageView.layer renderInContext:context];
- avatar = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- } else {
-
- avatar = [UIImage imageNamed:@"menuLogoUser"];
- }
-
- item.image = avatar;
- item.target = self;
-
- if ([account isEqualToString:appDelegate.activeAccount]) {
-
- item.action = nil;
- [menuArray insertObject:item atIndex:0];
-
- } else {
-
- item.action = @selector(changeDefaultAccount:);
- [menuArray addObject:item];
- }
- }
-
- // Add + new account
- CCMenuItem *item = [[CCMenuItem alloc] init];
-
- item.title = NSLocalizedString(@"_add_account_", nil);
- item.argument = @"";
- item.image = [UIImage imageNamed:@"add"];
- item.target = self;
- item.action = @selector(addNewAccount:);
-
- [menuArray addObject:item];
-
- OptionalConfiguration options;
- Color textColor, backgroundColor;
-
- textColor.R = 0;
- textColor.G = 0;
- textColor.B = 0;
-
- backgroundColor.R = 1;
- backgroundColor.G = 1;
- backgroundColor.B = 1;
-
- options.arrowSize = 9;
- options.marginXSpacing = 7;
- options.marginYSpacing = 10;
- options.intervalSpacing = 20;
- options.menuCornerRadius = 6.5;
- options.maskToBackground = NO;
- options.shadowOfMenu = YES;
- options.hasSeperatorLine = YES;
- options.seperatorLineHasInsets = YES;
- options.textColor = textColor;
- options.menuBackgroundColor = backgroundColor;
-
- CGRect rect = self.view.frame;
- CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
- CGFloat safeAreaTop = 0;
- CGFloat offsetY = 35;
- if (@available(iOS 11, *)) {
- safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
- }
- rect.origin.y = locationY + safeAreaTop + offsetY;
- rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
-
- [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
- [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
- }
- - (void)changeDefaultAccount:(CCMenuItem *)sender
- {
- NSInteger transferInprogress = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", appDelegate.activeAccount, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:@"fileName" ascending:true] count];
-
- if (transferInprogress > 0) {
- [JDStatusBarNotification showWithStatus:NSLocalizedString(@"_transfers_in_queue_", nil) dismissAfter:k_dismissAfterSecond styleName:JDStatusBarStyleDefault];
- return;
- }
-
- [appDelegate.netQueue cancelAllOperations];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- // LOGOUT
-
- [appDelegate unsubscribingNextcloudServerPushNotification];
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
- if (tableAccount) {
-
- // LOGIN
-
- [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
-
- // go to home sweet home
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-
- [appDelegate subscribingNextcloudServerPushNotification];
- }
- });
- }
- - (void)addNewAccount:(CCMenuItem *)sender
- {
- NSInteger transferInprogress = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", appDelegate.activeAccount, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusInUpload, k_metadataStatusUploading] sorted:@"fileName" ascending:true] count];
-
- if (transferInprogress > 0) {
- [JDStatusBarNotification showWithStatus:NSLocalizedString(@"_transfers_in_queue_", nil) dismissAfter:k_dismissAfterSecond styleName:JDStatusBarStyleDefault];
- return;
- }
-
- [appDelegate.netQueue cancelAllOperations];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_login];
- });
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== ReMenu ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createReMenuBackgroundView:(REMenu *)menu
- {
- CGFloat safeAreaBottom = 0;
- CGFloat safeAreaTop = 0;
- CGFloat statusBar = 0;
-
- if (@available(iOS 11, *)) {
- safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
- safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
- }
- if ([UIApplication sharedApplication].isStatusBarHidden) {
- statusBar = 13;
- }
-
- CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
- UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
- CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
- _reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
- [UIView animateWithDuration:0.2 animations:^{
- CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
- CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
-
- if (y>minimum) {
-
- _reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
- [self.tabBarController.view addSubview:_reMenuBackgroundView];
- }
- }];
- }
- - (void)createReMainMenu
- {
- NSString *title;
- NSString *groupBy = [CCUtility getGroupBySettings];
- NSString *sorted = [CCUtility getOrderSettings];
- BOOL ascending = [CCUtility getAscendingSettings];
-
- // ITEM SELECT ----------------------------------------------------------------------------------------------------
-
- appDelegate.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"select"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
- }];
-
- // ITEM ORDER ----------------------------------------------------------------------------------------------------
- if ([sorted isEqualToString:@"fileName"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_a_z_", nil)]; }
- else title = NSLocalizedString(@"_order_by_name_a_z_", nil);
-
- appDelegate.sortFileNameAZItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameAZ"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"fileName"];
- [CCUtility setAscendingSettings:true];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
- if ([sorted isEqualToString:@"fileName"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_z_a_", nil)]; }
- else title = NSLocalizedString(@"_order_by_name_z_a_", nil);
-
- appDelegate.sortFileNameZAItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameZA"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"fileName"];
- [CCUtility setAscendingSettings:false];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- if ([sorted isEqualToString:@"date"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_more_recent_", nil)]; }
- else title = NSLocalizedString(@"_order_by_date_more_recent_", nil);
-
- appDelegate.sortDateMoreRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateMoreRecent"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"date"];
- [CCUtility setAscendingSettings:false];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- if ([sorted isEqualToString:@"date"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_less_recent_", nil)]; }
- else title = NSLocalizedString(@"_order_by_date_less_recent_", nil);
-
- appDelegate.sortDateLessRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateLessRecent"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"date"];
- [CCUtility setAscendingSettings:true];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- if ([sorted isEqualToString:@"size"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_smallest_", nil)]; }
- else title = NSLocalizedString(@"_order_by_size_smallest_", nil);
-
- appDelegate.sortSmallestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortSmallest"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"size"];
- [CCUtility setAscendingSettings:true];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- if ([sorted isEqualToString:@"size"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_largest_", nil)]; }
- else title = NSLocalizedString(@"_order_by_size_largest_", nil);
-
- appDelegate.sortLargestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortLargest"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [CCUtility setOrderSettings:@"size"];
- [CCUtility setAscendingSettings:false];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- // ITEM GROUP ALPHABETIC -----------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"alphabetic"]) { title = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
- else { title = NSLocalizedString(@"_group_alphabetic_no_", nil); }
-
- appDelegate.alphabeticItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"alphabetic"]) [CCUtility setGroupBySettings:@"none"];
- else [CCUtility setGroupBySettings:@"alphabetic"];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- // ITEM GROUP TYPEFILE -------------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"typefile"]) { title = NSLocalizedString(@"_group_typefile_yes_", nil); }
- else { title = NSLocalizedString(@"_group_typefile_no_", nil); }
-
- appDelegate.typefileItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByFile"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"typefile"]) [CCUtility setGroupBySettings:@"none"];
- else [CCUtility setGroupBySettings:@"typefile"];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- // ITEM GROUP DATE -------------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"date"]) { title = NSLocalizedString(@"_group_date_yes_", nil); }
- else { title = NSLocalizedString(@"_group_date_no_", nil); }
-
- appDelegate.dateItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"date"]) [CCUtility setGroupBySettings:@"none"];
- else [CCUtility setGroupBySettings:@"date"];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
-
- if ([CCUtility getDirectoryOnTop]) { title = NSLocalizedString(@"_directory_on_top_yes_", nil); }
- else { title = NSLocalizedString(@"_directory_on_top_no_", nil); }
-
- appDelegate.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"foldersOnTop"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- if ([CCUtility getDirectoryOnTop]) [CCUtility setDirectoryOnTop:NO];
- else [CCUtility setDirectoryOnTop:YES];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }];
-
- // REMENU --------------------------------------------------------------------------------------------------------------
- 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]];
-
- appDelegate.reMainMenu.itemHeight = 40;
-
- appDelegate.reMainMenu.imageOffset = CGSizeMake(5, -1);
-
- appDelegate.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
- appDelegate.reMainMenu.imageOffset = CGSizeMake(0, 0);
- appDelegate.reMainMenu.waitUntilAnimationIsComplete = NO;
-
- appDelegate.reMainMenu.separatorHeight = 0.5;
- appDelegate.reMainMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
-
- appDelegate.reMainMenu.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
- appDelegate.reMainMenu.textColor = [UIColor blackColor];
- appDelegate.reMainMenu.textAlignment = NSTextAlignmentLeft;
- appDelegate.reMainMenu.textShadowColor = nil;
- appDelegate.reMainMenu.textOffset = CGSizeMake(50, 0.0);
- appDelegate.reMainMenu.font = [UIFont systemFontOfSize:14.0];
-
- appDelegate.reMainMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- appDelegate.reMainMenu.highlightedSeparatorColor = nil;
- appDelegate.reMainMenu.highlightedTextColor = [UIColor blackColor];
- appDelegate.reMainMenu.highlightedTextShadowColor = nil;
- appDelegate.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
-
- appDelegate.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
- appDelegate.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
- appDelegate.reMainMenu.subtitleTextShadowColor = nil;
- appDelegate.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
- appDelegate.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
- appDelegate.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
-
- appDelegate.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
- appDelegate.reMainMenu.subtitleHighlightedTextShadowColor = nil;
- appDelegate.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
-
- appDelegate.reMainMenu.borderWidth = 0.3;
- appDelegate.reMainMenu.borderColor = [UIColor lightGrayColor];
-
- appDelegate.reMainMenu.animationDuration = 0.2;
- appDelegate.reMainMenu.closeAnimationDuration = 0.2;
-
- appDelegate.reMainMenu.bounce = NO;
-
- __weak typeof(self) weakSelf = self;
- [appDelegate.reMainMenu setClosePreparationBlock:^{
-
- // Backgroun reMenu (Gesture)
- [weakSelf.reMenuBackgroundView removeFromSuperview];
- [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
- }];
- }
- - (void)toggleReMainMenu
- {
- if (appDelegate.reMainMenu.isOpen) {
-
- [appDelegate.reMainMenu close];
-
- } else {
-
- [self createReMainMenu];
- [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
-
- // Backgroun reMenu & (Gesture)
- [self createReMenuBackgroundView:appDelegate.reMainMenu];
-
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
- [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
- }
- }
- - (void)createReSelectMenu
- {
- // ITEM SELECT ALL --------------------------------------------------------------------------------------------------
-
- appDelegate.selectAllItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_all_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectAll"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [self didSelectAll];
- }];
-
- // ITEM MOVE --------------------------------------------------------------------------------------------------------
-
- 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) {
- [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
- }];
-
- // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
-
- 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) {
- [self downloadSelectedFilesFolders];
- }];
-
- // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
-
- 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) {
- [self saveSelectedFiles];
- }];
-
- // ITEM DELETE ------------------------------------------------------------------------------------------------------
-
- appDelegate.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
- [self deleteFile];
- }];
-
- // E2EE
- if (_metadataFolder.e2eEncrypted) {
- if ([NCBrandOptions sharedInstance].disable_openin_file) {
- appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.deleteItem]];
- } else {
- appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
- }
- } else {
- if ([NCBrandOptions sharedInstance].disable_openin_file) {
- appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.deleteItem]];
- } else {
- appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
- }
- }
-
- appDelegate.reSelectMenu.itemHeight = 50;
- appDelegate.reSelectMenu.imageOffset = CGSizeMake(5, -1);
-
- appDelegate.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
- appDelegate.reSelectMenu.imageOffset = CGSizeMake(0, 0);
- appDelegate.reSelectMenu.waitUntilAnimationIsComplete = NO;
-
- appDelegate.reSelectMenu.separatorHeight = 0.5;
- appDelegate.reSelectMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
-
- appDelegate.reSelectMenu.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
- appDelegate.reSelectMenu.textColor = [UIColor blackColor];
- appDelegate.reSelectMenu.textAlignment = NSTextAlignmentLeft;
- appDelegate.reSelectMenu.textShadowColor = nil;
- appDelegate.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
- appDelegate.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
-
- appDelegate.reSelectMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- appDelegate.reSelectMenu.highlightedSeparatorColor = nil;
- appDelegate.reSelectMenu.highlightedTextColor = [UIColor blackColor];
- appDelegate.reSelectMenu.highlightedTextShadowColor = nil;
- appDelegate.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
-
- appDelegate.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
- appDelegate.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
- appDelegate.reSelectMenu.subtitleTextShadowColor = nil;
- appDelegate.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
- appDelegate.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
- appDelegate.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
-
- appDelegate.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
- appDelegate.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
- appDelegate.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
-
- appDelegate.reSelectMenu.borderWidth = 0.3;
- appDelegate.reSelectMenu.borderColor = [UIColor lightGrayColor];
-
- appDelegate.reSelectMenu.closeAnimationDuration = 0.2;
- appDelegate.reSelectMenu.animationDuration = 0.2;
- appDelegate.reSelectMenu.bounce = NO;
-
- __weak typeof(self) weakSelf = self;
- [appDelegate.reSelectMenu setClosePreparationBlock:^{
-
- // Backgroun reMenu (Gesture)
- [weakSelf.reMenuBackgroundView removeFromSuperview];
- [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
- }];
- }
- - (void)toggleReSelectMenu
- {
- if (appDelegate.reSelectMenu.isOpen) {
-
- [appDelegate.reSelectMenu close];
-
- } else {
-
- [self createReSelectMenu];
- [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
-
- // Backgroun reMenu & (Gesture)
- [self createReMenuBackgroundView:appDelegate.reSelectMenu];
-
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
- [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
- {
- if (recognizer.state == UIGestureRecognizerStateBegan) {
-
- CGPoint touchPoint = [recognizer locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
-
- if ([self indexPathIsValid:indexPath])
- self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
- else
- self.metadata = nil;
-
- [self becomeFirstResponder];
-
- UIMenuController *menuController = [UIMenuController sharedMenuController];
-
- UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
- UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
- UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
-
- UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
-
- UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
-
- if ([NCBrandOptions sharedInstance].disable_openin_file) {
- [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, pasteFileItem, pasteFilesItem, nil]];
- } else {
- [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
- }
-
- [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
- [menuController setMenuVisible:YES animated:YES];
- }
- }
- - (BOOL)canBecomeFirstResponder
- {
- return YES;
- }
- - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- {
- // For copy file, copy files, Open in ... :
- //
- // NO Directory
- // NO Error Passcode
- // NO In Session mode (download/upload)
- // NO Template
-
- if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
-
- if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
- else return NO;
- }
-
- if (@selector(copyFiles:) == action) {
-
- if (_isSelectedMode) {
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- if (!metadata.directory && metadata.status == k_metadataStatusNormal)
- return YES;
- }
- }
- return NO;
- }
- if (@selector(pasteFile:) == action) {
-
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSArray *items = [pasteboard items];
-
- if ([items count] == 1) {
-
- // Value : (NSData) fileID
-
- NSDictionary *dic = [items objectAtIndex:0];
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
-
- if (fileID) {
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
- if (metadata) {
- return [CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView];
- } else {
- return NO;
- }
- }
- }
-
- return NO;
- }
-
- if (@selector(pasteFiles:) == action) {
-
- BOOL isValid = NO;
-
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSArray *items = [pasteboard items];
-
- if ([items count] <= 1) return NO;
-
- for (NSDictionary *dic in items) {
-
- // Value : (NSData) fileID
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
- if (fileID) {
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
- if (metadata) {
- if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
- isValid = YES;
- } else {
- isValid = NO;
- break;
- }
- } else {
- isValid = NO;
- break;
- }
- } else {
- isValid = NO;
- break;
- }
- }
-
- return isValid;
- }
-
- return NO;
- }
- /************************************ COPY ************************************/
- - (void)copyFile:(id)sender
- {
- // Remove all item
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.items = [[NSArray alloc] init];
-
- if ([CCUtility fileProviderStorageExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
-
- [self copyFileToPasteboard:self.metadata];
-
- } else {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
-
- if (serverUrl) {
-
- self.metadata.session = k_download_session;
- self.metadata.sessionError = @"";
- self.metadata.sessionSelector = selectorLoadCopy;
- self.metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
- }
- }
- }
- - (void)copyFiles:(id)sender
- {
- // Remove all item
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.items = [[NSArray alloc] init];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
-
- [self copyFileToPasteboard:metadata];
-
- } else {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (serverUrl) {
-
- metadata.session = k_download_session;
- metadata.sessionError = @"";
- metadata.sessionSelector = selectorLoadCopy;
- metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
- }
- }
- }
-
- [self tableViewSelect:NO];
- }
- - (void)copyFileToPasteboard:(tableMetadata *)metadata
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
-
- // Value : (NSData) fileID
-
- NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.fileID], k_metadataKeyedUnarchiver,nil];
- [items addObject:item];
-
- [pasteboard setItems:items];
- }
- /************************************ OPEN IN ... ******************************/
- - (void)openinFile:(id)sender
- {
- [self DownloadOpenIn:self.metadata];
- }
- /************************************ PASTE ************************************/
- - (void)pasteFile:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items]];
- }
- - (void)pasteFiles:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items]];
- }
- - (void)uploadFilePasteArray:(NSArray *)items
- {
- for (NSDictionary *dic in items) {
-
- // Value : (NSData) fileID
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-
- if (metadata) {
-
- if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
-
- NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView directoryID:directoryID];
- NSString *fileID = [directoryID stringByAppendingString:fileName];
-
- [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageFileID:fileID fileNameView:fileName]];
-
- tableMetadata *metadataForUpload = [tableMetadata new];
-
- metadataForUpload.account = appDelegate.activeAccount;
- metadataForUpload.date = [NSDate new];
- metadataForUpload.directoryID = directoryID;
- metadataForUpload.fileID = fileID;
- metadataForUpload.fileName = fileName;
- metadataForUpload.fileNameView = fileName;
- metadataForUpload.session = k_upload_session;
- metadataForUpload.sessionSelector = selectorUploadFile;
- metadataForUpload.size = metadata.size;
- metadataForUpload.status = k_metadataStatusWaitUpload;
-
- // Add Medtadata for upload
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- }
- }
-
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Lock Passcode =====
- #pragma --------------------------------------------------------------------------------------------
- - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
- {
- return _failedAttempts;
- }
- - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
- {
- return _lockUntilDate;
- }
- - (void)passcodeViewCloseButtonPressed:(id)sender
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
- {
- if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
- if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
- _lockUntilDate = nil;
- _failedAttempts = 0;
- aResultHandler(YES);
- } else aResultHandler(NO);
- } else aResultHandler(YES);
- }
- - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
- {
- [aViewController dismissViewControllerAnimated:YES completion:nil];
-
- switch (aViewController.type) {
-
- case BKPasscodeViewControllerCheckPasscodeType: {
-
- if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
-
- // possiamo procedere alla prossima directory
- [self performSegueDirectoryWithControlPasscode:false];
-
- // avviamo la sessione Passcode Lock con now
- appDelegate.sessionePasscodeLock = [NSDate date];
- }
-
- // disattivazione lock cartella
- if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (!serverUrl)
- return;
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
-
- if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO]) {
-
- [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- }
-
- [self tableViewReloadData];
- }
- }
- break;
- default:
- break;
- }
- }
- - (void)comandoLockPassword
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (!serverUrl) return;
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
- // se non è abilitato il Lock Passcode esci
- if ([[CCUtility getBlockCode] length] == 0) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
- [alertController addAction:okAction];
- [self presentViewController:alertController animated:YES completion:nil];
- return;
- }
-
- // se è richiesta la disattivazione si chiede la password
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
-
- if (directory.lock) {
-
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
- viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
- viewController.inputViewTitlePassword = YES;
-
- if ([CCUtility getSimplyBlockCode]) {
-
- viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 6;
-
- } else {
-
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
- }
-
- BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
- touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
- viewController.touchIDManager = touchIDManager;
- viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navigationController animated:YES completion:nil];
-
- return;
- }
-
- // ---------------- ACTIVATE PASSWORD
-
- if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES]) {
-
- NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:self.metadata.fileID];
- if ([self indexPathIsValid:indexPath])
- [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
-
- } else {
-
- [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- }
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
- {
- if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
- return NO;
-
- if (metadata == nil || metadata.status != k_metadataStatusNormal)
- return NO;
-
- // E2EE
- if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
- return NO;
-
- return YES;
- }
- - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
- {
- NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- return [self canOpenMenuAction:metadata];
- }
- -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
- {
- }
- - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
- {
- NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
- self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (direction == MGSwipeDirectionRightToLeft) {
- [self actionDelete:indexPath];
- }
-
- if (direction == MGSwipeDirectionLeftToRight) {
- if (self.metadata.favorite)
- [self settingFavorite:self.metadata favorite:NO];
- else
- [self settingFavorite:self.metadata favorite:YES];
- }
-
- return YES;
- }
- - (void)actionDelete:(NSIndexPath *)indexPath
- {
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- // Directory locked ?
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] addFileName:metadata.fileName];
- if (!lockServerUrl) return;
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
- tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
-
- if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) {
-
- [appDelegate messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
- return;
- }
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- [self performSelector:@selector(deleteFile) withObject:nil];
- }]];
-
- if (localFile) {
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }]];
- }
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }]];
-
- alertController.popoverPresentationController.sourceView = self.tableView;
- alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [alertController.view layoutIfNeeded];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
- {
- CGPoint touch = [gestureRecognizer locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
-
- self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (!serverUrl) return;
-
- NSString *titoloLock, *titleFavorite;
-
- if (self.metadata.favorite) {
- titleFavorite = NSLocalizedString(@"_remove_favorites_", nil);
- } else {
- titleFavorite = NSLocalizedString(@"_add_favorites_", nil);
- }
-
- if (self.metadata.directory) {
-
- // calcolo lockServerUrl
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
-
- if (directory.lock)
- titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
- else
- titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
- }
-
- // ******************************************* AHKActionSheet *******************************************
-
- AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
-
- actionSheet.animationDuration = 0.2;
-
- actionSheet.buttonHeight = 50.0;
- actionSheet.cancelButtonHeight = 50.0f;
- actionSheet.separatorHeight = 5.0f;
-
- actionSheet.automaticallyTintButtonImages = @(NO);
-
- actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].encrypted };
- actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
- actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName:[UIColor blackColor] };
- actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
-
- actionSheet.separatorColor = [NCBrandColor sharedInstance].seperator;
- actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
-
- // ******************************************* DIRECTORY *******************************************
-
- if (self.metadata.directory) {
-
- BOOL lockDirectory = NO;
- BOOL optionOffline = NO;
- NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
- NSString *firstServerUrl = [CCUtility firtsPathComponentFromServerUrl:dirServerUrl activeUrl:appDelegate.activeUrl];
- BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] account:appDelegate.activeAccount];
-
- // Directory bloccata ?
- tableDirectory *directoryForLock = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl]];
- if (directoryForLock.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) lockDirectory = YES;
-
- // Directory set as offline ?
- tableDirectory *directoryOffline = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl CONTAINS %@ AND offline == true", appDelegate.activeAccount, firstServerUrl]];
- if (directoryOffline == nil) {
- optionOffline = YES;
- } else if (directoryOffline.serverUrl.length == dirServerUrl.length) {
- optionOffline = YES;
- } else if (directoryOffline.serverUrl.length > dirServerUrl.length) {
- optionOffline = YES;
- }
-
- [actionSheet addButtonWithTitle:self.metadata.fileNameView
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDisabled
- handler:nil
- ];
-
- [actionSheet addButtonWithTitle: titleFavorite
- image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:[NCBrandColor sharedInstance].yellowFavorite]
- backgroundColor: [NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type: AHKActionSheetButtonTypeDefault
- handler: ^(AHKActionSheet *as) {
- if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
- else [self settingFavorite:self.metadata favorite:YES];
- }];
-
- if (!lockDirectory && !isFolderEncrypted) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self openWindowShare:self.metadata];
- }];
- }
-
- if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !self.metadata.e2eEncrypted) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.text = self.metadata.fileNameView;
- //textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
- //textField.delegate = self;
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"[LOG] Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
-
- [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }];
- }
-
- if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !isFolderEncrypted) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
- }];
- }
-
- if (!isFolderEncrypted && optionOffline) {
-
- NSString *title;
-
- if (directoryOffline == nil) {
- title = NSLocalizedString(@"_set_available_offline_", nil);
- } else if (directoryOffline.serverUrl.length == dirServerUrl.length) {
- title = NSLocalizedString(@"_remove_available_offline_", nil);
- } else if (directoryOffline.serverUrl.length > dirServerUrl.length) {
- title = NSLocalizedString(@"_set_available_offline_", nil);
- }
-
- [actionSheet addButtonWithTitle:title
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- if (directoryOffline == nil) {
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:true];
- [[CCSynchronize sharedSynchronize] readFolder:dirServerUrl selector:selectorReadFolderWithDownload];
- } else if (directoryOffline.serverUrl.length == dirServerUrl.length) {
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:false];
- [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- } else if (directoryOffline.serverUrl.length > dirServerUrl.length) {
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:directoryOffline.serverUrl offline:false];
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:true];
- [[CCSynchronize sharedSynchronize] readFolder:dirServerUrl selector:selectorReadFolderWithDownload];
- }
- }];
- }
-
- if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES)) {
-
- [actionSheet addButtonWithTitle:titoloLock
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self performSelector:@selector(comandoLockPassword) withObject:nil];
- }];
- }
-
- if (!self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_set_folder_encrypted_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
- 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];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (error) {
- [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- } else {
- [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
- [self readFolder:self.serverUrl];
- }
- });
- });
- }];
- }
-
- if (self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_remove_folder_encrypted_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- 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];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (error) {
- [appDelegate messageNotification:@"_e2e_error_delete_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- } else {
- [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
- [self readFolder:self.serverUrl];
- }
- });
- });
- }];
- }
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor redColor]]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDestructive
- handler:^(AHKActionSheet *as) {
- [self actionDelete:indexPath];
- }];
- [actionSheet show];
- }
-
- // ******************************************* FILE *******************************************
-
- if (!self.metadata.directory) {
-
- UIImage *iconHeader;
- // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
- if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]])
- iconHeader = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
- else
- iconHeader = [UIImage imageNamed:self.metadata.iconName];
-
- [actionSheet addButtonWithTitle: self.metadata.fileNameView
- image: iconHeader
- backgroundColor: [NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type: AHKActionSheetButtonTypeDisabled
- handler: nil
- ];
-
-
- [actionSheet addButtonWithTitle: titleFavorite
- image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:[NCBrandColor sharedInstance].yellowFavorite]
- backgroundColor: [NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type: AHKActionSheetButtonTypeDefault
- handler: ^(AHKActionSheet *as) {
- if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
- else [self settingFavorite:self.metadata favorite:YES];
- }];
-
- if (!_metadataFolder.e2eEncrypted) {
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self openWindowShare:self.metadata];
- }];
- }
-
- if (![NCBrandOptions sharedInstance].disable_openin_file) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self performSelector:@selector(DownloadOpenIn:) withObject:self.metadata];
- }];
- }
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.text = self.metadata.fileNameView;
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"[LOG] Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- UITextField *fileName = alertController.textFields.firstObject;
- [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }];
-
- if (!_metadataFolder.e2eEncrypted) {
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
- [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
- }];
- }
-
- if (!_metadataFolder.e2eEncrypted) {
-
- NSString *title;
- tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", self.metadata.fileID]];
- if (localFile == nil || localFile.offline == false) { title = NSLocalizedString(@"_set_available_offline_", nil); }
- else { title = NSLocalizedString(@"_remove_available_offline_", nil); }
-
- [actionSheet addButtonWithTitle:title
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- if (localFile == nil || ![CCUtility fileProviderStorageExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
- self.metadata.session = k_download_session;
- self.metadata.sessionError = @"";
- self.metadata.sessionSelector = selectorLoadOffline;
- self.metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
- } else if (localFile.offline == false) {
- [[NCManageDatabase sharedInstance] setLocalFileWithFileID:self.metadata.fileID offline:true];
- [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- } else {
- [[NCManageDatabase sharedInstance] setLocalFileWithFileID:self.metadata.fileID offline:false];
- [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- }
- }];
- }
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor redColor]]
- backgroundColor:[NCBrandColor sharedInstance].backgroundView
- height:50.0
- type:AHKActionSheetButtonTypeDestructive
- handler:^(AHKActionSheet *as) {
- [self actionDelete:indexPath];
- }];
-
- [actionSheet show];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Datasource ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)clearDateReadDataSource:(NSNotification *)notification
- {
- _dateReadDataSource = Nil;
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
- }
- - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID action:(NSInteger)action
- {
- // test
- if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
- return;
-
- // Search Mode
- if (_isSearchMode) {
-
- // Create metadatas
- NSMutableArray *metadatas = [NSMutableArray new];
- for (tableMetadata *resultMetadata in _searchResultMetadatas) {
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", resultMetadata.fileID]];
- if (metadata) {
- [metadatas addObject:metadata];
- }
- }
-
- sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
- [self tableViewReloadData];
-
- if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
-
- _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
- _noFilesSearchDescription = @"";
- }
-
- if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
-
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
- }
-
- [self.tableView reloadEmptyDataSet];
-
- return;
- }
-
- // Se non siamo nella dir appropriata esci
- if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
- return;
- }
-
- // Remove optimization for encrypted directory
- if (_metadataFolder.e2eEncrypted)
- _dateReadDataSource = nil;
-
- // Controllo data lettura Data Source
- tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
- // Get MetadataFolder
- if (![serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
- _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", tableDirectory.fileID]];
-
- NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
-
- if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
-
- NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
- _dateReadDataSource = [NSDate date];
-
- // Data Source
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- sectionDataSource = sectionDataSourceTemp;
- [self tableViewReloadData];
- });
- });
-
- } else {
-
- [self tableViewReloadData];
- NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
- }
-
- }
- - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
- {
- // test
- if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
- return nil;
- }
-
- // current directoryID
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
- if (directoryID == nil) {
- return nil;
- }
-
- // get auto upload folder
- _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
- _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
-
- CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
- NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND status != %i", directoryID, k_metadataStatusHide] sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
-
- sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
-
- if (withReloadData) {
- sectionDataSource = sectionDataSourceTemp;
- [self tableViewReloadData];
- }
-
- return sectionDataSourceTemp;
- }
- - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
- {
- NSMutableArray *metadatas = [[NSMutableArray alloc] init];
-
- if (selectedRows.count > 0) {
-
- for (NSIndexPath *selectionIndex in selectedRows) {
-
- NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
- tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
- [metadatas addObject:metadata];
- }
- }
-
- return metadatas;
- }
- - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
- {
- NSInteger totSections =[sectionDataSource.sections count] ;
-
- if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
- return nil;
- }
-
- id valueSection = [sectionDataSource.sections objectAtIndex:section];
-
- return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Table ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)tableViewSelect:(BOOL)edit
- {
- // chiudiamo eventuali swipe aperti
- if (edit)
- [self.tableView setEditing:NO animated:NO];
-
- [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
- [self.tableView setEditing:edit animated:YES];
- _isSelectedMode = edit;
-
- if (edit)
- [self setUINavigationBarSelected];
- else
- [self setUINavigationBarDefault];
-
- [_selectedFileIDsMetadatas removeAllObjects];
-
- [self setTitle];
- }
- - (void)tableViewReloadData
- {
- // store selected cells before relod
- NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
-
- // reload table view
- [self.tableView reloadData];
-
- // selected cells stored
- for (NSIndexPath *path in indexPaths)
- [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
-
- [self setTableViewFooter];
-
- if (self.tableView.editing)
- [self setTitle];
-
- //
- [self.tableView reloadEmptyDataSet];
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.editing == 1) {
-
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
- return NO;
-
- if (metadata == nil || metadata.status != k_metadataStatusNormal)
- return NO;
- else
- return YES;
-
- } else {
-
- [_selectedFileIDsMetadatas removeAllObjects];
- }
-
- return YES;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 60;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return [[sectionDataSource.sectionArrayRow allKeys] count];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
- NSString *sectionTitle = [sections objectAtIndex:section];
-
- if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
- if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
-
- if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
-
- return 20.f;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- float shift;
- UIVisualEffectView *visualEffectView;
-
- NSString *titleSection;
-
- if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
- return nil;
-
- if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
- titleSection = [sectionDataSource.sections objectAtIndex:section];
-
- if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
- titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
-
- if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
- else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
- else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
- else titleSection = NSLocalizedString(titleSection,nil);
-
- // Format title
- NSString *currentDevice = [CCUtility currentDevice];
- if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
-
- visualEffectView = [[UIVisualEffectView alloc] init];
- visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.3];
-
- } else {
-
- UIVisualEffect *blurEffect;
- blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
- visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.2];
- }
-
- if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- shift = - 35;
- else
- shift = - 20;
-
- } else shift = - 10;
-
- // Title
- UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
- titleLabel.backgroundColor = [UIColor clearColor];
- titleLabel.textColor = [UIColor blackColor];
- titleLabel.font = [UIFont systemFontOfSize:12];
- titleLabel.textAlignment = NSTextAlignmentLeft;
- titleLabel.text = titleSection;
- titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [visualEffectView.contentView addSubview:titleLabel];
-
- // Elements
- UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
- elementLabel.backgroundColor = [UIColor clearColor];
- elementLabel.textColor = [UIColor blackColor];;
- elementLabel.font = [UIFont systemFontOfSize:12];
- elementLabel.textAlignment = NSTextAlignmentRight;
- elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
- NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
- NSUInteger rowsCount = [metadatas count];
-
- if (rowsCount == 0) return nil;
- if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
- if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
-
- [visualEffectView.contentView addSubview:elementLabel];
-
- return visualEffectView;
- }
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- {
- return [sectionDataSource.sections indexOfObject:title];
- }
- - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
- {
- if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
- return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
- else
- return nil;
- }
- /*
- -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
-
- }
- }
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
- return [CCCellMain new];
- }
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (serverUrl == nil) {
- return [CCCellMain new];
- }
-
- UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory];
-
- // NORMAL - > MAIN
-
- if ([cell isKindOfClass:[CCCellMain class]]) {
-
- NSString *shareLink = [appDelegate.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- NSString *shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- BOOL isShare = false;
- BOOL isMounted = false;
-
- if (_metadataFolder) {
- isShare = [metadata.permissions containsString:k_permission_shared] && ![_metadataFolder.permissions containsString:k_permission_shared];
- isMounted = [metadata.permissions containsString:k_permission_mounted] && ![_metadataFolder.permissions containsString:k_permission_mounted];
- }
-
- // Share add Tap
- if (isShare || isMounted || shareLink != nil || shareUserAndGroup != nil) {
-
- if (isShare || isMounted) {
-
- // Shared with you
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
- [tap setNumberOfTapsRequired:1];
- ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
- [((CCCellMain *)cell).shared addGestureRecognizer:tap];
-
- } else if (shareLink != nil || shareUserAndGroup != nil) {
-
- // You share
-
- if (metadata.directory) {
- ((CCCellMain *)cell).shared.userInteractionEnabled = NO;
- } else {
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
- [tap setNumberOfTapsRequired:1];
- ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
- [((CCCellMain *)cell).shared addGestureRecognizer:tap];
- }
- }
- }
-
- // More
- if ([self canOpenMenuAction:metadata]) {
-
- UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
- [tapMore setNumberOfTapsRequired:1];
- ((CCCellMain *)cell).more.userInteractionEnabled = YES;
- [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
- }
-
- // MGSwipeButton
- ((CCCellMain *)cell).delegate = self;
- // LEFT
- ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:1 color:[UIColor whiteColor]] backgroundColor:[NCBrandColor sharedInstance].yellowFavorite padding:25]];
-
- ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
- ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
-
- //centerIconOverText
- MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
- [favoriteButton centerIconOverText];
-
- // RIGHT
- ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor whiteColor]] backgroundColor:[UIColor redColor] padding:25]];
-
- ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
- ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
-
- //centerIconOverText
- MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
- [deleteButton centerIconOverText];
- }
-
- // TRANSFER
-
- if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
-
- // gesture Transfer
- [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
-
- UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
- [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
- [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
- }
-
- return cell;
-
- }
- - (void)setTableViewFooter
- {
- UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
- [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
-
- UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
- [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
-
- UIFont *appFont = [UIFont systemFontOfSize:12];
-
- footerLabel.font = appFont;
- footerLabel.textColor = [UIColor grayColor];
- footerLabel.backgroundColor = [UIColor clearColor];
- footerLabel.textAlignment = NSTextAlignmentCenter;
-
- NSString *folders;
- NSString *files;
- NSString *footerText;
-
- if (sectionDataSource.directories > 1) {
- folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
- } else if (sectionDataSource.directories == 1){
- folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
- } else {
- folders = @"";
- }
-
- if (sectionDataSource.files > 1) {
- files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
- } else if (sectionDataSource.files == 1){
- files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
- } else {
- files = @"";
- }
-
- if ([folders isEqualToString:@""]) {
- footerText = files;
- } else if ([files isEqualToString:@""]) {
- footerText = folders;
- } else {
- footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
- }
-
- footerLabel.text = footerText;
-
- [footerView addSubview:footerLabel];
- [self.tableView setTableFooterView:footerView];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
-
- // settiamo il record file.
- self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- if (!self.metadata)
- return;
-
- // se non può essere selezionata deseleziona
- if ([cell isEditing] == NO)
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
- if (self.tableView.editing) {
-
- [_selectedFileIDsMetadatas setObject:self.metadata forKey:self.metadata.fileID];
- [self setTitle];
- return;
- }
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (!serverUrl) return;
-
- // se è in corso una sessione
- if (self.metadata.status != k_metadataStatusNormal)
- return;
-
- // file
- if (self.metadata.directory == NO) {
-
- // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
- if ([CCUtility fileProviderStorageExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
-
- [[NCNetworkingMain sharedInstance] downloadFileSuccessFailure:self.metadata.fileName fileID:self.metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView errorMessage:@"" errorCode:0];
-
- } else {
-
- if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
-
- [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
-
- } else {
-
- 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) {
-
- [self shouldPerformSegue:self.metadata];
-
- } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCViewerRichdocument sharedInstance] isRichDocument:self.metadata]) {
-
- [self shouldPerformSegue:self.metadata];
-
- } else {
-
- self.metadata.session = k_download_session;
- self.metadata.sessionError = @"";
- self.metadata.sessionSelector = selectorLoadFileView;
- self.metadata.status = k_metadataStatusWaitDownload;
-
- // Add Metadata for Download
- (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
- [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
- }
- }
- }
- }
-
- if (self.metadata.directory) {
-
- imageTitleSegue = cell.imageTitleSegue;
- [self performSegueDirectoryWithControlPasscode:true];
- }
- }
- - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
-
- [_selectedFileIDsMetadatas removeObjectForKey:metadata.fileID];
-
- [self setTitle];
- }
- - (void)didSelectAll
- {
- for (int i = 0; i < self.tableView.numberOfSections; i++) {
- for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
- tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
- [_selectedFileIDsMetadatas setObject:metadata forKey:metadata.fileID];
- [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
- }
- }
- [self setTitle];
- }
- - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
- {
- if (!indexPath)
- return NO;
-
- NSInteger section = indexPath.section;
- NSInteger row = indexPath.row;
-
- NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
-
- if (section > lastSectionIndex || lastSectionIndex < 0)
- return NO;
-
- NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
-
- if (rowCount < 0)
- return NO;
-
- return row <= rowCount;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Navigation ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)shouldPerformSegue:(tableMetadata *)metadata
- {
- // if background return
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
-
- if (self.view.window == NO)
- return;
-
- // Collapsed ma siamo già in detail esci
- if (self.splitViewController.isCollapsed)
- if (_detailViewController.isViewLoaded && _detailViewController.view.window) return;
-
- // Metadata for push detail
- self.metadataForPushDetail = metadata;
-
- [self performSegueWithIdentifier:@"segueDetail" sender:self];
- }
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- id viewController = segue.destinationViewController;
- tableMetadata *metadata;
-
- if ([viewController isKindOfClass:[UINavigationController class]]) {
-
- UINavigationController *nav = viewController;
- _detailViewController = (CCDetail *)nav.topViewController;
-
- } else {
-
- _detailViewController = segue.destinationViewController;
- }
-
- NSMutableArray *photoDataSource = [NSMutableArray new];
-
- if ([sender isKindOfClass:[tableMetadata class]]) {
-
- metadata = sender;
- [photoDataSource addObject:sender];
-
- } else {
-
- metadata = self.metadataForPushDetail;
-
- for (NSString *fileID in sectionDataSource.allFileID) {
- tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
- [photoDataSource addObject:metadata];
- }
- }
-
- _detailViewController.metadataDetail = metadata;
- _detailViewController.photoDataSource = photoDataSource;
- _detailViewController.dateFilterQuery = nil;
-
- [_detailViewController setTitle:metadata.fileNameView];
- }
- // can i go to next viewcontroller
- - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
- {
- NSString *nomeDir;
- if (self.tableView.editing == NO) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
- if (!serverUrl) return;
-
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
-
- // 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
- if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil && controlPasscode) {
-
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
- viewController.fromType = CCBKPasscodeFromLockDirectory;
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
- viewController.inputViewTitlePassword = YES;
-
- if ([CCUtility getSimplyBlockCode]) {
-
- viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 6;
-
- } else {
-
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
- }
- BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
- touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
- viewController.touchIDManager = touchIDManager;
-
- viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
-
- UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navController animated:YES completion:nil];
-
- return;
- }
-
- // E2EE Check enable
- if (self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
-
- [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
- return;
- }
-
- nomeDir = self.metadata.fileName;
-
- NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
-
- CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
-
- if (!viewController) {
-
- viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
-
- viewController.serverUrl = serverUrlPush;
- viewController.titleMain = self.metadata.fileName;
- viewController.imageTitle = imageTitleSegue;
-
- // save self
- [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
-
- [self.navigationController pushViewController:viewController animated:YES];
-
- } else {
-
- if (viewController.isViewLoaded) {
-
- viewController.titleMain = self.metadata.fileName;
- viewController.imageTitle = imageTitleSegue;
-
- // Fix : Application tried to present modally an active controller
- if ([self.navigationController isBeingPresented]) {
- // being presented
- } else if ([self.navigationController isMovingToParentViewController]) {
- // being pushed
- } else {
- [self.navigationController pushViewController:viewController animated:YES];
- }
- }
- }
- }
- }
- @end
|