CCMain.m 200 KB

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