CCMain.m 198 KB

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