CCMain.m 201 KB

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