CCMain.m 196 KB

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