CCMain.m 197 KB

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