CCMain.m 202 KB

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