CCMain.m 215 KB

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