CCMain.m 214 KB

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