CCMain.m 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604
  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. if (metadata.directory) {
  786. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  787. if (serverUrl) {
  788. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
  789. [[CCSynchronize sharedSynchronize] readFolder:serverUrl selector:selectorReadFolderWithDownload];
  790. }
  791. } else {
  792. [[CCSynchronize sharedSynchronize] readFile:metadata selector:selectorReadFileWithDownload];
  793. }
  794. }
  795. [_hud hideHud];
  796. });
  797. [self tableViewSelect:NO];
  798. }
  799. #pragma --------------------------------------------------------------------------------------------
  800. #pragma mark ===== Upload new Photos/Videos =====
  801. #pragma --------------------------------------------------------------------------------------------
  802. //
  803. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  804. //
  805. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  806. {
  807. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  808. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
  809. // if request create the folder for Auto Upload & the subfolders
  810. if ([autoUploadPath isEqualToString:serverUrl])
  811. if (![[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
  812. return;
  813. dispatch_async(dispatch_get_main_queue(), ^{
  814. [self uploadFileAsset:assets serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
  815. });
  816. });
  817. }
  818. - (void)uploadFileAsset:(NSArray *)assets serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  819. {
  820. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
  821. if (!directoryID) return;
  822. for (PHAsset *asset in assets) {
  823. tableMetadata *metadata;
  824. NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType keyFileNameOriginal:k_keyFileNameOriginal];
  825. NSDate *assetDate = asset.creationDate;
  826. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  827. // Create serverUrl if use sub folder
  828. if (useSubFolder) {
  829. [formatter setDateFormat:@"yyyy"];
  830. NSString *yearString = [formatter stringFromDate:assetDate];
  831. [formatter setDateFormat:@"MM"];
  832. NSString *monthString = [formatter stringFromDate:assetDate];
  833. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
  834. }
  835. // Check if is in upload
  836. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID == %@ AND fileName == %@ AND session != ''", directoryID, fileName];
  837. NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
  838. if ([isRecordInSessions count] > 0)
  839. continue;
  840. // Prepare record metadata
  841. tableMetadata *metadataForUpload = [tableMetadata new];
  842. metadataForUpload.account = appDelegate.activeAccount;
  843. metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
  844. metadataForUpload.date = [NSDate new];
  845. metadataForUpload.directoryID = directoryID;
  846. metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
  847. metadataForUpload.fileName = fileName;
  848. metadataForUpload.fileNameView = fileName;
  849. metadataForUpload.session = session;
  850. metadataForUpload.sessionSelector = selectorUploadFile;
  851. metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
  852. metadataForUpload.status = k_metadataStatusWaitUpload;
  853. NSString *fileNameExtension = [fileName pathExtension];
  854. NSString *fileNameWithoutExtension = [fileName stringByDeletingPathExtension];
  855. if ([[fileNameExtension lowercaseString] isEqualToString:@"heic"] && [CCUtility getFormatCompatibility]) {
  856. NSString *fileNameCompatibility = [fileNameWithoutExtension stringByAppendingString:@".jpg"];
  857. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileNameCompatibility]];
  858. } else {
  859. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileName]];
  860. }
  861. // Check il file already exists
  862. if (metadata) {
  863. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileNameWithoutExtension message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  864. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  865. // NO OVERWITE
  866. }];
  867. UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  868. // Remove record metadata
  869. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID] clearDateReadDirectoryID:metadata.directoryID];
  870. // Add Medtadata for upload
  871. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  872. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  873. }];
  874. [alertController addAction:cancelAction];
  875. [alertController addAction:overwriteAction];
  876. UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  877. alertWindow.rootViewController = [[UIViewController alloc]init];
  878. alertWindow.windowLevel = UIWindowLevelAlert + 1;
  879. [alertWindow makeKeyAndVisible];
  880. [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
  881. } else {
  882. // Add Medtadata for upload
  883. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  884. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  885. }
  886. }
  887. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  888. }
  889. #pragma --------------------------------------------------------------------------------------------
  890. #pragma mark ==== Read File ====
  891. #pragma --------------------------------------------------------------------------------------------
  892. - (void)readFileSuccessFailure:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata message:(NSString *)message errorCode:(NSInteger)errorCode
  893. {
  894. // Check Active Account
  895. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  896. return;
  897. if (errorCode == 0) {
  898. // Read Folder
  899. if ([metadataNet.selector isEqualToString:selectorReadFileReloadFolder]) {
  900. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", metadataNet.account, metadataNet.serverUrl]];
  901. // Change etag, read folder
  902. if ([metadata.etag isEqualToString:directory.etag] == NO) {
  903. [self readFolder:metadataNet.serverUrl];
  904. }
  905. }
  906. } else {
  907. // Unauthorized
  908. if (errorCode == kOCErrorServerUnauthorized)
  909. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  910. }
  911. }
  912. - (void)readFileReloadFolder
  913. {
  914. if (!_serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode)
  915. return;
  916. // Load Datasource
  917. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  918. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  919. });
  920. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  921. metadataNet.action = actionReadFile;
  922. metadataNet.priority = NSOperationQueuePriorityHigh;
  923. metadataNet.selector = selectorReadFileReloadFolder;
  924. metadataNet.serverUrl = _serverUrl;
  925. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  926. }
  927. #pragma --------------------------------------------------------------------------------------------
  928. #pragma mark ==== Read Folder ====
  929. #pragma --------------------------------------------------------------------------------------------
  930. - (void)readFolderSuccessFailure:(CCMetadataNet *)metadataNet metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas message:(NSString *)message errorCode:(NSInteger)errorCode
  931. {
  932. // stoprefresh
  933. [refreshControl endRefreshing];
  934. // Check Active Account
  935. if (![metadataNet.account isEqualToString:metadataNet.account])
  936. return;
  937. // ERROR
  938. if (errorCode != 0) {
  939. _loadingFolder = NO;
  940. // Check Active Account
  941. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  942. return;
  943. // Unauthorized
  944. if (errorCode == kOCErrorServerUnauthorized) {
  945. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  946. } else {
  947. [self tableViewReloadData];
  948. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  949. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  950. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
  951. }
  952. return;
  953. }
  954. // save metadataFolder
  955. _metadataFolder = metadataFolder;
  956. if (_isSearchMode == NO) {
  957. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:metadataNet.serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted];
  958. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND (status == %d OR status == %d)", metadataNet.directoryID, k_metadataStatusNormal, k_metadataStatusHide] clearDateReadDirectoryID:metadataNet.directoryID];
  959. [[NCManageDatabase sharedInstance] setDateReadDirectoryWithDirectoryID:metadataNet.directoryID];
  960. }
  961. 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];
  962. // insert in Database
  963. NSMutableArray *metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas serverUrl:metadataNet.serverUrl];
  964. // reinsert metadatas in Download
  965. if (metadatasInDownload) {
  966. (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload serverUrl:metadataNet.serverUrl];
  967. }
  968. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  969. // File is changed ??
  970. if (!_isSearchMode && metadatasToInsertInDB)
  971. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:metadataNet.serverUrl account:appDelegate.activeAccount withDownload:NO];
  972. });
  973. // Search Mode
  974. if (_isSearchMode) {
  975. // Fix managed -> Unmanaged _searchResultMetadatas
  976. if (metadatasToInsertInDB)
  977. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
  978. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
  979. }
  980. // this is the same directory
  981. if ([metadataNet.serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
  982. // reload
  983. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:nil action:k_action_NULL];
  984. // Enable change user
  985. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  986. _loadingFolder = NO;
  987. [self tableViewReloadData];
  988. }
  989. // E2EE Is encrypted folder get metadata
  990. if (_metadataFolder.e2eEncrypted) {
  991. // Read Metadata
  992. if ([CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  994. NSString *metadata;
  995. NSError *error = [[NCNetworkingEndToEnd sharedManager] getEndToEndMetadata:&metadata fileID:metadataFolder.fileID user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  996. dispatch_async(dispatch_get_main_queue(), ^{
  997. if (error) {
  998. if (error.code != 404)
  999. [appDelegate messageNotification:@"_e2e_error_get_metadata_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1000. } else {
  1001. if ([[NCEndToEndMetadata sharedInstance] decoderMetadata:metadata privateKey:[CCUtility getEndToEndPrivateKey:appDelegate.activeAccount] serverUrl:self.serverUrl account:appDelegate.activeAccount url:appDelegate.activeUrl] == false)
  1002. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1003. else
  1004. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1005. }
  1006. });
  1007. });
  1008. } else {
  1009. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  1010. }
  1011. }
  1012. // rewrite title
  1013. [self setTitle];
  1014. }
  1015. - (void)readFolder:(NSString *)serverUrl
  1016. {
  1017. // init control
  1018. if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
  1019. [refreshControl endRefreshing];
  1020. return;
  1021. }
  1022. // Search Mode
  1023. if (_isSearchMode) {
  1024. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
  1025. _searchFileName = @""; // forced reload searchg
  1026. [self updateSearchResultsForSearchController:self.searchController];
  1027. return;
  1028. }
  1029. _loadingFolder = YES;
  1030. [self tableViewReloadData];
  1031. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  1032. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1033. metadataNet.action = actionReadFolder;
  1034. metadataNet.date = [NSDate date];
  1035. metadataNet.depth = @"1";
  1036. metadataNet.directoryID = directory.directoryID;
  1037. metadataNet.priority = NSOperationQueuePriorityHigh;
  1038. metadataNet.selector = selectorReadFolder;
  1039. metadataNet.serverUrl = serverUrl;
  1040. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1041. }
  1042. #pragma mark -
  1043. #pragma --------------------------------------------------------------------------------------------
  1044. #pragma mark ===== Search =====
  1045. #pragma --------------------------------------------------------------------------------------------
  1046. - (void)searchEnabled:(BOOL)enabled
  1047. {
  1048. if (enabled) {
  1049. if (self.tableView.tableHeaderView != nil)
  1050. return;
  1051. self.definesPresentationContext = YES;
  1052. self.searchController.searchResultsUpdater = self;
  1053. self.searchController.dimsBackgroundDuringPresentation = NO;
  1054. self.searchController.searchBar.translucent = NO;
  1055. [self.searchController.searchBar sizeToFit];
  1056. self.searchController.searchBar.delegate = self;
  1057. self.searchController.searchBar.barTintColor = [NCBrandColor sharedInstance].brand;
  1058. self.searchController.searchBar.backgroundColor = [NCBrandColor sharedInstance].brand;
  1059. self.searchController.searchBar.backgroundImage = [UIImage new];
  1060. // color searchbbar button text (cancel)
  1061. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  1062. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  1063. [searchButton setTitleColor:[NCBrandColor sharedInstance].brandText forState:UIControlStateNormal];
  1064. }
  1065. self.tableView.tableHeaderView = self.searchController.searchBar;
  1066. [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
  1067. } else {
  1068. self.tableView.tableHeaderView = nil;
  1069. }
  1070. }
  1071. - (void)searchStartTimer
  1072. {
  1073. NSString *startDirectory = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  1074. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1075. metadataNet.action = actionSearch;
  1076. metadataNet.contentType = nil;
  1077. metadataNet.date = nil;
  1078. metadataNet.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:startDirectory];
  1079. metadataNet.fileName = _searchFileName;
  1080. metadataNet.etag = @"";
  1081. metadataNet.depth = @"infinity";
  1082. metadataNet.priority = NSOperationQueuePriorityHigh;
  1083. metadataNet.selector = selectorSearchFiles;
  1084. metadataNet.serverUrl = startDirectory;
  1085. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1086. _noFilesSearchTitle = @"";
  1087. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  1088. [self.tableView reloadEmptyDataSet];
  1089. }
  1090. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  1091. {
  1092. // Color text "Cancel"
  1093. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:[NCBrandColor sharedInstance].brandText];
  1094. _isSearchMode = YES;
  1095. [self deleteRefreshControl];
  1096. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  1097. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1098. _searchFileName = fileName;
  1099. // First : filter
  1100. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  1101. if (!directoryID) return;
  1102. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView CONTAINS[cd] %@", directoryID, fileName];
  1103. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
  1104. [_searchResultMetadatas removeAllObjects];
  1105. for (tableMetadata *record in records)
  1106. [_searchResultMetadatas addObject:record];
  1107. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1108. metadataNet.account = appDelegate.activeAccount;
  1109. metadataNet.directoryID = directoryID;
  1110. metadataNet.selector = selectorSearchFiles;
  1111. metadataNet.serverUrl = _serverUrl;
  1112. [self readFolderSuccessFailure:metadataNet metadataFolder:nil metadatas:_searchResultMetadatas message:nil errorCode:0];
  1113. // Version >= 12
  1114. if ([[NCManageDatabase sharedInstance] getServerVersion] >= 12) {
  1115. [_timerWaitInput invalidate];
  1116. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1117. }
  1118. }
  1119. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1120. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1121. }
  1122. }
  1123. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1124. {
  1125. [self cancelSearchBar];
  1126. [self readFolder:_serverUrl];
  1127. }
  1128. - (void)searchSuccessFailure:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas message:(NSString *)message errorCode:(NSInteger)errorCode
  1129. {
  1130. // Check Active Account
  1131. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1132. return;
  1133. if (errorCode == 0) {
  1134. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
  1135. [self readFolderSuccessFailure:metadataNet metadataFolder:nil metadatas:metadatas message:nil errorCode:0];
  1136. } else {
  1137. // Unauthorized
  1138. if (errorCode == kOCErrorServerUnauthorized)
  1139. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  1140. else
  1141. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1142. _searchFileName = @"";
  1143. }
  1144. }
  1145. - (void)cancelSearchBar
  1146. {
  1147. if (self.searchController.active) {
  1148. [self.searchController setActive:NO];
  1149. [self createRefreshControl];
  1150. _isSearchMode = NO;
  1151. _searchFileName = @"";
  1152. _dateReadDataSource = nil;
  1153. _searchResultMetadatas = [NSMutableArray new];
  1154. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1155. }
  1156. //[self setNeedsStatusBarAppearanceUpdate];
  1157. }
  1158. #pragma mark -
  1159. #pragma --------------------------------------------------------------------------------------------
  1160. #pragma mark ===== Delete File or Folder =====
  1161. #pragma --------------------------------------------------------------------------------------------
  1162. - (void)deleteFile
  1163. {
  1164. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  1165. return;
  1166. NSArray *metadatas;
  1167. if ([_selectedFileIDsMetadatas count] > 0) {
  1168. metadatas = [_selectedFileIDsMetadatas allValues];
  1169. } else {
  1170. metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
  1171. }
  1172. // remove optimization
  1173. _dateReadDataSource = nil;
  1174. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:_metadataFolder.e2eEncrypted serverUrl:self.serverUrl folderFileID:_metadataFolder.fileID completion:^(NSInteger errorCode, NSString *message) {
  1175. // Reload
  1176. if (_isSearchMode)
  1177. [self readFolder:self.serverUrl];
  1178. else
  1179. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1180. }];
  1181. // End Select Table View
  1182. [self tableViewSelect:NO];
  1183. }
  1184. #pragma --------------------------------------------------------------------------------------------
  1185. #pragma mark ===== Rename / Move =====
  1186. #pragma --------------------------------------------------------------------------------------------
  1187. - (void)renameSuccess:(CCMetadataNet *)metadataNet
  1188. {
  1189. // Rename metadata
  1190. (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:metadataNet.fileNameTo fileID:metadataNet.fileID];
  1191. if (metadataNet.directory) {
  1192. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadataNet.fileName];
  1193. NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadataNet.fileNameTo];
  1194. tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  1195. if (directoryTable == nil) {
  1196. [self renameMoveFileOrFolderFailure:metadataNet message:@"Internal error, ServerUrl not found" errorCode:0];
  1197. return;
  1198. }
  1199. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:nil fileID:nil encrypted:directoryTable.e2eEncrypted];
  1200. } else {
  1201. [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadataNet.fileID date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:metadataNet.fileNameTo etag:nil];
  1202. // Move file system
  1203. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadataNet.fileID], metadataNet.fileName];
  1204. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadataNet.fileID], metadataNet.fileNameTo];
  1205. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1206. NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadataNet.fileID fileNameView:metadataNet.fileName];
  1207. NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadataNet.fileID fileNameView:metadataNet.fileNameTo];
  1208. [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
  1209. }
  1210. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataNet.serverUrl fileID:metadataNet.fileID action:k_action_MOD];
  1211. }
  1212. - (void)renameFile:(NSArray *)arguments
  1213. {
  1214. tableMetadata* metadata = [arguments objectAtIndex:0];
  1215. NSString *fileName = [arguments objectAtIndex:1];
  1216. // E2EE
  1217. if (_metadataFolder.e2eEncrypted) {
  1218. // verify if exists the new fileName
  1219. if ([[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, self.serverUrl, fileName]]) {
  1220. [appDelegate messageNotification:@"_error_e2ee_" description:@"_file_already_exists_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  1221. return;
  1222. }
  1223. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  1224. 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];
  1225. if (error) {
  1226. dispatch_async(dispatch_get_main_queue(), ^{
  1227. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_send_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1228. });
  1229. } else {
  1230. [[NCManageDatabase sharedInstance] setMetadataFileNameViewWithDirectoryID:metadata.directoryID fileName:metadata.fileName newFileNameView:fileName];
  1231. // Move file system
  1232. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], metadata.fileNameView];
  1233. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], fileName];
  1234. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1235. [[NSFileManager defaultManager] moveItemAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:fileName] error:nil];
  1236. }
  1237. // Unlock
  1238. tableE2eEncryptionLock *tableLock = [[NCManageDatabase sharedInstance] getE2ETokenLockWithServerUrl:self.serverUrl];
  1239. if (tableLock != nil) {
  1240. 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];
  1241. if (error) {
  1242. dispatch_async(dispatch_get_main_queue(), ^{
  1243. [appDelegate messageNotification:@"_e2e_error_unlock_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1244. });
  1245. }
  1246. }
  1247. dispatch_async(dispatch_get_main_queue(), ^{
  1248. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1249. });
  1250. });
  1251. } else {
  1252. // Plain
  1253. NSString *fileNameNew = [CCUtility removeForbiddenCharactersServer:fileName];
  1254. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1255. if ([fileName length] == 0 || [fileName isEqualToString:metadata.fileNameView]) {
  1256. return;
  1257. }
  1258. // Verify if exists the fileName TO
  1259. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  1260. [ocNetworking readFile:fileNameNew serverUrl:serverUrl account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
  1261. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1262. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1263. }];
  1264. [alert addAction:ok];
  1265. [self presentViewController:alert animated:YES completion:nil];
  1266. } failure:^(NSString *message, NSInteger errorCode) {
  1267. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1268. metadataNet.action = actionMoveFileOrFolder;
  1269. metadataNet.directory = metadata.directory;
  1270. metadataNet.fileID = metadata.fileID;
  1271. metadataNet.fileName = metadata.fileName;
  1272. metadataNet.fileNameTo = fileNameNew;
  1273. metadataNet.fileNameView = metadata.fileNameView;
  1274. metadataNet.selector = selectorRename;
  1275. metadataNet.serverUrl = serverUrl;
  1276. metadataNet.serverUrlTo = serverUrl;
  1277. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1278. }];
  1279. }
  1280. }
  1281. - (void)renameMoveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1282. {
  1283. if ([message length] > 0) {
  1284. if ([metadataNet.selector isEqualToString:selectorRename]) {
  1285. [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1286. }
  1287. if ([metadataNet.selector isEqualToString:selectorMove]) {
  1288. [appDelegate messageNotification:@"_move_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1289. }
  1290. }
  1291. if ([metadataNet.selector isEqualToString:selectorMove]) {
  1292. [_hud hideHud];
  1293. if (message && errorCode != kOCErrorServerUnauthorized)
  1294. [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1295. // End Select Table View
  1296. [self tableViewSelect:NO];
  1297. // reload Datasource
  1298. if (_isSearchMode)
  1299. [self readFolder:metadataNet.serverUrl];
  1300. else
  1301. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1302. }
  1303. }
  1304. - (void)moveSuccess:(CCMetadataNet *)metadataNet
  1305. {
  1306. [_queueSelector removeObject:metadataNet.selector];
  1307. if ([_queueSelector count] == 0) {
  1308. [_hud hideHud];
  1309. NSString *fileName = metadataNet.fileName;
  1310. NSString *directoryID = metadataNet.directoryID;
  1311. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1312. NSString *serverUrlTo = [[NCManageDatabase sharedInstance] getServerUrl:directoryIDTo];
  1313. if (!serverUrlTo) return;
  1314. // FILE -> Metadata
  1315. if (metadataNet.directory == NO)
  1316. [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
  1317. // DIRECTORY -> Directory - CCMetadata
  1318. if (metadataNet.directory == YES) {
  1319. // delete all dir / subdir
  1320. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:fileName]];
  1321. // move metadata
  1322. [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
  1323. // Add new directory
  1324. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
  1325. (void) [[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:false favorite:false fileID:nil permissions:nil serverUrl:newDirectory];
  1326. }
  1327. // next
  1328. [_selectedFileIDsMetadatas removeObjectForKey:metadataNet.fileID];
  1329. if ([_selectedFileIDsMetadatas count] > 0) {
  1330. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1331. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrlTo, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1332. } else {
  1333. // End Select Table View
  1334. [self tableViewSelect:NO];
  1335. // reload Datasource
  1336. if (_isSearchMode)
  1337. [self readFolder:metadataNet.serverUrl];
  1338. else
  1339. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1340. }
  1341. }
  1342. }
  1343. - (void)moveFileOrFolderMetadata:(NSArray *)arguments
  1344. {
  1345. tableMetadata *metadata = [arguments objectAtIndex:0];
  1346. NSString *serverUrlTo = [arguments objectAtIndex:1];
  1347. NSInteger numFile = [[arguments objectAtIndex:2] integerValue];
  1348. NSInteger ofFile = [[arguments objectAtIndex:3] integerValue];
  1349. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1350. if (!serverUrl) return;
  1351. NSString *directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
  1352. if (!directoryIDTo) return;
  1353. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  1354. [ocNetworking readFile:metadata.fileName serverUrl:serverUrlTo account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
  1355. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1356. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1357. }];
  1358. [alert addAction:ok];
  1359. [self presentViewController:alert animated:YES completion:nil];
  1360. // End Select Table View
  1361. [self tableViewSelect:NO];
  1362. // reload Datasource
  1363. [self readFileReloadFolder];
  1364. } failure:^(NSString *message, NSInteger errorCode) {
  1365. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1366. metadataNet.action = actionMoveFileOrFolder;
  1367. metadataNet.directory = metadata.directory;
  1368. metadataNet.fileID = metadata.fileID;
  1369. metadataNet.directoryID = metadata.directoryID;
  1370. metadataNet.directoryIDTo = directoryIDTo;
  1371. metadataNet.fileName = metadata.fileName;
  1372. metadataNet.fileNameView = metadata.fileNameView;
  1373. metadataNet.fileNameTo = metadata.fileName;
  1374. metadataNet.etag = metadata.etag;
  1375. metadataNet.selector = selectorMove;
  1376. metadataNet.serverUrl = serverUrl;
  1377. metadataNet.serverUrlTo = serverUrlTo;
  1378. [_queueSelector addObject:metadataNet.selector];
  1379. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1380. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1381. }];
  1382. }
  1383. // DELEGATE : Move
  1384. - (void)dismissMove
  1385. {
  1386. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1387. }
  1388. // DELEGATE : Move
  1389. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title type:(NSString *)type
  1390. {
  1391. [_queueSelector removeAllObjects];
  1392. // E2EE DENIED
  1393. if ([CCUtility isFolderEncrypted:serverUrlTo account:appDelegate.activeAccount]) {
  1394. [appDelegate messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  1395. return;
  1396. }
  1397. if ([_selectedFileIDsMetadatas count] > 0) {
  1398. _numSelectedFileIDsMetadatas = [_selectedFileIDsMetadatas count];
  1399. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1400. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrlTo, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1401. } else {
  1402. _numSelectedFileIDsMetadatas = 1;
  1403. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[self.metadata, serverUrlTo, [NSNumber numberWithInteger:1], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1404. }
  1405. }
  1406. - (void)moveOpenWindow:(NSArray *)indexPaths
  1407. {
  1408. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  1409. return;
  1410. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1411. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1412. viewController.delegate = self;
  1413. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1414. viewController.tintColor = [NCBrandColor sharedInstance].brandText;
  1415. viewController.barTintColor = [NCBrandColor sharedInstance].brand;
  1416. viewController.tintColorTitle = [NCBrandColor sharedInstance].brandText;
  1417. viewController.networkingOperationQueue = appDelegate.netQueue;
  1418. // E2EE
  1419. viewController.includeDirectoryE2EEncryption = NO;
  1420. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1421. [self presentViewController:navigationController animated:YES completion:nil];
  1422. }
  1423. #pragma --------------------------------------------------------------------------------------------
  1424. #pragma mark ===== Create folder =====
  1425. #pragma --------------------------------------------------------------------------------------------
  1426. - (void)createFolder
  1427. {
  1428. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  1429. NSString *message;
  1430. UIAlertController *alertController;
  1431. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  1432. message = @"/";
  1433. } else {
  1434. message = [serverUrl lastPathComponent];
  1435. }
  1436. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  1437. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1438. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  1439. textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
  1440. }];
  1441. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1442. NSLog(@"[LOG] Cancel action");
  1443. }];
  1444. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1445. UITextField *fileName = alertController.textFields.firstObject;
  1446. [self createFolder:fileName.text serverUrl:serverUrl];
  1447. }];
  1448. okAction.enabled = NO;
  1449. [alertController addAction:cancelAction];
  1450. [alertController addAction:okAction];
  1451. [self presentViewController:alertController animated:YES completion:nil];
  1452. }
  1453. - (void)createFolder:(NSString *)fileNameFolder serverUrl:(NSString *)serverUrl
  1454. {
  1455. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1456. if (![fileNameFolder length]) return;
  1457. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
  1458. if (!directoryID) return;
  1459. NSString *fileIDTemp = [[NSUUID UUID] UUIDString];
  1460. // Create Directory (temp) on metadata
  1461. tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:YES fileID:fileIDTemp directoryID:directoryID fileName:fileNameFolder etag:@"" size:0 status:k_metadataStatusNormal];
  1462. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1463. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
  1464. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1465. // Creeate folder Networking
  1466. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  1467. [ocNetworking createFolder:fileNameFolder serverUrl:serverUrl account:appDelegate.activeAccount success:^(NSString *fileID, NSDate *date) {
  1468. // Delete Temp Dir
  1469. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp] clearDateReadDirectoryID:nil];
  1470. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrl, fileNameFolder];
  1471. if (_metadataFolder.e2eEncrypted) {
  1472. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1473. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:newDirectory fileID:fileID user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1474. dispatch_async(dispatch_get_main_queue(), ^{
  1475. if (error) {
  1476. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1477. }
  1478. [self readFolder:self.serverUrl];
  1479. });
  1480. });
  1481. } else {
  1482. [self readFolder:self.serverUrl];
  1483. }
  1484. } failure:^(NSString *message, NSInteger errorCode) {
  1485. // Unauthorized
  1486. if (errorCode == kOCErrorServerUnauthorized)
  1487. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  1488. else
  1489. [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1490. // Delete Temp Dir
  1491. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp] clearDateReadDirectoryID:nil];
  1492. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  1493. // We are in directory fail ?
  1494. CCMain *vc = [appDelegate.listMainVC objectForKey:[CCUtility stringAppendServerUrl:_serverUrl addFileName:fileNameFolder]];
  1495. if (vc)
  1496. [vc.navigationController popViewControllerAnimated:YES];
  1497. }];
  1498. }
  1499. #pragma --------------------------------------------------------------------------------------------
  1500. #pragma mark ===== Progress & Task Button =====
  1501. #pragma --------------------------------------------------------------------------------------------
  1502. - (void)triggerProgressTask:(NSNotification *)notification
  1503. {
  1504. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
  1505. }
  1506. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1507. {
  1508. UITouch *touch = [[event allTouches] anyObject];
  1509. CGPoint location = [touch locationInView:self.tableView];
  1510. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1511. if ([self indexPathIsValid:indexPath]) {
  1512. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1513. if (metadataSection) {
  1514. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadataSection.fileID]];
  1515. if (metadata)
  1516. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
  1517. }
  1518. }
  1519. }
  1520. - (void)cancelAllTask:(id)sender
  1521. {
  1522. CGPoint location = [sender locationInView:self.tableView];
  1523. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1524. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1525. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1526. [[NCMainCommon sharedInstance] cancelAllTransfer];
  1527. }]];
  1528. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  1529. alertController.popoverPresentationController.sourceView = self.tableView;
  1530. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1531. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1532. [alertController.view layoutIfNeeded];
  1533. [self presentViewController:alertController animated:YES completion:nil];
  1534. }
  1535. #pragma --------------------------------------------------------------------------------------------
  1536. #pragma mark ===== Shared =====
  1537. #pragma --------------------------------------------------------------------------------------------
  1538. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  1539. {
  1540. [_hud hideHud];
  1541. // Check Active Account
  1542. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1543. return;
  1544. NSArray *result = [[NCManageDatabase sharedInstance] updateShare:items activeUrl:appDelegate.activeUrl];
  1545. if (result) {
  1546. appDelegate.sharesLink = result[0];
  1547. appDelegate.sharesUserAndGroup = result[1];
  1548. }
  1549. // Notify Shares View
  1550. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
  1551. if (openWindow) {
  1552. if (_shareOC) {
  1553. [_shareOC reloadData];
  1554. } else {
  1555. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadataNet.fileID]];
  1556. // Apriamo la view
  1557. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  1558. _shareOC.delegate = self;
  1559. _shareOC.metadata = metadata;
  1560. _shareOC.serverUrl = metadataNet.serverUrl;
  1561. _shareOC.shareLink = [appDelegate.sharesLink objectForKey:metadata.fileID];
  1562. _shareOC.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:metadata.fileID];
  1563. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  1564. [self presentViewController:_shareOC animated:YES completion:nil];
  1565. }
  1566. }
  1567. [self tableViewReloadData];
  1568. }
  1569. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1570. {
  1571. [_hud hideHud];
  1572. // Check Active Account
  1573. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1574. return;
  1575. // Unauthorized
  1576. if (errorCode == kOCErrorServerUnauthorized)
  1577. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  1578. else
  1579. [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1580. if (_shareOC)
  1581. [_shareOC reloadData];
  1582. [self tableViewReloadData];
  1583. }
  1584. - (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission
  1585. {
  1586. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1587. metadataNet.action = actionShare;
  1588. metadataNet.fileID = metadata.fileID;
  1589. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
  1590. metadataNet.fileNameView = metadata.fileNameView;
  1591. metadataNet.sharePermission = permission;
  1592. metadataNet.password = password;
  1593. metadataNet.selector = selectorShare;
  1594. metadataNet.serverUrl = serverUrl;
  1595. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1596. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1597. }
  1598. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  1599. {
  1600. [_hud hideHud];
  1601. // Check Active Account
  1602. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1603. return;
  1604. // rimuoviamo la condivisione da db
  1605. NSArray *result = [[NCManageDatabase sharedInstance] unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:appDelegate.sharesLink sharesUserAndGroup:appDelegate.sharesUserAndGroup];
  1606. if (result) {
  1607. appDelegate.sharesLink = result[0];
  1608. appDelegate.sharesUserAndGroup = result[1];
  1609. }
  1610. if (_shareOC)
  1611. [_shareOC reloadData];
  1612. [self tableViewReloadData];
  1613. }
  1614. - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl
  1615. {
  1616. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1617. metadataNet.action = actionUnShare;
  1618. metadataNet.fileID = metadata.fileID;
  1619. metadataNet.fileName = metadata.fileName;
  1620. metadataNet.fileNameView = metadata.fileNameView;
  1621. metadataNet.selector = selectorUnshare;
  1622. metadataNet.serverUrl = serverUrl;
  1623. metadataNet.share = share;
  1624. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1625. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1626. }
  1627. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  1628. {
  1629. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1630. metadataNet.action = actionUpdateShare;
  1631. metadataNet.fileID = metadata.fileID;
  1632. metadataNet.expirationTime = expirationTime;
  1633. metadataNet.password = password;
  1634. metadataNet.selector = selectorUpdateShare;
  1635. metadataNet.serverUrl = serverUrl;
  1636. metadataNet.share = share;
  1637. metadataNet.sharePermission = permission;
  1638. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1639. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1640. }
  1641. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  1642. {
  1643. [_hud hideHud];
  1644. // Check Active Account
  1645. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1646. return;
  1647. if (_shareOC)
  1648. [_shareOC reloadUserAndGroup:items];
  1649. }
  1650. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1651. {
  1652. [_hud hideHud];
  1653. // Check Active Account
  1654. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  1655. return;
  1656. // Unauthorized
  1657. if (errorCode == kOCErrorServerUnauthorized)
  1658. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  1659. else
  1660. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1661. }
  1662. - (void)getUserAndGroup:(NSString *)find
  1663. {
  1664. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1665. metadataNet.action = actionGetUserAndGroup;
  1666. metadataNet.optionAny = find;
  1667. metadataNet.selector = selectorGetUserAndGroup;
  1668. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1669. [_hud visibleIndeterminateHud];
  1670. }
  1671. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(tableMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  1672. {
  1673. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1674. metadataNet.action = actionShareWith;
  1675. metadataNet.fileID = metadata.fileID;
  1676. metadataNet.directoryID = directoryID;
  1677. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
  1678. metadataNet.fileNameView = metadata.fileNameView;
  1679. metadataNet.serverUrl = serverUrl;
  1680. metadataNet.selector = selectorShare;
  1681. metadataNet.share = user;
  1682. metadataNet.shareeType = shareeType;
  1683. metadataNet.sharePermission = permission;
  1684. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1685. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1686. }
  1687. - (void)openWindowShare:(tableMetadata *)metadata
  1688. {
  1689. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1690. if (!serverUrl) return;
  1691. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  1692. metadataNet.action = actionReadShareServer;
  1693. metadataNet.fileID = metadata.fileID;
  1694. metadataNet.fileName = metadata.fileName;
  1695. metadataNet.fileNameView = metadata.fileNameView;
  1696. metadataNet.selector = selectorOpenWindowShare;
  1697. metadataNet.serverUrl = serverUrl;
  1698. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  1699. [_hud visibleIndeterminateHud];
  1700. }
  1701. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  1702. {
  1703. CGPoint location = [tapGesture locationInView:self.tableView];
  1704. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1705. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1706. if (metadata)
  1707. [self openWindowShare:metadata];
  1708. }
  1709. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  1710. {
  1711. CGPoint location = [tapGesture locationInView:self.tableView];
  1712. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1713. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1714. if (metadata) {
  1715. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  1716. vc.metadata = metadata;
  1717. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  1718. [self presentViewController:vc animated:YES completion:nil];
  1719. }
  1720. }
  1721. #pragma --------------------------------------------------------------------------------------------
  1722. #pragma mark ===== Favorite =====
  1723. #pragma --------------------------------------------------------------------------------------------
  1724. - (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
  1725. {
  1726. NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
  1727. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  1728. [ocNetworking settingFavorite:fileNameServerUrl favorite:favorite completion:^(NSString *message, NSInteger errorCode) {
  1729. if (errorCode == 0) {
  1730. [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadata.fileID favorite:favorite];
  1731. _dateReadDataSource = nil;
  1732. if (_isSearchMode)
  1733. [self readFolder:self.serverUrl];
  1734. else
  1735. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
  1736. if (metadata.directory && favorite) {
  1737. NSString *dir = [CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName];
  1738. [appDelegate.activeFavorites addFavoriteFolder:dir];
  1739. }
  1740. if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
  1741. metadata.favorite = favorite;
  1742. metadata.session = k_download_session;
  1743. metadata.sessionError = @"";
  1744. metadata.sessionSelector = selectorDownloadSynchronize;
  1745. metadata.status = k_metadataStatusWaitDownload;
  1746. // Add Metadata for Download
  1747. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1748. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  1749. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
  1750. }
  1751. } else {
  1752. if (errorCode == kOCErrorServerUnauthorized)
  1753. [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
  1754. }
  1755. }];
  1756. }
  1757. #pragma --------------------------------------------------------------------------------------------
  1758. #pragma mark ===== Open in... =====
  1759. #pragma --------------------------------------------------------------------------------------------
  1760. - (void)DownloadOpenIn:(tableMetadata *)metadata
  1761. {
  1762. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1763. if (!serverUrl) return;
  1764. metadata.session = k_download_session;
  1765. metadata.sessionError = @"";
  1766. metadata.sessionSelector = selectorOpenIn;
  1767. metadata.status = k_metadataStatusWaitDownload;
  1768. // Add Metadata for Download
  1769. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1770. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  1771. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
  1772. }
  1773. - (void)openIn:(tableMetadata *)metadata
  1774. {
  1775. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  1776. docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  1777. docController.delegate = self;
  1778. NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  1779. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  1780. if (cell) {
  1781. [docController presentOptionsMenuFromRect:cell.frame inView:self.tableView animated:YES];
  1782. } else {
  1783. [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  1784. }
  1785. }
  1786. #pragma --------------------------------------------------------------------------------------------
  1787. #pragma mark ==== Menu LOGO ====
  1788. #pragma --------------------------------------------------------------------------------------------
  1789. - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
  1790. {
  1791. if (appDelegate.reSelectMenu.isOpen || appDelegate.reMainMenu.isOpen)
  1792. return;
  1793. // Brand
  1794. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  1795. return;
  1796. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  1797. NSMutableArray *menuArray = [NSMutableArray new];
  1798. for (NSString *account in listAccount) {
  1799. CCMenuItem *item = [[CCMenuItem alloc] init];
  1800. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  1801. item.argument = account;
  1802. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
  1803. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-avatar.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url]];
  1804. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  1805. if (avatar) {
  1806. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
  1807. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  1808. CGSize imageSize = avatarImageView.bounds.size;
  1809. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1810. CGContextRef context = UIGraphicsGetCurrentContext();
  1811. [avatarImageView.layer renderInContext:context];
  1812. avatar = UIGraphicsGetImageFromCurrentImageContext();
  1813. UIGraphicsEndImageContext();
  1814. } else {
  1815. avatar = [UIImage imageNamed:@"menuLogoUser"];
  1816. }
  1817. item.image = avatar;
  1818. item.target = self;
  1819. if ([account isEqualToString:appDelegate.activeAccount]) {
  1820. item.action = nil;
  1821. [menuArray insertObject:item atIndex:0];
  1822. } else {
  1823. item.action = @selector(changeDefaultAccount:);
  1824. [menuArray addObject:item];
  1825. }
  1826. }
  1827. // Add + new account
  1828. CCMenuItem *item = [[CCMenuItem alloc] init];
  1829. item.title = NSLocalizedString(@"_add_account_", nil);
  1830. item.argument = @"";
  1831. item.image = [UIImage imageNamed:@"add"];
  1832. item.target = self;
  1833. item.action = @selector(addNewAccount:);
  1834. [menuArray addObject:item];
  1835. OptionalConfiguration options;
  1836. Color textColor, backgroundColor;
  1837. textColor.R = 0;
  1838. textColor.G = 0;
  1839. textColor.B = 0;
  1840. backgroundColor.R = 1;
  1841. backgroundColor.G = 1;
  1842. backgroundColor.B = 1;
  1843. options.arrowSize = 9;
  1844. options.marginXSpacing = 7;
  1845. options.marginYSpacing = 10;
  1846. options.intervalSpacing = 20;
  1847. options.menuCornerRadius = 6.5;
  1848. options.maskToBackground = NO;
  1849. options.shadowOfMenu = YES;
  1850. options.hasSeperatorLine = YES;
  1851. options.seperatorLineHasInsets = YES;
  1852. options.textColor = textColor;
  1853. options.menuBackgroundColor = backgroundColor;
  1854. CGRect rect = self.view.frame;
  1855. CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
  1856. CGFloat safeAreaTop = 0;
  1857. CGFloat offsetY = 35;
  1858. if (@available(iOS 11, *)) {
  1859. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
  1860. }
  1861. rect.origin.y = locationY + safeAreaTop + offsetY;
  1862. rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
  1863. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  1864. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  1865. }
  1866. - (void)changeDefaultAccount:(CCMenuItem *)sender
  1867. {
  1868. 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];
  1869. if (transferInprogress > 0) {
  1870. [JDStatusBarNotification showWithStatus:NSLocalizedString(@"_transfers_in_queue_", nil) dismissAfter:k_dismissAfterSecond styleName:JDStatusBarStyleDefault];
  1871. return;
  1872. }
  1873. [appDelegate.netQueue cancelAllOperations];
  1874. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1875. // LOGOUT
  1876. [appDelegate unsubscribingNextcloudServerPushNotification];
  1877. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  1878. if (tableAccount) {
  1879. // LOGIN
  1880. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
  1881. // go to home sweet home
  1882. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  1883. [appDelegate subscribingNextcloudServerPushNotification];
  1884. }
  1885. });
  1886. }
  1887. - (void)addNewAccount:(CCMenuItem *)sender
  1888. {
  1889. 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];
  1890. if (transferInprogress > 0) {
  1891. [JDStatusBarNotification showWithStatus:NSLocalizedString(@"_transfers_in_queue_", nil) dismissAfter:k_dismissAfterSecond styleName:JDStatusBarStyleDefault];
  1892. return;
  1893. }
  1894. [appDelegate.netQueue cancelAllOperations];
  1895. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1896. [appDelegate openLoginView:self loginType:k_login_Add selector:k_intro_login];
  1897. });
  1898. }
  1899. #pragma --------------------------------------------------------------------------------------------
  1900. #pragma mark ==== ReMenu ====
  1901. #pragma --------------------------------------------------------------------------------------------
  1902. - (void)createReMenuBackgroundView:(REMenu *)menu
  1903. {
  1904. CGFloat safeAreaBottom = 0;
  1905. CGFloat safeAreaTop = 0;
  1906. CGFloat statusBar = 0;
  1907. if (@available(iOS 11, *)) {
  1908. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  1909. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  1910. }
  1911. if ([UIApplication sharedApplication].isStatusBarHidden) {
  1912. statusBar = 13;
  1913. }
  1914. CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
  1915. UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
  1916. CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
  1917. _reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
  1918. [UIView animateWithDuration:0.2 animations:^{
  1919. CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
  1920. CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
  1921. if (y>minimum) {
  1922. _reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
  1923. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  1924. }
  1925. }];
  1926. }
  1927. - (void)createReMainMenu
  1928. {
  1929. NSString *title;
  1930. NSString *groupBy = [CCUtility getGroupBySettings];
  1931. NSString *sorted = [CCUtility getOrderSettings];
  1932. BOOL ascending = [CCUtility getAscendingSettings];
  1933. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  1934. 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) {
  1935. if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
  1936. }];
  1937. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  1938. if ([sorted isEqualToString:@"fileName"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_a_z_", nil)]; }
  1939. else title = NSLocalizedString(@"_order_by_name_a_z_", nil);
  1940. appDelegate.sortFileNameAZItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameAZ"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1941. [CCUtility setOrderSettings:@"fileName"];
  1942. [CCUtility setAscendingSettings:true];
  1943. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1944. }];
  1945. if ([sorted isEqualToString:@"fileName"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_z_a_", nil)]; }
  1946. else title = NSLocalizedString(@"_order_by_name_z_a_", nil);
  1947. appDelegate.sortFileNameZAItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameZA"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1948. [CCUtility setOrderSettings:@"fileName"];
  1949. [CCUtility setAscendingSettings:false];
  1950. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1951. }];
  1952. if ([sorted isEqualToString:@"date"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_more_recent_", nil)]; }
  1953. else title = NSLocalizedString(@"_order_by_date_more_recent_", nil);
  1954. appDelegate.sortDateMoreRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateMoreRecent"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1955. [CCUtility setOrderSettings:@"date"];
  1956. [CCUtility setAscendingSettings:false];
  1957. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1958. }];
  1959. if ([sorted isEqualToString:@"date"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_less_recent_", nil)]; }
  1960. else title = NSLocalizedString(@"_order_by_date_less_recent_", nil);
  1961. appDelegate.sortDateLessRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateLessRecent"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1962. [CCUtility setOrderSettings:@"date"];
  1963. [CCUtility setAscendingSettings:true];
  1964. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1965. }];
  1966. if ([sorted isEqualToString:@"size"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_smallest_", nil)]; }
  1967. else title = NSLocalizedString(@"_order_by_size_smallest_", nil);
  1968. appDelegate.sortSmallestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortSmallest"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1969. [CCUtility setOrderSettings:@"size"];
  1970. [CCUtility setAscendingSettings:true];
  1971. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1972. }];
  1973. if ([sorted isEqualToString:@"size"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_largest_", nil)]; }
  1974. else title = NSLocalizedString(@"_order_by_size_largest_", nil);
  1975. appDelegate.sortLargestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortLargest"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1976. [CCUtility setOrderSettings:@"size"];
  1977. [CCUtility setAscendingSettings:false];
  1978. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1979. }];
  1980. // ITEM GROUP ALPHABETIC -----------------------------------------------------------------------------------------------------
  1981. if ([groupBy isEqualToString:@"alphabetic"]) { title = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  1982. else { title = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  1983. appDelegate.alphabeticItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1984. if ([groupBy isEqualToString:@"alphabetic"]) [CCUtility setGroupBySettings:@"none"];
  1985. else [CCUtility setGroupBySettings:@"alphabetic"];
  1986. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1987. }];
  1988. // ITEM GROUP TYPEFILE -------------------------------------------------------------------------------------------------------
  1989. if ([groupBy isEqualToString:@"typefile"]) { title = NSLocalizedString(@"_group_typefile_yes_", nil); }
  1990. else { title = NSLocalizedString(@"_group_typefile_no_", nil); }
  1991. appDelegate.typefileItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file"] multiplier:1 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  1992. if ([groupBy isEqualToString:@"typefile"]) [CCUtility setGroupBySettings:@"none"];
  1993. else [CCUtility setGroupBySettings:@"typefile"];
  1994. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1995. }];
  1996. // ITEM GROUP DATE -------------------------------------------------------------------------------------------------------
  1997. if ([groupBy isEqualToString:@"date"]) { title = NSLocalizedString(@"_group_date_yes_", nil); }
  1998. else { title = NSLocalizedString(@"_group_date_no_", nil); }
  1999. appDelegate.dateItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] multiplier:2 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  2000. if ([groupBy isEqualToString:@"date"]) [CCUtility setGroupBySettings:@"none"];
  2001. else [CCUtility setGroupBySettings:@"date"];
  2002. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2003. }];
  2004. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2005. if ([CCUtility getDirectoryOnTop]) { title = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2006. else { title = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2007. appDelegate.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:1 color:[NCBrandColor sharedInstance].icon] highlightedImage:nil action:^(REMenuItem *item) {
  2008. if ([CCUtility getDirectoryOnTop]) [CCUtility setDirectoryOnTop:NO];
  2009. else [CCUtility setDirectoryOnTop:YES];
  2010. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2011. }];
  2012. // REMENU --------------------------------------------------------------------------------------------------------------
  2013. 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]];
  2014. appDelegate.reMainMenu.itemHeight = 40;
  2015. appDelegate.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2016. appDelegate.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2017. appDelegate.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2018. appDelegate.reMainMenu.waitUntilAnimationIsComplete = NO;
  2019. appDelegate.reMainMenu.separatorHeight = 0.5;
  2020. appDelegate.reMainMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
  2021. appDelegate.reMainMenu.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  2022. appDelegate.reMainMenu.textColor = [UIColor blackColor];
  2023. appDelegate.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2024. appDelegate.reMainMenu.textShadowColor = nil;
  2025. appDelegate.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2026. appDelegate.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2027. appDelegate.reMainMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  2028. appDelegate.reMainMenu.highlightedSeparatorColor = nil;
  2029. appDelegate.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2030. appDelegate.reMainMenu.highlightedTextShadowColor = nil;
  2031. appDelegate.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2032. appDelegate.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2033. appDelegate.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2034. appDelegate.reMainMenu.subtitleTextShadowColor = nil;
  2035. appDelegate.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2036. appDelegate.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2037. appDelegate.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2038. appDelegate.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2039. appDelegate.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2040. appDelegate.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2041. appDelegate.reMainMenu.borderWidth = 0.3;
  2042. appDelegate.reMainMenu.borderColor = [UIColor lightGrayColor];
  2043. appDelegate.reMainMenu.animationDuration = 0.2;
  2044. appDelegate.reMainMenu.closeAnimationDuration = 0.2;
  2045. appDelegate.reMainMenu.bounce = NO;
  2046. __weak typeof(self) weakSelf = self;
  2047. [appDelegate.reMainMenu setClosePreparationBlock:^{
  2048. // Backgroun reMenu (Gesture)
  2049. [weakSelf.reMenuBackgroundView removeFromSuperview];
  2050. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  2051. }];
  2052. }
  2053. - (void)toggleReMainMenu
  2054. {
  2055. if (appDelegate.reMainMenu.isOpen) {
  2056. [appDelegate.reMainMenu close];
  2057. } else {
  2058. [self createReMainMenu];
  2059. [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
  2060. // Backgroun reMenu & (Gesture)
  2061. [self createReMenuBackgroundView:appDelegate.reMainMenu];
  2062. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2063. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2064. }
  2065. }
  2066. - (void)createReSelectMenu
  2067. {
  2068. // ITEM SELECT ALL --------------------------------------------------------------------------------------------------
  2069. 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) {
  2070. [self didSelectAll];
  2071. }];
  2072. // ITEM MOVE --------------------------------------------------------------------------------------------------------
  2073. 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) {
  2074. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2075. }];
  2076. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2077. 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) {
  2078. [self downloadSelectedFilesFolders];
  2079. }];
  2080. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2081. 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) {
  2082. [self saveSelectedFiles];
  2083. }];
  2084. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2085. 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) {
  2086. [self deleteFile];
  2087. }];
  2088. // E2EE
  2089. if (_metadataFolder.e2eEncrypted) {
  2090. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  2091. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  2092. } else {
  2093. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  2094. }
  2095. } else {
  2096. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  2097. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  2098. } else {
  2099. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  2100. }
  2101. }
  2102. appDelegate.reSelectMenu.itemHeight = 50;
  2103. appDelegate.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2104. appDelegate.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2105. appDelegate.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2106. appDelegate.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2107. appDelegate.reSelectMenu.separatorHeight = 0.5;
  2108. appDelegate.reSelectMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
  2109. appDelegate.reSelectMenu.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  2110. appDelegate.reSelectMenu.textColor = [UIColor blackColor];
  2111. appDelegate.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2112. appDelegate.reSelectMenu.textShadowColor = nil;
  2113. appDelegate.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2114. appDelegate.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2115. appDelegate.reSelectMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  2116. appDelegate.reSelectMenu.highlightedSeparatorColor = nil;
  2117. appDelegate.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2118. appDelegate.reSelectMenu.highlightedTextShadowColor = nil;
  2119. appDelegate.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2120. appDelegate.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2121. appDelegate.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2122. appDelegate.reSelectMenu.subtitleTextShadowColor = nil;
  2123. appDelegate.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2124. appDelegate.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2125. appDelegate.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2126. appDelegate.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2127. appDelegate.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2128. appDelegate.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2129. appDelegate.reSelectMenu.borderWidth = 0.3;
  2130. appDelegate.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2131. appDelegate.reSelectMenu.closeAnimationDuration = 0.2;
  2132. appDelegate.reSelectMenu.animationDuration = 0.2;
  2133. appDelegate.reSelectMenu.bounce = NO;
  2134. __weak typeof(self) weakSelf = self;
  2135. [appDelegate.reSelectMenu setClosePreparationBlock:^{
  2136. // Backgroun reMenu (Gesture)
  2137. [weakSelf.reMenuBackgroundView removeFromSuperview];
  2138. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  2139. }];
  2140. }
  2141. - (void)toggleReSelectMenu
  2142. {
  2143. if (appDelegate.reSelectMenu.isOpen) {
  2144. [appDelegate.reSelectMenu close];
  2145. } else {
  2146. [self createReSelectMenu];
  2147. [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
  2148. // Backgroun reMenu & (Gesture)
  2149. [self createReMenuBackgroundView:appDelegate.reSelectMenu];
  2150. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2151. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2152. }
  2153. }
  2154. #pragma --------------------------------------------------------------------------------------------
  2155. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2156. #pragma --------------------------------------------------------------------------------------------
  2157. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2158. {
  2159. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2160. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  2161. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  2162. if ([self indexPathIsValid:indexPath])
  2163. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2164. else
  2165. self.metadata = nil;
  2166. [self becomeFirstResponder];
  2167. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2168. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2169. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2170. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2171. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2172. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2173. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  2174. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, pasteFileItem, pasteFilesItem, nil]];
  2175. } else {
  2176. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  2177. }
  2178. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  2179. [menuController setMenuVisible:YES animated:YES];
  2180. }
  2181. }
  2182. - (BOOL)canBecomeFirstResponder
  2183. {
  2184. return YES;
  2185. }
  2186. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2187. {
  2188. // For copy file, copy files, Open in ... :
  2189. //
  2190. // NO Directory
  2191. // NO Error Passcode
  2192. // NO In Session mode (download/upload)
  2193. // NO Template
  2194. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2195. if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
  2196. else return NO;
  2197. }
  2198. if (@selector(copyFiles:) == action) {
  2199. if (_isSelectedMode) {
  2200. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2201. for (tableMetadata *metadata in selectedMetadatas) {
  2202. if (!metadata.directory && metadata.status == k_metadataStatusNormal)
  2203. return YES;
  2204. }
  2205. }
  2206. return NO;
  2207. }
  2208. if (@selector(pasteFile:) == action) {
  2209. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2210. NSArray *items = [pasteboard items];
  2211. if ([items count] == 1) {
  2212. // Value : (NSData) fileID
  2213. NSDictionary *dic = [items objectAtIndex:0];
  2214. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2215. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2216. if (fileID) {
  2217. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  2218. if (metadata) {
  2219. return [CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView];
  2220. } else {
  2221. return NO;
  2222. }
  2223. }
  2224. }
  2225. return NO;
  2226. }
  2227. if (@selector(pasteFiles:) == action) {
  2228. BOOL isValid = NO;
  2229. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2230. NSArray *items = [pasteboard items];
  2231. if ([items count] <= 1) return NO;
  2232. for (NSDictionary *dic in items) {
  2233. // Value : (NSData) fileID
  2234. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2235. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2236. if (fileID) {
  2237. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  2238. if (metadata) {
  2239. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  2240. isValid = YES;
  2241. } else {
  2242. isValid = NO;
  2243. break;
  2244. }
  2245. } else {
  2246. isValid = NO;
  2247. break;
  2248. }
  2249. } else {
  2250. isValid = NO;
  2251. break;
  2252. }
  2253. }
  2254. return isValid;
  2255. }
  2256. return NO;
  2257. }
  2258. /************************************ COPY ************************************/
  2259. - (void)copyFile:(id)sender
  2260. {
  2261. // Remove all item
  2262. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2263. pasteboard.items = [[NSArray alloc] init];
  2264. if ([CCUtility fileProviderStorageExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
  2265. [self copyFileToPasteboard:self.metadata];
  2266. } else {
  2267. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  2268. if (serverUrl) {
  2269. self.metadata.session = k_download_session;
  2270. self.metadata.sessionError = @"";
  2271. self.metadata.sessionSelector = selectorLoadCopy;
  2272. self.metadata.status = k_metadataStatusWaitDownload;
  2273. // Add Metadata for Download
  2274. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2275. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  2276. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  2277. }
  2278. }
  2279. }
  2280. - (void)copyFiles:(id)sender
  2281. {
  2282. // Remove all item
  2283. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2284. pasteboard.items = [[NSArray alloc] init];
  2285. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2286. for (tableMetadata *metadata in selectedMetadatas) {
  2287. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  2288. [self copyFileToPasteboard:metadata];
  2289. } else {
  2290. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  2291. if (serverUrl) {
  2292. metadata.session = k_download_session;
  2293. metadata.sessionError = @"";
  2294. metadata.sessionSelector = selectorLoadCopy;
  2295. metadata.status = k_metadataStatusWaitDownload;
  2296. // Add Metadata for Download
  2297. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  2298. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  2299. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:metadata.fileID action:k_action_MOD];
  2300. }
  2301. }
  2302. }
  2303. [self tableViewSelect:NO];
  2304. }
  2305. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  2306. {
  2307. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2308. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2309. // Value : (NSData) fileID
  2310. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.fileID], k_metadataKeyedUnarchiver,nil];
  2311. [items addObject:item];
  2312. [pasteboard setItems:items];
  2313. }
  2314. /************************************ OPEN IN ... ******************************/
  2315. - (void)openinFile:(id)sender
  2316. {
  2317. [self DownloadOpenIn:self.metadata];
  2318. }
  2319. /************************************ PASTE ************************************/
  2320. - (void)pasteFile:(id)sender
  2321. {
  2322. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2323. [self uploadFilePasteArray:[pasteboard items]];
  2324. }
  2325. - (void)pasteFiles:(id)sender
  2326. {
  2327. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2328. [self uploadFilePasteArray:[pasteboard items]];
  2329. }
  2330. - (void)uploadFilePasteArray:(NSArray *)items
  2331. {
  2332. for (NSDictionary *dic in items) {
  2333. // Value : (NSData) fileID
  2334. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2335. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2336. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
  2337. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  2338. if (metadata) {
  2339. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  2340. NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView directoryID:directoryID];
  2341. NSString *fileID = [directoryID stringByAppendingString:fileName];
  2342. [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageFileID:fileID fileNameView:fileName]];
  2343. tableMetadata *metadataForUpload = [tableMetadata new];
  2344. metadataForUpload.account = appDelegate.activeAccount;
  2345. metadataForUpload.date = [NSDate new];
  2346. metadataForUpload.directoryID = directoryID;
  2347. metadataForUpload.fileID = fileID;
  2348. metadataForUpload.fileName = fileName;
  2349. metadataForUpload.fileNameView = fileName;
  2350. metadataForUpload.session = k_upload_session;
  2351. metadataForUpload.sessionSelector = selectorUploadFile;
  2352. metadataForUpload.size = metadata.size;
  2353. metadataForUpload.status = k_metadataStatusWaitUpload;
  2354. // Add Medtadata for upload
  2355. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  2356. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  2357. }
  2358. }
  2359. }
  2360. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  2361. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  2362. }
  2363. #pragma --------------------------------------------------------------------------------------------
  2364. #pragma mark ===== Lock Passcode =====
  2365. #pragma --------------------------------------------------------------------------------------------
  2366. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2367. {
  2368. return _failedAttempts;
  2369. }
  2370. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2371. {
  2372. return _lockUntilDate;
  2373. }
  2374. - (void)passcodeViewCloseButtonPressed:(id)sender
  2375. {
  2376. [self dismissViewControllerAnimated:YES completion:nil];
  2377. }
  2378. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2379. {
  2380. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2381. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2382. _lockUntilDate = nil;
  2383. _failedAttempts = 0;
  2384. aResultHandler(YES);
  2385. } else aResultHandler(NO);
  2386. } else aResultHandler(YES);
  2387. }
  2388. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2389. {
  2390. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2391. switch (aViewController.type) {
  2392. case BKPasscodeViewControllerCheckPasscodeType: {
  2393. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2394. // possiamo procedere alla prossima directory
  2395. [self performSegueDirectoryWithControlPasscode:false];
  2396. // avviamo la sessione Passcode Lock con now
  2397. appDelegate.sessionePasscodeLock = [NSDate date];
  2398. }
  2399. // disattivazione lock cartella
  2400. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2401. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  2402. if (!serverUrl)
  2403. return;
  2404. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
  2405. if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO]) {
  2406. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2407. }
  2408. [self tableViewReloadData];
  2409. }
  2410. }
  2411. break;
  2412. default:
  2413. break;
  2414. }
  2415. }
  2416. - (void)comandoLockPassword
  2417. {
  2418. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  2419. if (!serverUrl) return;
  2420. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
  2421. // se non è abilitato il Lock Passcode esci
  2422. if ([[CCUtility getBlockCode] length] == 0) {
  2423. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) preferredStyle:UIAlertControllerStyleAlert];
  2424. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  2425. [alertController addAction:okAction];
  2426. [self presentViewController:alertController animated:YES completion:nil];
  2427. return;
  2428. }
  2429. // se è richiesta la disattivazione si chiede la password
  2430. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2431. if (directory.lock) {
  2432. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2433. viewController.delegate = self;
  2434. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2435. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2436. viewController.inputViewTitlePassword = YES;
  2437. if ([CCUtility getSimplyBlockCode]) {
  2438. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2439. viewController.passcodeInputView.maximumLength = 6;
  2440. } else {
  2441. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2442. viewController.passcodeInputView.maximumLength = 64;
  2443. }
  2444. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  2445. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2446. viewController.touchIDManager = touchIDManager;
  2447. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2448. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2449. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  2450. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2451. [self presentViewController:navigationController animated:YES completion:nil];
  2452. return;
  2453. }
  2454. // ---------------- ACTIVATE PASSWORD
  2455. if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES]) {
  2456. NSIndexPath *indexPath = [sectionDataSource.fileIDIndexPath objectForKey:self.metadata.fileID];
  2457. if ([self indexPathIsValid:indexPath])
  2458. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2459. } else {
  2460. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2461. }
  2462. }
  2463. #pragma mark -
  2464. #pragma --------------------------------------------------------------------------------------------
  2465. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  2466. #pragma --------------------------------------------------------------------------------------------
  2467. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  2468. {
  2469. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  2470. return NO;
  2471. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  2472. return NO;
  2473. // E2EE
  2474. if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
  2475. return NO;
  2476. return YES;
  2477. }
  2478. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  2479. {
  2480. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2481. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2482. return [self canOpenMenuAction:metadata];
  2483. }
  2484. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  2485. {
  2486. }
  2487. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  2488. {
  2489. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2490. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2491. if (direction == MGSwipeDirectionRightToLeft) {
  2492. [self actionDelete:indexPath];
  2493. }
  2494. if (direction == MGSwipeDirectionLeftToRight) {
  2495. if (self.metadata.favorite)
  2496. [self settingFavorite:self.metadata favorite:NO];
  2497. else
  2498. [self settingFavorite:self.metadata favorite:YES];
  2499. }
  2500. return YES;
  2501. }
  2502. - (void)actionDelete:(NSIndexPath *)indexPath
  2503. {
  2504. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2505. // Directory locked ?
  2506. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] addFileName:metadata.fileName];
  2507. if (!lockServerUrl) return;
  2508. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2509. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
  2510. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) {
  2511. [appDelegate messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2512. return;
  2513. }
  2514. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  2515. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2516. [self performSelector:@selector(deleteFile) withObject:nil];
  2517. }]];
  2518. if (localFile) {
  2519. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2520. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
  2521. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
  2522. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  2523. }]];
  2524. }
  2525. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2526. }]];
  2527. alertController.popoverPresentationController.sourceView = self.tableView;
  2528. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  2529. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2530. [alertController.view layoutIfNeeded];
  2531. [self presentViewController:alertController animated:YES completion:nil];
  2532. }
  2533. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  2534. {
  2535. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  2536. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  2537. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2538. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  2539. if (!serverUrl) return;
  2540. NSString *titoloLock, *titleFavorite;
  2541. if (self.metadata.favorite) {
  2542. titleFavorite = NSLocalizedString(@"_remove_favorites_", nil);
  2543. } else {
  2544. titleFavorite = NSLocalizedString(@"_add_favorites_", nil);
  2545. }
  2546. if (self.metadata.directory) {
  2547. // calcolo lockServerUrl
  2548. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
  2549. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2550. if (directory.lock)
  2551. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  2552. else
  2553. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  2554. }
  2555. // ******************************************* AHKActionSheet *******************************************
  2556. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
  2557. actionSheet.animationDuration = 0.2;
  2558. actionSheet.buttonHeight = 50.0;
  2559. actionSheet.cancelButtonHeight = 50.0f;
  2560. actionSheet.separatorHeight = 5.0f;
  2561. actionSheet.automaticallyTintButtonImages = @(NO);
  2562. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].encrypted };
  2563. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
  2564. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName:[UIColor blackColor] };
  2565. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
  2566. actionSheet.separatorColor = [NCBrandColor sharedInstance].seperator;
  2567. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  2568. // ******************************************* DIRECTORY *******************************************
  2569. if (self.metadata.directory) {
  2570. BOOL lockDirectory = NO;
  2571. BOOL optionOnDevice = NO;
  2572. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
  2573. NSString *firstServerUrl = [CCUtility firtsPathComponentFromServerUrl:dirServerUrl activeUrl:appDelegate.activeUrl];
  2574. BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] account:appDelegate.activeAccount];
  2575. // Directory bloccata ?
  2576. tableDirectory *directoryForLock = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl]];
  2577. if (directoryForLock.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) lockDirectory = YES;
  2578. // Directory set as offline ?
  2579. tableDirectory *directoryOnDevice = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl CONTAINS %@ AND onDevice == true", appDelegate.activeAccount, firstServerUrl]];
  2580. if (directoryOnDevice == nil) {
  2581. optionOnDevice = YES;
  2582. } else if (directoryOnDevice.serverUrl.length == dirServerUrl.length) {
  2583. optionOnDevice = YES;
  2584. } else if (directoryOnDevice.serverUrl.length > dirServerUrl.length) {
  2585. optionOnDevice = YES;
  2586. }
  2587. [actionSheet addButtonWithTitle:self.metadata.fileNameView
  2588. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement]
  2589. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2590. height:50.0
  2591. type:AHKActionSheetButtonTypeDisabled
  2592. handler:nil
  2593. ];
  2594. [actionSheet addButtonWithTitle: titleFavorite
  2595. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:[NCBrandColor sharedInstance].yellowFavorite]
  2596. backgroundColor: [NCBrandColor sharedInstance].backgroundView
  2597. height: 50.0
  2598. type: AHKActionSheetButtonTypeDefault
  2599. handler: ^(AHKActionSheet *as) {
  2600. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2601. else [self settingFavorite:self.metadata favorite:YES];
  2602. }];
  2603. if (!lockDirectory && !isFolderEncrypted) {
  2604. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  2605. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2606. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2607. height:50.0
  2608. type:AHKActionSheetButtonTypeDefault
  2609. handler:^(AHKActionSheet *as) {
  2610. [self openWindowShare:self.metadata];
  2611. }];
  2612. }
  2613. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !self.metadata.e2eEncrypted) {
  2614. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2615. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2616. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2617. height:50.0
  2618. type:AHKActionSheetButtonTypeDefault
  2619. handler:^(AHKActionSheet *as) {
  2620. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2621. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2622. textField.text = self.metadata.fileNameView;
  2623. //textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
  2624. //textField.delegate = self;
  2625. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2626. }];
  2627. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2628. NSLog(@"[LOG] Cancel action");
  2629. }];
  2630. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2631. UITextField *fileName = alertController.textFields.firstObject;
  2632. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2633. }];
  2634. okAction.enabled = NO;
  2635. [alertController addAction:cancelAction];
  2636. [alertController addAction:okAction];
  2637. [self presentViewController:alertController animated:YES completion:nil];
  2638. }];
  2639. }
  2640. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !isFolderEncrypted) {
  2641. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2642. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2643. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2644. height:50.0
  2645. type:AHKActionSheetButtonTypeDefault
  2646. handler:^(AHKActionSheet *as) {
  2647. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2648. }];
  2649. }
  2650. if (!lockDirectory && !isFolderEncrypted && optionOnDevice) {
  2651. NSString *title;
  2652. if (directoryOnDevice == nil) {
  2653. title = NSLocalizedString(@"_set_available_offline_", nil);
  2654. } else if (directoryOnDevice.serverUrl.length == dirServerUrl.length) {
  2655. title = NSLocalizedString(@"_remove_available_offline_", nil);
  2656. } else if (directoryOnDevice.serverUrl.length > dirServerUrl.length) {
  2657. title = NSLocalizedString(@"_set_available_offline_", nil);
  2658. }
  2659. [actionSheet addButtonWithTitle:title
  2660. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"onDevice"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2661. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2662. height:50.0
  2663. type:AHKActionSheetButtonTypeDefault
  2664. handler:^(AHKActionSheet *as) {
  2665. if (directoryOnDevice == nil) {
  2666. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl onDevice:true];
  2667. } else if (directoryOnDevice.serverUrl.length == dirServerUrl.length) {
  2668. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl onDevice:false];
  2669. } else if (directoryOnDevice.serverUrl.length > dirServerUrl.length) {
  2670. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:directoryOnDevice.serverUrl onDevice:false];
  2671. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl onDevice:true];
  2672. }
  2673. }];
  2674. }
  2675. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [serverUrl isEqualToString:_autoUploadDirectory] == YES)) {
  2676. [actionSheet addButtonWithTitle:titoloLock
  2677. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2678. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2679. height:50.0
  2680. type:AHKActionSheetButtonTypeDefault
  2681. handler:^(AHKActionSheet *as) {
  2682. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  2683. }];
  2684. }
  2685. if (!self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2686. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_set_folder_encrypted_", nil)
  2687. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2688. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2689. height:50.0
  2690. type:AHKActionSheetButtonTypeDefault
  2691. handler:^(AHKActionSheet *as) {
  2692. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  2693. 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];
  2694. dispatch_async(dispatch_get_main_queue(), ^{
  2695. if (error) {
  2696. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2697. } else {
  2698. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2699. [self readFolder:self.serverUrl];
  2700. }
  2701. });
  2702. });
  2703. }];
  2704. }
  2705. if (self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2706. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_remove_folder_encrypted_", nil)
  2707. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2708. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2709. height:50.0
  2710. type:AHKActionSheetButtonTypeDefault
  2711. handler:^(AHKActionSheet *as) {
  2712. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2713. 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];
  2714. dispatch_async(dispatch_get_main_queue(), ^{
  2715. if (error) {
  2716. [appDelegate messageNotification:@"_e2e_error_delete_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2717. } else {
  2718. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2719. [self readFolder:self.serverUrl];
  2720. }
  2721. });
  2722. });
  2723. }];
  2724. }
  2725. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2726. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor redColor]]
  2727. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2728. height:50.0
  2729. type:AHKActionSheetButtonTypeDestructive
  2730. handler:^(AHKActionSheet *as) {
  2731. [self actionDelete:indexPath];
  2732. }];
  2733. [actionSheet show];
  2734. }
  2735. // ******************************************* FILE *******************************************
  2736. if (!self.metadata.directory) {
  2737. UIImage *iconHeader;
  2738. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  2739. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]])
  2740. iconHeader = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
  2741. else
  2742. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  2743. [actionSheet addButtonWithTitle: self.metadata.fileNameView
  2744. image: iconHeader
  2745. backgroundColor: [NCBrandColor sharedInstance].backgroundView
  2746. height: 50.0
  2747. type: AHKActionSheetButtonTypeDisabled
  2748. handler: nil
  2749. ];
  2750. [actionSheet addButtonWithTitle: titleFavorite
  2751. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:[NCBrandColor sharedInstance].yellowFavorite]
  2752. backgroundColor: [NCBrandColor sharedInstance].backgroundView
  2753. height: 50.0
  2754. type: AHKActionSheetButtonTypeDefault
  2755. handler: ^(AHKActionSheet *as) {
  2756. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2757. else [self settingFavorite:self.metadata favorite:YES];
  2758. }];
  2759. if (!_metadataFolder.e2eEncrypted) {
  2760. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  2761. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2762. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2763. height: 50.0
  2764. type:AHKActionSheetButtonTypeDefault
  2765. handler:^(AHKActionSheet *as) {
  2766. [self openWindowShare:self.metadata];
  2767. }];
  2768. }
  2769. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  2770. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  2771. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2772. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2773. height: 50.0
  2774. type:AHKActionSheetButtonTypeDefault
  2775. handler:^(AHKActionSheet *as) {
  2776. [self performSelector:@selector(DownloadOpenIn:) withObject:self.metadata];
  2777. }];
  2778. }
  2779. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2780. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2781. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2782. height: 50.0
  2783. type:AHKActionSheetButtonTypeDefault
  2784. handler:^(AHKActionSheet *as) {
  2785. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2786. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2787. textField.text = self.metadata.fileNameView;
  2788. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2789. }];
  2790. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2791. NSLog(@"[LOG] Cancel action");
  2792. }];
  2793. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2794. UITextField *fileName = alertController.textFields.firstObject;
  2795. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2796. }];
  2797. okAction.enabled = NO;
  2798. [alertController addAction:cancelAction];
  2799. [alertController addAction:okAction];
  2800. [self presentViewController:alertController animated:YES completion:nil];
  2801. }];
  2802. if (!_metadataFolder.e2eEncrypted) {
  2803. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2804. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2805. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2806. height:50.0
  2807. type:AHKActionSheetButtonTypeDefault
  2808. handler:^(AHKActionSheet *as) {
  2809. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2810. }];
  2811. }
  2812. if (!_metadataFolder.e2eEncrypted) {
  2813. NSString *title;
  2814. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", self.metadata.fileID]];
  2815. if (localFile == nil || localFile.onDevice == false) { title = NSLocalizedString(@"_set_available_offline_", nil); }
  2816. else { title = NSLocalizedString(@"_remove_available_offline_", nil); }
  2817. [actionSheet addButtonWithTitle:title
  2818. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"onDevice"] multiplier:2 color:[NCBrandColor sharedInstance].icon]
  2819. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2820. height:50.0
  2821. type:AHKActionSheetButtonTypeDefault
  2822. handler:^(AHKActionSheet *as) {
  2823. if (localFile == nil) {
  2824. self.metadata.session = k_download_session;
  2825. self.metadata.sessionError = @"";
  2826. self.metadata.sessionSelector = selectorLoadOnDevice;
  2827. self.metadata.status = k_metadataStatusWaitDownload;
  2828. // Add Metadata for Download
  2829. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2830. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  2831. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  2832. } else if (localFile.onDevice == false) {
  2833. [[NCManageDatabase sharedInstance] setLocalFileWithFileID:self.metadata.fileID onDevice:true];
  2834. } else {
  2835. [[NCManageDatabase sharedInstance] setLocalFileWithFileID:self.metadata.fileID onDevice:false];
  2836. }
  2837. }];
  2838. }
  2839. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2840. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor redColor]]
  2841. backgroundColor:[NCBrandColor sharedInstance].backgroundView
  2842. height:50.0
  2843. type:AHKActionSheetButtonTypeDestructive
  2844. handler:^(AHKActionSheet *as) {
  2845. [self actionDelete:indexPath];
  2846. }];
  2847. [actionSheet show];
  2848. }
  2849. }
  2850. #pragma --------------------------------------------------------------------------------------------
  2851. #pragma mark - ==== Datasource ====
  2852. #pragma --------------------------------------------------------------------------------------------
  2853. - (void)clearDateReadDataSource:(NSNotification *)notification
  2854. {
  2855. _dateReadDataSource = Nil;
  2856. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
  2857. }
  2858. - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID action:(NSInteger)action
  2859. {
  2860. // test
  2861. if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
  2862. return;
  2863. // Search Mode
  2864. if (_isSearchMode) {
  2865. // Create metadatas
  2866. NSMutableArray *metadatas = [NSMutableArray new];
  2867. for (tableMetadata *resultMetadata in _searchResultMetadatas) {
  2868. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", resultMetadata.fileID]];
  2869. if (metadata) {
  2870. [metadatas addObject:metadata];
  2871. }
  2872. }
  2873. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
  2874. [self tableViewReloadData];
  2875. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  2876. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  2877. _noFilesSearchDescription = @"";
  2878. }
  2879. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  2880. _noFilesSearchTitle = @"";
  2881. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  2882. }
  2883. [self.tableView reloadEmptyDataSet];
  2884. return;
  2885. }
  2886. // Se non siamo nella dir appropriata esci
  2887. if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
  2888. return;
  2889. }
  2890. // Remove optimization for encrypted directory
  2891. if (_metadataFolder.e2eEncrypted)
  2892. _dateReadDataSource = nil;
  2893. // Controllo data lettura Data Source
  2894. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  2895. // Get MetadataFolder
  2896. if (![serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
  2897. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", tableDirectory.fileID]];
  2898. NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
  2899. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  2900. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  2901. _dateReadDataSource = [NSDate date];
  2902. // Data Source
  2903. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2904. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
  2905. dispatch_async(dispatch_get_main_queue(), ^{
  2906. sectionDataSource = sectionDataSourceTemp;
  2907. [self tableViewReloadData];
  2908. });
  2909. });
  2910. } else {
  2911. [self tableViewReloadData];
  2912. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  2913. }
  2914. }
  2915. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
  2916. {
  2917. // test
  2918. if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
  2919. return nil;
  2920. }
  2921. // current directoryID
  2922. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
  2923. if (directoryID == nil) {
  2924. return nil;
  2925. }
  2926. // get auto upload folder
  2927. _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  2928. _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
  2929. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  2930. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND status != %i", directoryID, k_metadataStatusHide] sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  2931. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
  2932. if (withReloadData) {
  2933. sectionDataSource = sectionDataSourceTemp;
  2934. [self tableViewReloadData];
  2935. }
  2936. return sectionDataSourceTemp;
  2937. }
  2938. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  2939. {
  2940. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  2941. if (selectedRows.count > 0) {
  2942. for (NSIndexPath *selectionIndex in selectedRows) {
  2943. NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  2944. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  2945. [metadatas addObject:metadata];
  2946. }
  2947. }
  2948. return metadatas;
  2949. }
  2950. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  2951. {
  2952. NSInteger totSections =[sectionDataSource.sections count] ;
  2953. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  2954. return nil;
  2955. }
  2956. id valueSection = [sectionDataSource.sections objectAtIndex:section];
  2957. return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
  2958. }
  2959. #pragma --------------------------------------------------------------------------------------------
  2960. #pragma mark - ==== Table ====
  2961. #pragma --------------------------------------------------------------------------------------------
  2962. - (void)tableViewSelect:(BOOL)edit
  2963. {
  2964. // chiudiamo eventuali swipe aperti
  2965. if (edit)
  2966. [self.tableView setEditing:NO animated:NO];
  2967. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  2968. [self.tableView setEditing:edit animated:YES];
  2969. _isSelectedMode = edit;
  2970. if (edit)
  2971. [self setUINavigationBarSelected];
  2972. else
  2973. [self setUINavigationBarDefault];
  2974. [_selectedFileIDsMetadatas removeAllObjects];
  2975. [self setTitle];
  2976. }
  2977. - (void)tableViewReloadData
  2978. {
  2979. // store selected cells before relod
  2980. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  2981. // reload table view
  2982. [self.tableView reloadData];
  2983. // selected cells stored
  2984. for (NSIndexPath *path in indexPaths)
  2985. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  2986. [self setTableViewFooter];
  2987. if (self.tableView.editing)
  2988. [self setTitle];
  2989. //
  2990. [self.tableView reloadEmptyDataSet];
  2991. }
  2992. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  2993. {
  2994. if (tableView.editing == 1) {
  2995. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2996. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  2997. return NO;
  2998. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  2999. return NO;
  3000. else
  3001. return YES;
  3002. } else {
  3003. [_selectedFileIDsMetadatas removeAllObjects];
  3004. }
  3005. return YES;
  3006. }
  3007. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3008. {
  3009. return 60;
  3010. }
  3011. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3012. {
  3013. return [[sectionDataSource.sectionArrayRow allKeys] count];
  3014. }
  3015. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3016. {
  3017. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  3018. }
  3019. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3020. {
  3021. NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
  3022. NSString *sectionTitle = [sections objectAtIndex:section];
  3023. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3024. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3025. if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  3026. return 20.f;
  3027. }
  3028. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3029. {
  3030. float shift;
  3031. UIVisualEffectView *visualEffectView;
  3032. NSString *titleSection;
  3033. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  3034. return nil;
  3035. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  3036. titleSection = [sectionDataSource.sections objectAtIndex:section];
  3037. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  3038. titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  3039. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3040. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3041. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3042. else titleSection = NSLocalizedString(titleSection,nil);
  3043. // Format title
  3044. NSString *currentDevice = [CCUtility currentDevice];
  3045. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3046. visualEffectView = [[UIVisualEffectView alloc] init];
  3047. visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.3];
  3048. } else {
  3049. UIVisualEffect *blurEffect;
  3050. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3051. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3052. visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.2];
  3053. }
  3054. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
  3055. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3056. shift = - 35;
  3057. else
  3058. shift = - 20;
  3059. } else shift = - 10;
  3060. // Title
  3061. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3062. titleLabel.backgroundColor = [UIColor clearColor];
  3063. titleLabel.textColor = [UIColor blackColor];
  3064. titleLabel.font = [UIFont systemFontOfSize:12];
  3065. titleLabel.textAlignment = NSTextAlignmentLeft;
  3066. titleLabel.text = titleSection;
  3067. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3068. [visualEffectView.contentView addSubview:titleLabel];
  3069. // Elements
  3070. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3071. elementLabel.backgroundColor = [UIColor clearColor];
  3072. elementLabel.textColor = [UIColor blackColor];;
  3073. elementLabel.font = [UIFont systemFontOfSize:12];
  3074. elementLabel.textAlignment = NSTextAlignmentRight;
  3075. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3076. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3077. NSUInteger rowsCount = [metadatas count];
  3078. if (rowsCount == 0) return nil;
  3079. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3080. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3081. [visualEffectView.contentView addSubview:elementLabel];
  3082. return visualEffectView;
  3083. }
  3084. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3085. {
  3086. return [sectionDataSource.sections indexOfObject:title];
  3087. }
  3088. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3089. {
  3090. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
  3091. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3092. else
  3093. return nil;
  3094. }
  3095. /*
  3096. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3097. {
  3098. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3099. }
  3100. }
  3101. */
  3102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3103. {
  3104. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3105. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  3106. return [CCCellMain new];
  3107. }
  3108. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  3109. if (serverUrl == nil) {
  3110. return [CCCellMain new];
  3111. }
  3112. // Download thumbnail
  3113. if (metadata.thumbnailExists && !_metadataFolder.e2eEncrypted && ![CCUtility fileProviderStorageIconExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  3114. [self downloadThumbnail:metadata serverUrl:serverUrl indexPath:indexPath];
  3115. }
  3116. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory];
  3117. // NORMAL - > MAIN
  3118. if ([cell isKindOfClass:[CCCellMain class]]) {
  3119. NSString *shareLink = [appDelegate.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3120. NSString *shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3121. BOOL isShare = false;
  3122. BOOL isMounted = false;
  3123. if (_metadataFolder) {
  3124. isShare = [metadata.permissions containsString:k_permission_shared] && ![_metadataFolder.permissions containsString:k_permission_shared];
  3125. isMounted = [metadata.permissions containsString:k_permission_mounted] && ![_metadataFolder.permissions containsString:k_permission_mounted];
  3126. }
  3127. // Share add Tap
  3128. if (isShare || isMounted || shareLink != nil || shareUserAndGroup != nil) {
  3129. if (isShare || isMounted) {
  3130. // Shared with you
  3131. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3132. [tap setNumberOfTapsRequired:1];
  3133. ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
  3134. [((CCCellMain *)cell).shared addGestureRecognizer:tap];
  3135. } else if (shareLink != nil || shareUserAndGroup != nil) {
  3136. // You share
  3137. if (metadata.directory) {
  3138. ((CCCellMain *)cell).shared.userInteractionEnabled = NO;
  3139. } else {
  3140. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3141. [tap setNumberOfTapsRequired:1];
  3142. ((CCCellMain *)cell).shared.userInteractionEnabled = YES;
  3143. [((CCCellMain *)cell).shared addGestureRecognizer:tap];
  3144. }
  3145. }
  3146. }
  3147. // More
  3148. if ([self canOpenMenuAction:metadata]) {
  3149. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  3150. [tapMore setNumberOfTapsRequired:1];
  3151. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  3152. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  3153. }
  3154. // MGSwipeButton
  3155. ((CCCellMain *)cell).delegate = self;
  3156. // LEFT
  3157. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:1 color:[UIColor whiteColor]] backgroundColor:[NCBrandColor sharedInstance].yellowFavorite padding:25]];
  3158. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  3159. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  3160. //centerIconOverText
  3161. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  3162. [favoriteButton centerIconOverText];
  3163. // RIGHT
  3164. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[UIColor whiteColor]] backgroundColor:[UIColor redColor] padding:25]];
  3165. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  3166. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  3167. //centerIconOverText
  3168. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  3169. [deleteButton centerIconOverText];
  3170. }
  3171. // TRANSFER
  3172. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  3173. // gesture Transfer
  3174. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3175. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  3176. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  3177. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  3178. }
  3179. return cell;
  3180. }
  3181. - (void)setTableViewFooter
  3182. {
  3183. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3184. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3185. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3186. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3187. UIFont *appFont = [UIFont systemFontOfSize:12];
  3188. footerLabel.font = appFont;
  3189. footerLabel.textColor = [UIColor grayColor];
  3190. footerLabel.backgroundColor = [UIColor clearColor];
  3191. footerLabel.textAlignment = NSTextAlignmentCenter;
  3192. NSString *folders;
  3193. NSString *files;
  3194. NSString *footerText;
  3195. if (sectionDataSource.directories > 1) {
  3196. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  3197. } else if (sectionDataSource.directories == 1){
  3198. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  3199. } else {
  3200. folders = @"";
  3201. }
  3202. if (sectionDataSource.files > 1) {
  3203. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  3204. } else if (sectionDataSource.files == 1){
  3205. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  3206. } else {
  3207. files = @"";
  3208. }
  3209. if ([folders isEqualToString:@""]) {
  3210. footerText = files;
  3211. } else if ([files isEqualToString:@""]) {
  3212. footerText = folders;
  3213. } else {
  3214. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  3215. }
  3216. footerLabel.text = footerText;
  3217. [footerView addSubview:footerLabel];
  3218. [self.tableView setTableFooterView:footerView];
  3219. }
  3220. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3221. {
  3222. CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
  3223. // settiamo il record file.
  3224. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3225. if (!self.metadata)
  3226. return;
  3227. // se non può essere selezionata deseleziona
  3228. if ([cell isEditing] == NO)
  3229. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  3230. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  3231. if (self.tableView.editing) {
  3232. [_selectedFileIDsMetadatas setObject:self.metadata forKey:self.metadata.fileID];
  3233. [self setTitle];
  3234. return;
  3235. }
  3236. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  3237. if (!serverUrl) return;
  3238. // se è in corso una sessione
  3239. if (self.metadata.status != k_metadataStatusNormal)
  3240. return;
  3241. // file
  3242. if (self.metadata.directory == NO) {
  3243. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  3244. if ([CCUtility fileProviderStorageExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
  3245. [[NCNetworkingMain sharedInstance] downloadFileSuccessFailure:self.metadata.fileName fileID:self.metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView errorMessage:@"" errorCode:0];
  3246. } else {
  3247. if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  3248. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  3249. } else {
  3250. 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) {
  3251. [self shouldPerformSegue];
  3252. } else {
  3253. self.metadata.session = k_download_session;
  3254. self.metadata.sessionError = @"";
  3255. self.metadata.sessionSelector = selectorLoadFileView;
  3256. self.metadata.status = k_metadataStatusWaitDownload;
  3257. // Add Metadata for Download
  3258. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  3259. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  3260. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  3261. }
  3262. }
  3263. }
  3264. }
  3265. if (self.metadata.directory) {
  3266. imageTitleSegue = cell.imageTitleSegue;
  3267. [self performSegueDirectoryWithControlPasscode:true];
  3268. }
  3269. }
  3270. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  3271. {
  3272. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3273. [_selectedFileIDsMetadatas removeObjectForKey:metadata.fileID];
  3274. [self setTitle];
  3275. }
  3276. - (void)didSelectAll
  3277. {
  3278. for (int i = 0; i < self.tableView.numberOfSections; i++) {
  3279. for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
  3280. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3281. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  3282. [_selectedFileIDsMetadatas setObject:metadata forKey:metadata.fileID];
  3283. [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  3284. }
  3285. }
  3286. [self setTitle];
  3287. }
  3288. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  3289. {
  3290. if (!indexPath)
  3291. return NO;
  3292. NSInteger section = indexPath.section;
  3293. NSInteger row = indexPath.row;
  3294. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  3295. if (section > lastSectionIndex || lastSectionIndex < 0)
  3296. return NO;
  3297. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  3298. if (rowCount < 0)
  3299. return NO;
  3300. return row <= rowCount;
  3301. }
  3302. #pragma --------------------------------------------------------------------------------------------
  3303. #pragma mark ===== Navigation ====
  3304. #pragma --------------------------------------------------------------------------------------------
  3305. - (void)shouldPerformSegue
  3306. {
  3307. // if background return
  3308. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  3309. if (self.view.window == NO)
  3310. return;
  3311. // Collapsed ma siamo già in detail esci
  3312. if (self.splitViewController.isCollapsed)
  3313. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return;
  3314. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  3315. }
  3316. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  3317. {
  3318. id viewController = segue.destinationViewController;
  3319. tableMetadata *metadata;
  3320. if ([viewController isKindOfClass:[UINavigationController class]]) {
  3321. UINavigationController *nav = viewController;
  3322. _detailViewController = (CCDetail *)nav.topViewController;
  3323. } else {
  3324. _detailViewController = segue.destinationViewController;
  3325. }
  3326. NSMutableArray *photoDataSource = [NSMutableArray new];
  3327. if ([sender isKindOfClass:[tableMetadata class]]) {
  3328. metadata = sender;
  3329. [photoDataSource addObject:sender];
  3330. } else {
  3331. metadata = self.metadata;
  3332. for (NSString *fileID in sectionDataSource.allFileID) {
  3333. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3334. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  3335. [photoDataSource addObject:metadata];
  3336. }
  3337. }
  3338. _detailViewController.metadataDetail = metadata;
  3339. _detailViewController.photoDataSource = photoDataSource;
  3340. _detailViewController.dateFilterQuery = nil;
  3341. [_detailViewController setTitle:metadata.fileNameView];
  3342. }
  3343. // can i go to next viewcontroller
  3344. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  3345. {
  3346. NSString *nomeDir;
  3347. if (self.tableView.editing == NO) {
  3348. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:self.metadata.directoryID];
  3349. if (!serverUrl) return;
  3350. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:self.metadata.fileName];
  3351. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  3352. // 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
  3353. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil && controlPasscode) {
  3354. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3355. viewController.delegate = self;
  3356. viewController.fromType = CCBKPasscodeFromLockDirectory;
  3357. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3358. viewController.inputViewTitlePassword = YES;
  3359. if ([CCUtility getSimplyBlockCode]) {
  3360. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  3361. viewController.passcodeInputView.maximumLength = 6;
  3362. } else {
  3363. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3364. viewController.passcodeInputView.maximumLength = 64;
  3365. }
  3366. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  3367. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  3368. viewController.touchIDManager = touchIDManager;
  3369. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  3370. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3371. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  3372. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3373. [self presentViewController:navController animated:YES completion:nil];
  3374. return;
  3375. }
  3376. // E2EE Check enable
  3377. if (self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
  3378. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  3379. return;
  3380. }
  3381. nomeDir = self.metadata.fileName;
  3382. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
  3383. CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
  3384. if (!viewController) {
  3385. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
  3386. viewController.serverUrl = serverUrlPush;
  3387. viewController.titleMain = self.metadata.fileName;
  3388. viewController.imageTitle = imageTitleSegue;
  3389. // save self
  3390. [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
  3391. [self.navigationController pushViewController:viewController animated:YES];
  3392. } else {
  3393. if (viewController.isViewLoaded) {
  3394. viewController.titleMain = self.metadata.fileName;
  3395. viewController.imageTitle = imageTitleSegue;
  3396. // Fix : Application tried to present modally an active controller
  3397. if ([self.navigationController isBeingPresented]) {
  3398. // being presented
  3399. } else if ([self.navigationController isMovingToParentViewController]) {
  3400. // being pushed
  3401. } else {
  3402. [self.navigationController pushViewController:viewController animated:YES];
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. @end