CCMain.m 199 KB

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