CCMain.m 206 KB

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