CCMain.m 214 KB

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