CCMain.m 197 KB

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