CCMain.m 199 KB

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