CCMain.m 200 KB

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